⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hvite.c

📁 Hidden Markov Toolkit (HTK) 3.2.1 HTK is a toolkit for use in research into automatic speech recogn
💻 C
📖 第 1 页 / 共 3 页
字号:
      if (hset.hsKind==DISCRETEHS){         for (s=1; s<=hset.swidth[0]; s++){            if( (obs.vq[s] < 1) || (obs.vq[s] > maxMixInS[s]))               HError(3250,"ProcessFile: Discrete data value [ %d ] out of range in stream [ %d ] in file %s",obs.vq[s],s,fn);         }      }      ProcessObservation(vri,&obs,-1,xfInfo.inXForm);            if (trace & T_FRS) {         for (d=vri->genMaxNode,j=0;j<30;d=d->links[0].node,j++)            if (d->type==n_word) break;         if (d->type==n_word){            if (d->info.pron==NULL) p=":bound:";            else p=d->info.pron->word->wordName->name;         }         else p=":external:";         m=FindMacroStruct(&hset,'h',vri->genMaxNode->info.hmm);         printf("Optimum @%-4d HMM: %s (%s)  %d %5.3f\n",                vri->frame,m->id->name,p,                vri->nact,vri->genMaxTok.like/vri->frame);         fflush(stdout);      }      nFrames++;      tact+=vri->nact;   }   lat=CompleteRecognition(vri,pbinfo.tgtSampRate/10000000.0,&ansHeap);      if (lat==NULL) {      if ((trace & T_TOP) && fn != NULL){         if (restartable)            printf("No tokens survived to final node of network at beam %.1f\n", currGenBeam);         else            printf("No tokens survived to final node of network\n");         fflush(stdout);      } else if (fn==NULL){         printf("Sorry [%d frames]?\n",nFrames);fflush(stdout);      }            if (pbinfo.a != NULL && replay)  ReplayAudio(pbinfo);      CloseBuffer(pbuf);      return FALSE;   }      if (vri->noTokenSurvived && restartable)      return FALSE;   if (vri->noTokenSurvived && trace & T_TOP) {      printf("No tokens survived to final node of network\n");      printf("  Output most likely partial hypothesis within network\n");      fflush(stdout);   }   lat->utterance=thisFN;   lat->net=wdNetFn;   lat->vocab=dictFn;      if (trace & T_TOP || fn==NULL) {      node=NULL;      for (j=0;j<lat->nn;j++) {         node=lat->lnodes+j;         if (node->pred==NULL) break;         node=NULL;      }      aclk=lmlk=0.0;      while(node!=NULL) {         for (arc=NULL,cur=node->foll;cur!=NULL;cur=cur->farc) arc=cur;         if (arc==NULL) break;         if (arc->end->word!=NULL)            printf("%s ",arc->end->word->wordName->name);         aclk+=arc->aclike+arc->prlike*lat->prscale;         lmlk+=arc->lmlike*lat->lmscale+lat->wdpenalty;         node=arc->end;      }      printf(" ==  [%d frames] %.4f [Ac=%.1f LM=%.1f] (Act=%.1f)\n",nFrames,             (aclk+lmlk)/nFrames, aclk,lmlk,(float)tact/nFrames);      fflush(stdout);   }   if (pbinfo.a != NULL && replay)  ReplayAudio(pbinfo);      /* accumulate stats for online unsupervised adaptation       only if a token survived */   if ((lat != NULL) &&  (!vri->noTokenSurvived) && ((update > 0) || (xfInfo.useOutXForm)))      DoOnlineAdaptation(lat, pbuf, nFrames);   if (enableOutput){      if (nToks>1 && latExt!=NULL) {         MakeFN(thisFN,labDir,latExt,lfn);         if ((file=FOpen(lfn,NetOFilter,&isPipe))==NULL)             HError(3211,"ProcessFile: Could not open file %s for lattice output",lfn);         if (latForm==NULL)            form=HLAT_DEFAULT;         else {            for (p=latForm,form=0;*p!=0;p++) {               switch (*p) {               case 'A': form|=HLAT_ALABS; break;               case 'B': form|=HLAT_LBIN; break;               case 't': form|=HLAT_TIMES; break;               case 'v': form|=HLAT_PRON; break;               case 'a': form|=HLAT_ACLIKE; break;               case 'l': form|=HLAT_LMLIKE; break;               case 'd': form|=HLAT_ALIGN; break;               case 'm': form|=HLAT_ALDUR; break;               case 'n': form|=HLAT_ALLIKE; break;               case 'r': form|=HLAT_PRLIKE; break;               }            }         }         if(WriteLattice(lat,file,form)<SUCCESS)            HError(3214,"ProcessFile: WriteLattice failed");         FClose(file,isPipe);      }      trans=TranscriptionFromLattice(&ansHeap,lat,nTrans);            if (labForm!=NULL)         FormatTranscription(trans,pbinfo.tgtSampRate,states,models,                             strchr(labForm,'X')!=NULL,                             strchr(labForm,'N')!=NULL,strchr(labForm,'S')!=NULL,                             strchr(labForm,'C')!=NULL,strchr(labForm,'T')!=NULL,                             strchr(labForm,'W')!=NULL,strchr(labForm,'M')!=NULL);      MakeFN(thisFN,labDir,labExt,lfn);      /* if(LSave(lfn,trans,ofmt)<SUCCESS)         HError(3214,"ProcessFile: Cannot save file %s", lfn); */      LSave(lfn,trans,ofmt);      Dispose(&ansHeap,trans);   }   Dispose(&ansHeap,lat);   CloseBuffer(pbuf);   if (trace & T_MMU){      printf("Memory State after utter %d\n",utterNum);      PrintAllHeapStats();   }   return !vri->noTokenSurvived;}/* --------------------- Top Level Processing --------------------- *//* DoAlignment: by creating network from transcriptions or lattices */void DoAlignment(void){   FILE *nf;   char lfn[255];   Transcription *trans;   Network *net;   Boolean isPipe;   int n=0;   LogDouble currGenBeam;   AdaptXForm *incXForm;   if (trace&T_TOP) {      if (loadNetworks)          printf("New network will be used for each file\n");      else         printf("Label file will be used to align each file\n");      fflush(stdout);   }   CreateHeap(&netHeap,"Net heap",MSTAK,1,0,8000,80000);   while (NumArgs()>0) {      if (NextArg() != STRINGARG)         HError(3219,"DoAlignment: Data file name expected");      datFN = GetStrArg();      if (trace&T_TOP) {         printf("Aligning File: %s\n",datFN);  fflush(stdout);      }      MakeFN(datFN,labInDir,labInExt,lfn);      if (loadNetworks) {         if ( (nf = FOpen(lfn,NetFilter,&isPipe)) == NULL)            HError(3210,"DoAlignment: Cannot open Word Net file %s",lfn);         if((wdNet = ReadLattice(nf,&netHeap,&vocab,TRUE,FALSE))==NULL)            HError(3210,"DoAlignment: ReadLattice failed");         FClose(nf,isPipe);         if (trace&T_TOP) {            printf("Read lattice with %d nodes / %d arcs\n",                   wdNet->nn,wdNet->na);            fflush(stdout);         }      }      else {         LabList *ll = NULL;         trans=LOpen(&netHeap,lfn,ifmt);         if (trans->numLists >= 1)            ll = GetLabelList(trans,1);         if (!ll && !bndId)            HError(3233, "DoAlignment: cannot align empty transcription");         wdNet=LatticeFromLabels(ll, bndId, &vocab,&netHeap);         if (trace&T_TOP) {            printf("Created lattice with %d nodes / %d arcs from label file\n",                   wdNet->nn,wdNet->na);            fflush(stdout);         }      }      net=ExpandWordNet(&netHeap,wdNet,&vocab,&hset);      ++n;      currGenBeam = genBeam;      /* This handles the initial input transform, parent transform setting	 and output transform creation */      if (UpdateSpkrStats(&hset, &xfInfo, datFN) && (!(xfInfo.useInXForm))) {         xfInfo.inXForm = NULL;      }      if (genBeamInc == 0.0)         ProcessFile (datFN, net, n, currGenBeam, FALSE);      else {         Boolean completed;         completed = ProcessFile (datFN, net, n, currGenBeam, TRUE);         currGenBeam += genBeamInc;         while (!completed && (currGenBeam <= genBeamLim - genBeamInc)) {            completed = ProcessFile (datFN, net, n, currGenBeam, TRUE);            currGenBeam += genBeamInc;         }         if (!completed)            ProcessFile (datFN, net, n, currGenBeam, FALSE);      }      if (update > 0 && n%update == 0) {         if (trace&T_TOP) {            printf("Transforming model set\n");            fflush(stdout);         }	 /* 	    at every stage a new transform is created - fix?? 	    Estimate transform and then set it up as the 	    input XForm	 */	 incXForm = CreateAdaptXForm(&hset,"inc");         TidyBaseAccs();	 GenAdaptXForm(&hset,incXForm);         xfInfo.inXForm = GetMLLRDiagCov(incXForm);;	 SetXForm(&hset,xfInfo.inXForm);	 ApplyHMMSetXForm(&hset,xfInfo.inXForm);      }      ResetHeap(&netHeap);   }}/* DoRecognition:  use single network to recognise each input utterance */void DoRecognition(void){   FILE *nf;   Network *net;   Boolean isPipe;   int n=0;   AdaptXForm *incXForm;   if ( (nf = FOpen(wdNetFn,NetFilter,&isPipe)) == NULL)      HError(3210,"DoRecognition: Cannot open Word Net file %s",wdNetFn);   if((wdNet = ReadLattice(nf,&ansHeap,&vocab,TRUE,FALSE))==NULL)      HError(3210,"DoAlignment: ReadLattice failed");   FClose(nf,isPipe);   if (trace&T_TOP) {      printf("Read lattice with %d nodes / %d arcs\n",wdNet->nn,wdNet->na);      fflush(stdout);   }   CreateHeap(&netHeap,"Net heap",MSTAK,1,0,              wdNet->na*sizeof(NetLink),wdNet->na*sizeof(NetLink));   net = ExpandWordNet(&netHeap,wdNet,&vocab,&hset);   ResetHeap(&ansHeap);   if (trace&T_TOP) {      printf("Created network with %d nodes / %d links\n",             net->numNode,net->numLink);  fflush(stdout);   }   if (trace & T_MEM){      printf("Memory State Before Recognition\n");      PrintAllHeapStats();   }   if (NumArgs()==0) {      /* Process audio */      while(TRUE){         printf("\nREADY[%d]>\n",++n); fflush(stdout);	 /* no input transform possible for audio input .... */         ProcessFile(NULL,net,n,genBeam, FALSE);         if (update > 0 && n%update == 0) {            if (trace&T_TOP) {               printf("Transforming model set\n");               fflush(stdout);            }	    /* 	       at every stage a new transform is created - fix?? 	       Estimate transform and then set it up as the 	       input XForm	    */	    incXForm = CreateAdaptXForm(&hset,"inc");            TidyBaseAccs();	    GenAdaptXForm(&hset,incXForm);            xfInfo.inXForm = GetMLLRDiagCov(incXForm);;            SetXForm(&hset,xfInfo.inXForm);	    ApplyHMMSetXForm(&hset,xfInfo.inXForm);         }      }   }   else {                   /* Process files */      while (NumArgs()>0) {         if (NextArg()!=STRINGARG)            HError(3219,"DoRecognition: Data file name expected");         datFN = GetStrArg();         if (trace&T_TOP) {            printf("File: %s\n",datFN); fflush(stdout);         }	 /* This handles the initial input transform, parent transform setting	    and output transform creation */         if (UpdateSpkrStats(&hset, &xfInfo, datFN) && (!(xfInfo.useInXForm))) {            xfInfo.inXForm = NULL;         }         ProcessFile(datFN,net,n++,genBeam,FALSE);         if (update > 0 && n%update == 0) {            if (trace&T_TOP) {               printf("Transforming model set\n");               fflush(stdout);            }	    /* 	       at every stage a new transform is created - fix?? 	       Estimate transform and then set it up as the 	       input XForm	    */	    incXForm = CreateAdaptXForm(&hset,"inc");            TidyBaseAccs();	    GenAdaptXForm(&hset,incXForm);            xfInfo.inXForm = GetMLLRDiagCov(incXForm);;            SetXForm(&hset,xfInfo.inXForm);	    ApplyHMMSetXForm(&hset,xfInfo.inXForm);         }      }   }}/* ----------------------------------------------------------- *//*                      END:  HVite.c                          *//* ----------------------------------------------------------- */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -