Exemplo n.º 1
0
std::vector<std::string> recognize() {

	ABuffer auChan("auChan");		// waveform data 
	ABuffer feChan("feChan");		// features 
	ABuffer ansChan("ansChan");		// recognition output 

	ASource ain("AIn",&auChan);			// auChan connects source to coder 
	ACode acode("ACode",&auChan,&feChan); //feChan connects coder to reco 
	
	AHmms hset("HmmSet");	// create HMM set called HmmSet 
	ADict dict("ADict");	// create a dictionary called ADict 
	AGram gram("AGram");	// create a grammar called AGram 
	ARMan rman;				// create a resource manager 
	rman.StoreHMMs(&hset);	// store the resources in rman 
	rman.StoreDict(&dict); 
	rman.StoreGram(&gram); 
	
	ResourceGroup *group = rman.NewGroup("directions"); 
	group->AddHMMs(&hset); 
	group->AddDict(&dict); 
	group->AddGram(&gram); 
	ARec arec("ARec",&feChan,&ansChan,&rman); // create recogniser 
	
	ain.Start(); acode.Start(); arec.Start();
	
	arec.SendMessage("start()");
	ain.SendMessage("start()");

	// Waiting for processing to finish
	do
	{
		usleep(10000);
	}while(!auChan.IsEmpty() || !feChan.IsEmpty());
	
	// Get the results
	std::vector<std::string> result;
	while(!ansChan.IsEmpty())
	{
		APacket p = ansChan.GetPacket();
		if(p.GetKind() == PhrasePacket)
		{
			APhraseData *pd = (APhraseData *)p.GetData();
			result.push_back(pd->word);
		}
	}
	
	ain.SendMessage("stop()");
	acode.SendMessage("terminate()");
	arec.SendMessage("terminate()");
	ain.SendMessage("terminate()");
	
	// Wait for threads to finish
	acode.Join();
	arec.Join();
	ain.Join();
	
	return result;
}
int cTumkwsaSink::setupATK()
{
  try {

  // ------- load HTK config......
  int argc=3;
  const char* argv[3] = {"ASR","-C",NULL};
  if (configfile != NULL)
    argv[2]=configfile;
  else
    argv[2]="asr.cfg";

  if (InitHTK(argc,(char**)argv,version,TRUE)<SUCCESS){
    COMP_ERR("failed to initialise ASR subsystem!");
  }

  ConfParam *cParm[MAXGLOBS];       /* config parameters */
  int numParm,i;
  char ngramFN[100],buf[100];
  ngramFN[0] = '\0';

  // Read configuration parms for ANGRAM to see if NGram used
  numParm = GetConfig((char *)"ANGRAM", TRUE, cParm, MAXGLOBS);
  if (numParm>0){
    if (GetConfStr(cParm,numParm,(char *)"NGRAMFILE",buf)) strcpy(ngramFN,buf);
  }

  // Create Buffers
  feChan = new ABuffer("feChan");
  ansChan = new ABuffer("ansChan");

  // create a resource manager
  rman = new ARMan();

  arec = new ARec("ARec",feChan,ansChan,rman,0);

  // create global resources
  hset = new AHmms("HmmSet"); // load info in config
  dict = new ADict("ADict");
  gram = new AGram("AGram");
  rman->StoreHMMs(hset);
  rman->StoreDict(dict);
  rman->StoreGram(gram);

  ResourceGroup *main = rman->NewGroup("main");
  main->AddHMMs(hset);
  main->AddDict(dict);
  main->AddGram(gram);

  if (strlen(ngramFN)>0){
    ANGram * ngram  = new ANGram("ANGram");
    rman->StoreNGram(ngram);
    main->AddNGram(ngram);
  }

  arec->Start();
  arec->SendMessage("usegrp(main)");
  arec->SendMessage("start()");

  terminated = FALSE;

  }
  catch (ATK_Error e){ ReportErrors((char*)"ATK",e.i); return 0;}
  catch (HTK_Error e){ ReportErrors((char*)"HTK",e.i); return 0;}

  HThread t = HCreateThread("resultThread", 0, HPRIO_NORM, ATKresultThreadRunner, this);
  ATKresThread = t->thread;
  //smileThreadCreate( ATKresThread, ATKresultThreadRunner, this );

  atkIsSetup=1;
  
  return 1;
}
Exemplo n.º 3
0
int main(int argc, char *argv[])
{
   APacket p;

   try {

      // if (NCInitHTK("TRec.cfg",version)<SUCCESS){
      if (InitHTK(argc,argv,version)<SUCCESS){
         ReportErrors("Main",0); exit(-1);
      }
      printf("TRec: Basic Recogniser Test\n");
      ConfParam *cParm[MAXGLOBS];       /* config parameters */
      int numParm,i;
      char ngramFN[100],buf[100];
      ngramFN[0] = '\0';
      // Read configuration parms for ANGRAM to see if NGram used
      numParm = GetConfig("ANGRAM", TRUE, cParm, MAXGLOBS);
      if (numParm>0){
         if (GetConfStr(cParm,numParm,"NGRAMFILE",buf)) strcpy(ngramFN,buf);
      }
      printf("TRec: HTK initialised: %s\n",ngramFN);
      // Create Buffers
      ABuffer auChan("auChan");
      ABuffer feChan("feChan");
      ABuffer ansChan("ansChan");
      printf("TRec: Buffers initialised\n");
      // create a resource manager
      ARMan rman;

      // Create Audio Source and Coder
      ASource ain("AIn",&auChan);
      ACode acode("ACode",&auChan,&feChan);
      ARec  arec("ARec",&feChan,&ansChan,&rman,0);
      printf("TRec: Components initialised\n");

      // create global resources
      AHmms hset("HmmSet"); // load info in config
      ADict dict("ADict");
      AGram gram("AGram");
      rman.StoreHMMs(&hset);
      rman.StoreDict(&dict);
      rman.StoreGram(&gram);

      ResourceGroup *main = rman.NewGroup("main");
      main->AddHMMs(&hset);
      main->AddDict(&dict);
      main->AddGram(&gram);

      if (strlen(ngramFN)>0){
         ANGram * ngram  = new ANGram("ANGram");
         rman.StoreNGram(ngram);
         main->AddNGram(ngram);
      }

#ifdef WITHMON
      // Create Monitor and Start it
      AMonitor amon;
      amon.AddComponent(&ain);
      amon.AddComponent(&acode);
      amon.AddComponent(&arec);
      amon.Start();
#endif

      // Start components executing
      ain.Start();
      acode.Start();
      arec.Start();
      arec.SendMessage("usegrp(main)");
      arec.SendMessage("start()");

      Boolean terminated = FALSE;
      while (!terminated) {
         APacket p = ansChan.GetPacket();
         if (p.GetKind() == StringPacket){
            AStringData * sd = (AStringData *)p.GetData();
            if (sd->data.find("TERMINATED") != string::npos) {
               terminated = TRUE;
            }
         }
         p.Show();
      }
      // Shutdown
      printf("Waiting for ain\n");
      ain.Join();
      printf("Waiting for acode\n");
      acode.Join();
      printf("Waiting for arec\n");
      arec.Join();
#ifdef WITHMON
      printf("Waiting for monitor\n");
      amon.Terminate();
      HJoinMonitor();
#endif
      return 0;
   }
   catch (ATK_Error e){ ReportErrors("ATK",e.i); return 0;}
   catch (HTK_Error e){ ReportErrors("HTK",e.i); return 0;}
}