现在的位置: 首页 > 综合 > 正文

如何在vc++6.0/2003/2005/2008中调用ATK

2013年10月01日 ⁄ 综合 ⁄ 共 20219字 ⁄ 字号 评论关闭

Application Example using the ATK Real-Time API  

 

下面是一个关于HTK的例子

 

 

  1. #include "stdafx.h"    
  2.    
  3.    
  4. #include "dllSudx.h"    
  5. typedef vector<STRING>  TStringArray;   
  6.    
  7. struct ASampleSet   
  8. {   
  9.     char name[256];   
  10.     TSoundTag tags[301];   
  11. };   
  12.    
  13. typedef vector<ASAMPLESET>  TSampleSetList;   
  14.    
  15. TStringArray sampleList;   
  16. TSampleSetList sampleSetList;   
  17. int vector_count = 0;   
  18.    
  19. int ListWavFiles(char* dir, TStringArray& fileList)   
  20. {   
  21.     struct _finddata_t c_file;   
  22.     long hFile;   
  23.     char tmp[1024];   
  24.     int retVal = 0;   
  25.    
  26.     sprintf(tmp, "%s//%s", dir, "*.wav");   
  27.        
  28.     /* Find first .c file in current directory */   
  29.     if( (hFile = _findfirst( tmp, &c_file )) == -1L )   
  30.         return retVal;   
  31.     else   
  32.     {   
  33.         sprintf(tmp, "%s//%s", dir, c_file.name);   
  34.         fileList.push_back(tmp);   
  35.         retVal++;   
  36.         while( _findnext( hFile, &c_file ) == 0 )   
  37.         {   
  38.             sprintf(tmp, "%s//%s", dir, c_file.name);   
  39.             fileList.push_back(tmp);   
  40.             retVal++;   
  41.         }   
  42.         _findclose( hFile );   
  43.     }   
  44.    
  45.     return retVal;   
  46. }   
  47.    
  48.    
  49. int ListVecFiles(char* dir, TStringArray& fileList)   
  50. {   
  51.     struct _finddata_t c_file;   
  52.     long hFile;   
  53.     char tmp[1024];   
  54.     int retVal = 0;   
  55.    
  56.     sprintf(tmp, "%s//%s", dir, "*.vec");   
  57.        
  58.     /* Find first .c file in current directory */   
  59.     if( (hFile = _findfirst( tmp, &c_file )) == -1L )   
  60.         return retVal;   
  61.     else   
  62.     {   
  63.         sprintf(tmp, "%s//%s", dir, c_file.name);   
  64.         fileList.push_back(tmp);   
  65.         retVal++;   
  66.         while( _findnext( hFile, &c_file ) == 0 )   
  67.         {   
  68.             sprintf(tmp, "%s//%s", dir, c_file.name);   
  69.             fileList.push_back(tmp);   
  70.             retVal++;   
  71.         }   
  72.         _findclose( hFile );   
  73.     }   
  74.    
  75.     return retVal;   
  76. }   
  77.    
  78.    
  79. int LoadVecFiles(TStringArray& fileList, TSampleSetList& sampleSetList)   
  80. {   
  81.     int retVal = 0;   
  82.    
  83.     for(int i=0; i<FILELIST.SIZE(); <声音文件名 printf(?使用方法:test printf(?参数错误/n?); { *if(argc!="4)" bVolumeFlag) bool , vecDirectory char* *VoiceName, VRecognize16BitWav(char int ; g_TestVectorFileName="test.vec" string } FALSE; : TRUE ? matchCount="0;" return matchCount++; i+="3;" pMatchResult[matchCount].dwMatchOffset="i;" pMatchResult[matchCount].ucScore="score;" &score)) bMode, pSampleVec, if(sudxCompareEx(pSrcVec+i, score; i++) matchCount<100; && i<nSrcLen-tailLen i="0;" for(int tailLen="64;" else 0; if(nSampleLen<300) if(nSampleLen<64) if(bMode="=TRUE)" tailLen; 输出匹配结果(得分、偏移量) pMatchResult) MATCHRESULT* 输出匹配结果个数 pnMaxMatch, int* 模式。="TRUE:快速模式;=FALSE:准确模式" BOOL 样本向量的个数 nSampleLen, 样本向量的首地址指针 TSoundTag* 信号源向量的长度(以TSoundTag为计量单位) nSrcLen, 待识别信号源向量的首地址指针 pSrcVec, sudxMatch(TSoundTag* 注意事项:pnMaxMatch的存储空间由应用程序分配,最大为100条记录。 函数返回:1:调用成功。0:调用失败 MATCHRESULT; dwMatchOffset; DWORD ucScore; char unsigned tagMATCHRESULT struct typedef retVal; ); fflush(stdout fileList[i].c_str()); [%s]/n?, file open not printf(?can fclose(fp); !/n?, OK set[%s] printf(?sample retVal++; sampleSetList.push_back(aset); strcpy(aset.name, short!/n?, too if(size!="80)" fp); 80, sizeof(TSoundTag), size="fread(aset.tags," aset; ASampleSet if(fp) ?rb?); fp="fopen(fileList[i].c_str()," FILE*> <样本目录> <音量标志>/n");   
  84.         printf("/t声音文件名是要被识别的声音文件,样本目录中包含已经预先处理好的样本/n"   
  85.                         "/t 音量标志: 表示识别时是否采用音量相关的方式,为0表示识别时不管音量大小,为1表示识别时需要考虑音量大小/n"   
  86.                         "Press any key continue...");   
  87.         getch();   
  88.         return -1;   
  89.     }*/   
  90.    
  91.     //int volFlag = atol(argv[3]);    
  92.     if(bVolumeFlag)   
  93.     {   
  94.         sudxSetCompVolumeFlag(TRUE);   
  95.         printf("采用与音量相关的方式比较/n");   
  96.     }   
  97.     else   
  98.     {   
  99.         sudxSetCompVolumeFlag(FALSE);   
  100.         printf("采用与音量无关的方式比较/n");   
  101.     }   
  102.    
  103.     TStringArray sampleList;   
  104.     int i = ListVecFiles(vecDirectory, sampleList);   
  105.     if(i<=0)   
  106.     {   
  107.         printf("No sample files in dir [%s]/n", vecDirectory);   
  108.         return -2;   
  109.     }   
  110.        
  111.     TSampleSetList sampleSetList;   
  112.     int vector_count = LoadVecFiles(sampleList, sampleSetList);   
  113.     if(vector_count<=0)   
  114.     {   
  115.         printf("没有找到样本集合文件/n");   
  116.         return -3;   
  117.     }   
  118.    
  119.    
  120.     printf("Now start.../n");   
  121.     const int bufSampleSize = 49306; ////充值成功,你的账户余额为的 8k采样,8位长度编码的语音文件大小    
  122.     unsigned char * p8bitBuf = new unsigned   char[ bufSampleSize];   
  123.     short *pFileBuf = new short[bufSampleSize*2];   //每次处理2M个16bit pcm样本,也就是4M byte数据。    
  124.    
  125.    
  126. //  char outFile[1000];    
  127. //  sprintf(outFile, "%s//%s.vec", "c:", VoiceName);    
  128. //  FILE* fout = fopen(outFile, "w+b");     //打开或创建向量文件    
  129.    
  130.     FILE *fp = fopen(VoiceName, "rb");   
  131.     fseek(fp, 0L, SEEK_END);   
  132.     long size = ftell(fp);   
  133.     fseek(fp, 44L, SEEK_SET);   //跳过wav头     
  134.    
  135.     int old_clock = clock();   
  136. //  long segSize = fread(p8bitBuf, sizeof(char), bufSampleSize, fp);    
  137.     //alaw2linear( p8bitBuf , bufSampleSize , pFileBuf );    
  138.    
  139.     long segSize = fread(pFileBuf, sizeof(short), bufSampleSize, fp);   
  140.     TSoundTag* pOut;   
  141.     int outSize, tailSize;   
  142.     short* pTail=NULL;   
  143.    
  144.     int last_result[17];   
  145.      int iMax = sudxGetMaxInputSampleSize();   
  146.    
  147.     int error = sudxCalcBuffer( pFileBuf, segSize, &pOut, &outSize, &pTail, &tailSize, last_result);   
  148.     if ( error > 0 )   
  149.     {   
  150.         if ( outSize > (64 + 1 ))   
  151.         {   
  152.             old_clock = clock();   
  153.    
  154.             int compare_turn = outSize - 64 - 1;   
  155.             for(i=0; i<COMPARE_TURN; { int i++) for(int [%s]/n?, file if(tailSize tailSize="compare_turn+64-300-i;" sampleSetList[j].name); (i+1)*128, %d, pos sample at Match printf(?Quick ) FALSE) &(sampleSetList[j].tags[1]), sudxCompare(pOut+1+i, if( j++) j<vector_count; j="0;">300)   
  156.                         {   
  157.                             if(sudxCompare(pOut+1+i, sampleSetList[j].tags+1, TRUE))   
  158.                                 printf("精确匹配位置 %d, file[%s]/n", (i+1)*128, sampleSetList[j].name);   
  159.                             else   
  160.                                 printf("!!Slow Not Match at sample pos %d, file[%s]/n", (i+1)*128, sampleSetList[j].name);   
  161.                         }   
  162.                     }   
  163.                     else   
  164.                     {   
  165.                         printf("Not Match at sample pos %d, file [%s]/n", (i+1)*128, sampleSetList[j].name);   
  166.                     }   
  167.    
  168.                 }   
  169.             }   
  170.             int time_passed = clock()-old_clock;   
  171.             printf("计算结束, 耗时%d ms/n", time_passed);   
  172.             printf("比较速度为每秒钟可查找%f秒音乐/n"double(compare_turn)*128.0/8000.0/(double(time_passed)/1000.0));   
  173.    
  174.         }   
  175.         else   
  176.         {   
  177.             printf("输入的声音过短,不能比较/n");   
  178.             return -2;   
  179.         }   
  180.    
  181.     }   
  182.     else    
  183.     {   
  184.         return -1;   
  185.     }   
  186.     return 0;   
  187. }   
  188.    
  189.    
  190. int VRecoInit(char * vecDirectory )   
  191. {   
  192.    
  193.        
  194.     int i = ListVecFiles(vecDirectory, sampleList);   
  195.     if(i<=0)   
  196.     {   
  197.         printf("No sample files in dir [%s]/n", vecDirectory);   
  198.         return -2;   
  199.     }   
  200.        
  201.        
  202.      vector_count = LoadVecFiles(sampleList, sampleSetList);   
  203.     if(vector_count<=0)   
  204.     {   
  205.         printf("没有找到样本集合文件/n");   
  206.         return -3;   
  207.     }   
  208.    
  209.     return 0;   
  210.    
  211.    
  212.    
  213.    
  214. }   
  215. ///    
  216. int VRecognize(char *VoiceName, char* vecDirectory , bool bVolumeFlag,  int * iMatchCount)   
  217. {   
  218.     /*if(argc!=4)  
  219.     {  
  220.         printf("参数错误/n");  
  221.         printf("使用方法:test <声音文件名> <样本目录> <音量标志>/n");  
  222.         printf("/t声音文件名是要被识别的声音文件,样本目录中包含已经预先处理好的样本/n"  
  223.                         "/t 音量标志: 表示识别时是否采用音量相关的方式,为0表示识别时不管音量大小,为1表示识别时需要考虑音量大小/n"  
  224.                         "Press any key continue...");  
  225.         getch();  
  226.         return -1;  
  227.     }*/   
  228.    
  229.     //int volFlag = atol(argv[3]);    
  230.     if(bVolumeFlag)   
  231.     {   
  232.         sudxSetCompVolumeFlag(TRUE);   
  233.         printf("采用与音量相关的方式比较/n");   
  234.     }   
  235.     else   
  236.     {   
  237.         sudxSetCompVolumeFlag(FALSE);   
  238.         printf("采用与音量无关的方式比较/n");   
  239.     }   
  240.    
  241.     char gcaMsg[1000];   
  242.     sprintf(gcaMsg , "Now start...%s/n", VoiceName);   
  243.     printf( gcaMsg );   
  244.     fflush(stdout);   
  245.     const int bufSampleSize = 2048*1024; ////充值成功,你的账户余额为的 8k采样,8位长度编码的语音文件大小    
  246.     unsigned char * p8bitBuf = new unsigned   char[ bufSampleSize];   
  247.     short *pFileBuf = new short[bufSampleSize]; //每次处理2M个16bit pcm样本,也就是4M byte数据。    
  248.    
  249.    
  250.    
  251. //  char outFile[1000];    
  252. //  sprintf(outFile, "%s//%s.vec", "c:", VoiceName);    
  253. //  FILE* fout = fopen(outFile, "w+b");     //打开或创建向量文件    
  254.    
  255.     try   
  256.     {   
  257.     
  258.        sprintf(gcaMsg , "bf fopen...%s/n", VoiceName);   
  259.        printf( gcaMsg );   
  260.        fflush(stdout);   
  261.            
  262.         FILE *fp = fopen(VoiceName, "rb");   
  263.         fseek(fp, 0L, SEEK_END);   
  264.         long size = ftell(fp);   
  265.         fseek(fp, 44L, SEEK_SET);   //跳过wav头     
  266.    
  267.    
  268.         sprintf(gcaMsg , "af fopen...%s/n", VoiceName);   
  269.         printf( gcaMsg );   
  270.         fflush(stdout);   
  271.        
  272.    
  273.         int old_clock = clock();   
  274.         long segSize = fread(p8bitBuf, sizeof(char), bufSampleSize, fp);   
  275.         alaw2linear( p8bitBuf , bufSampleSize , pFileBuf );   
  276.    
  277.         sprintf(gcaMsg , "Af alaw2linear...%s/n", VoiceName);   
  278.         printf( gcaMsg );   
  279.         fflush(stdout);   
  280.        
  281.         //  long segSize = fread(pFileBuf, sizeof(short), bufSampleSize, fp);    
  282.         TSoundTag* pOut;   
  283.         int outSize, tailSize;   
  284.         short* pTail=NULL;   
  285.    
  286.         int last_result[17];   
  287.         //int iMax = sudxGetMaxInputSampleSize();    
  288.    
  289.            
  290.         int error = sudxCalcBuffer( pFileBuf, segSize, &pOut, &outSize, &pTail, &tailSize, last_result);   
  291.    
  292.         if ( error > 0 )   
  293.         {   
  294.         sprintf(gcaMsg , "Af sudxCalcBuffer...%s/n", VoiceName);   
  295.         printf( gcaMsg );   
  296.         fflush(stdout);   
  297.    
  298.             if ( outSize > (64 + 1 ))   
  299.             {   
  300.                 old_clock = clock();   
  301.    
  302.                 int compare_turn = outSize - 64 - 1;   
  303.                 for(int i=0; i<COMPARE_TURN; { int i++) for(int [%s]/n?, file if(tailSize tailSize="compare_turn+64-300-i;" sampleSetList[j].name); (i+1)*128, %d, pos sample at Match printf(?Quick ) FALSE) &(sampleSetList[j].tags[1]), sudxCompare(pOut+1+i, if( j++) j<vector_count; j="0;" iMatchCount)++; (*>300)   
  304.                             {   
  305.                                 if(sudxCompare(pOut+1+i, sampleSetList[j].tags+1, TRUE))   
  306.                                 {   
  307.    
  308.                                     (* iMatchCount) ++;   
  309.                                     printf("精确匹配位置 %d, file[%s]/n", (i+1)*128, sampleSetList[j].name);   
  310.                                 }   
  311.                                 else   
  312.                                 {   
  313.                                 //  printf("!!Slow Not Match at sample pos %d, file[%s]/n", (i+1)*128, sampleSetList[j].name);    
  314.                                 }   
  315.                             }   
  316.                         }   
  317.                     }   
  318.                 }   
  319.                 int time_passed = clock()-old_clock;   
  320.                 printf("计算结束, 耗时%d ms  Match Count =%d/n", time_passed,(* iMatchCount) );   
  321.                 printf("比较速度为每秒钟可查找%f秒音乐/n"double(compare_turn)*128.0/8000.0/(double(time_passed)/1000.0));   
  322.                 fflush( stdout );   
  323.    
  324.             }   
  325.             else   
  326.             {   
  327.                 printf("输入的声音过短,不能比较/n");   
  328.                 return -2;   
  329.             }   
  330.    
  331.         }   
  332.         else    
  333.         {   
  334.             sprintf(gcaMsg , "Now Fail ...%s/n  return -1""CalcBuffer");   
  335.             printf( gcaMsg );   
  336.             fflush(stdout);   
  337.        
  338.             return -1;   
  339.         }   
  340.     }   
  341.     catch ( ... )   
  342.     {   
  343.    
  344.             sprintf(gcaMsg , "Now Fail ...%s/n  return -3""Catch");   
  345.             printf( gcaMsg );   
  346.             fflush(stdout);      
  347.         return -3;   
  348.     }   
  349.         
  350.     return 0;   
  351. }      
  352.    
  353.    
  354. char * asds_version="!HVER!ASDS: 1.6.0 [SJY 01/06/07]";  
  355.   
  356. #include "AMonitor.h"   
  357. #include "AIO.h"   
  358.   
  359. // ---------------- Globals To Define the Recognition System -----------------   
  360. class QA;  
  361.   
  362. // Information Channel - connects to AIO output   
  363. static ABuffer *inChan;        // input channel from AIO   
  364.   
  365. // Active components (threads)   
  366. // NB: AIO will start-up its own ASource,ASyn,ACode & ARec   
  367. static AIO *aio;               // the AIO subsystem   
  368. static AMonitor *amon;         // system monitor   
  369.   
  370. // Global resources - these will be passed to AIO on creation   
  371. ARMan *rman;       // resource manager for dict, grammars and HMMSet   
  372. AHmms *hset;       // HMM set is global since it never changes   
  373. ADict *dict;       // ditto dictionary (though it can be edited if desired)   
  374. AGram *ggrm;       // global grammar, always active   
  375. QA *qty, *top;     // question/answer instances   
  376.   
  377. // ------------------ Simple Question/Answer Class ----------------------   
  378.   
  379. // the status of each slot determines the dialogue flow.  each slot   
  380. // starts as unknown.  When an answer is provided with high confidence   
  381. // (>minconf), the slot is immediately grounded.  Otherwise the slot   
  382. // status moves to unconfirmed ready for explicit checking.   
  383.   
  384. typedef enum { unknown, unconfirmed, grounded, cancelled } SlotStatus;  
  385.   
  386. // the system listens to the user in QA.listen, this implements a simple   
  387. // state machine where the states are:   
  388. typedef enum { aActive,aInProcess,aTimeout,aDone,aTerminated} ASRStatus;  
  389. typedef enum { sActive, sDone, sInt } SynStatus;  
  390.   
  391. static Boolean terminated = FALSE;  
  392.   
  393. static const float minconf = 0.5;  
  394.   
  395. class QA {  
  396. public:  
  397.    QA(const string& aname,          // name of qa object   
  398.       const string& aprompt,        // query prompt   
  399.       const string& gramfile,       // name of grammar file   
  400.       const string& ahelp);     // help message   
  401.    ASRStatus Listen(string prompt, string rgroup, SynStatus& ss);  
  402.             // output prompt and listen using given res group and update slot value   
  403.    void Ask();                          // ask question, record answer and set status   
  404.    void Check();                        // check answer and set status   
  405.    void GetSlot();               // get a value for the slot by asking and checking   
  406.    string GetValue();            // strip tag and return actual value   
  407.    void Show();                     // show current slot status   
  408.    void Reset();  
  409.    SlotStatus status;               // slot status   
  410.    string  value;                       // slot value   
  411.    float  curconf;                  // current input   
  412.    string curtag;  
  413.    string curwords;  
  414. private:  
  415.    string name;                  // name of slot (also name of semantic tag)   
  416.    string prompt;                       // question   
  417.    string help;                     // help string   
  418.    ResourceGroup *ask;  
  419.    ResourceGroup *chk;  
  420. };  
  421.   
  422. // construct a QA object with given prompt and grammar   
  423. QA::QA(const string& aname, const string& aprompt,  
  424.        const string& gramfile, const string& ahelp)  
  425. {  
  426.    // save the prompts   
  427.    prompt = aprompt; help = ahelp; name = aname;  
  428.    // create grammar specific to this question   
  429.    AGram *g1 = new AGram(name,gramfile);  
  430.    rman->StoreGram(g1);  
  431.    ask = rman->NewGroup(name+"-ask");  
  432.    ask->AddHMMs(hset);           // Add the global resources   
  433.    ask->AddDict(dict);  
  434.    ask->AddGram(ggrm);           // include global grammar in parallel with   
  435.    ask->AddGram(g1);             // qa specific grammar   
  436.    // create copy of ask but prepend "No" to front of qa grammar   
  437.    // and add confirm in parallel   
  438.    chk = rman->NewGroup(name+"-chk");  
  439.    chk->AddHMMs(hset);           // Add the global resources   
  440.    chk->AddDict(dict);  
  441.    chk->AddGram(ggrm);           // include global grammar   
  442.    AGram *g2 = new AGram(*g1);   // copy g1   
  443.    rman->StoreGram(g2);  
  444.    g2->OpenEdit();               // Modify copy of g1 by prepending   
  445.    GramSubN *s = g2->main;       // "NO" to front with skip to end   
  446.    GramNode *ent = s->NewNullNode(99);  
  447.    GramNode *no  = s->NewWordNode("NO","no");  
  448.    GramNode *yes = s->NewCallNode("confirm","yes");   // Add confirm in //   
  449.    s->AddLink(ent,no); s->AddLink(ent,yes); s->AddLink(yes,s->exit);  
  450.    s->AddLink(no,s->entry); s->AddLink(no,s->exit);  
  451.    s->entry = ent;  
  452.    g2->CloseEdit();  
  453.    chk->AddGram(g2);    // Add the new "correction" grammar   
  454.    // initial status is unknown   
  455.    status = unknown; value = "";  
  456. }  
  457.   
  458. // Reset slot values for a new dialogue   
  459. void QA::Reset()  
  460. {  
  461.    status = unknown; value = "";  
  462. }  
  463.   
  464. // For debugging only   
  465. void QA::Show()  
  466. {  
  467.    string s = "???";  
  468.   
  469.    switch (status){  
  470.       case unknown:    s = "unknown";   break;  
  471.       case unconfirmed: s = "unconfirmed";  break;  
  472.       case grounded:       s = "grounded";  break;  
  473.       case cancelled:   s = "cancelled";    break;  
  474.    }  
  475.    printf("Slot: %s:  status=%s  value=%s  [cur=%s(%s) %.1f]/n",  
  476.       name.c_str(),s.c_str(),value.c_str(),curtag.c_str(),curwords.c_str(),curconf);  
  477. }  
  478.   
  479. // listen to rec packets and construct slot value   
  480. // return system status when finished listening   
  481. ASRStatus QA::Listen(string prompt, string rgroup, SynStatus& ss)  
  482. {  
  483.    APacket p;  
  484.    string s="";  
  485.    float conf=0.0;  
  486.    int numwords=0;  
  487.    ASRStatus as;  
  488.   
  489.    curtag=""; curwords="";  
  490.    // set the resource group to use and start recognising   
  491.    string grp = "setgroup("+rgroup+")";  
  492.    string prmpt = "ask(/""+prompt+"/")";  
  493.    printf("%s --> %s/n",prmpt.c_str(),grp.c_str());  
  494.    aio->SendMessage(grp);  
  495.    aio->SendMessage(prmpt);  
  496.    // listen to response of form  "tag(w1 w2 ...)"   
  497.    // Following implements a simple state machine ss= syn state as=asr state   
  498.    ss = sActive; as = aActive;  
  499.    do {  
  500.       AStringData *sd;  
  501.       ACommandData *cd;  
  502.       APhraseData *pd;  
  503.       string cmd;  
  504.       p = inChan->GetPacket();  
  505.       switch(p.GetKind()) {  
  506.          case StringPacket:  
  507.             sd = (AStringData *)p.GetData();  
  508.             if (sd->data.find("TERMINATED") != string::npos) {  
  509.                as = aTerminated;  
  510.             }  
  511.             break;  
  512.          case CommandPacket:  
  513.             cd = (ACommandData *)p.GetData();  
  514.             cmd = cd->GetCommand();  
  515.             if (cmd=="synFinished")  
  516.                ss = sDone;  
  517.             else if (cmd=="synInterrupted")  
  518.                ss = sInt;  
  519.             else if (cmd=="asrTimeOut")  
  520.                as = aTimeout;  
  521.             break;  
  522.          case PhrasePacket:  
  523.             pd = (APhraseData *)p.GetData();  
  524.             if (as == aActive && pd->ptype == OpenTag_PT){  
  525.                assert(s == "" && numwords == 0);  
  526.                as = aInProcess;  
  527.             }else if (as == aInProcess && pd->ptype == Word_PT) {  
  528.                if (s=="") s = pd->word; else s = s + " " + pd->word;  
  529.                // printf("{%s[%.2f]}",pd->word.c_str(),pd->confidence);   
  530.                conf += pd->confidence; ++numwords;  
  531.             }else if (as == aInProcess &&  
  532.                (pd->ptype == CloseTag_PT || pd->ptype == End_PT)){  
  533.                curtag = pd->tag;  
  534.                curwords = s;  
  535.                as = aDone;  
  536.             }  
  537.             break;  
  538.       }  
  539.    } while (as <= aInProcess);  
  540.    curconf = numwords==0?0.0:conf/numwords;  
  541.    printf("/n  Response:  %s(%s)[%.1f]/n",curtag.c_str(),curwords.c_str(),curconf);  
  542.    return as;  
  543. }  
  544.   
  545. // ask for information   
  546. void QA::Ask()  
  547. {  
  548.    Boolean ok = FALSE;  
  549.    ASRStatus as; SynStatus ss;  
  550.    do {  
  551.       as=Listen(prompt,ask->gname,ss);  
  552.       if (as==aDone){  
  553.          if (curtag == "command") {  
  554.             if (curwords == "HELP") {  
  555.                aio->SendMessage("tell(/""+help+"/")");  
  556.             }else if (curwords == "CANCEL"){  
  557.                aio->SendMessage("tell(/"Cancelled/")");  
  558.                ok = TRUE; status = cancelled;  
  559.             }  
  560.          }  
  561.          if (curtag == name){  
  562.             if (curconf > minconf){  
  563.                status = grounded;  
  564.             }else{  
  565.                status = unconfirmed;  
  566.             }  
  567.             value = curtag+"("+curwords+")";  
  568.             ok = TRUE;  
  569.          }  
  570.       }else if (as==aTimeout) {  
  571.          printf("Timeout/n");  
  572.          aio->SendMessage("tell(/"Sorry, I didnt hear that!/")");  
  573.       }else if (as==aTerminated) {  
  574.          terminated = TRUE;  
  575.       }  
  576.    } while (!ok && !terminated);  
  577. }  
  578.   
  579. // confirm current slot value   
  580. void QA::Check()  
  581. {  
  582.    Boolean ok = FALSE;  
  583.    ASRStatus as; SynStatus ss;  
  584.    string prompt;  
  585.    do {  
  586.       prompt = "Are sure you want "

抱歉!评论已关闭.