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;
}
Пример #2
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;}
}