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

📄 hvite.c

📁 隐马尔科夫模型工具箱
💻 C
📖 第 1 页 / 共 3 页
字号:
         prScale = GetChkedFlt(0.0,1000.0,s);  break;      case 's':         lmScale = GetChkedFlt(0.0,1000.0,s);  break;      case 't':         genBeam = GetChkedFlt(0,1.0E20,s); 	 if (genBeam == 0.0)	    genBeam = -LZERO;         if (NextArg()==FLOATARG || NextArg()==INTARG) {             genBeamInc = GetChkedFlt(0.0,1.0E20,s);             genBeamLim = GetChkedFlt(0.0,1.0E20,s);             if (genBeamLim < (genBeam + genBeamInc)) {                genBeamLim = genBeam; genBeamInc = 0.0;             }          }          else {             genBeamInc = 0.0;             genBeamLim = genBeam;          }            break;      case 'w':         if (NextArg()!=STRINGARG)            loadNetworks=TRUE;         else {            wdNetFn = GetStrArg();            if (strlen(wdNetFn)==0) {               wdNetFn=NULL;               loadNetworks=TRUE;            }         }         break;      case 'u':         maxActive = GetChkedInt(0,100000,s); break;            case 'v':         wordBeam = GetChkedFlt(0,1.0E20,s);          if (wordBeam == 0.0)            wordBeam = -LZERO;         break;      case 'x':         if (NextArg()!=STRINGARG)            HError(3219,"HVite: HMM file extension expected");         hmmExt = GetStrArg(); break;      case 'y':         if (NextArg()!=STRINGARG)            HError(3219,"HVite: Output label file extension expected");         labExt = GetStrArg(); break;      case 'z':         if (NextArg()!=STRINGARG)            HError(3219,"HVite: Lattice output file extension expected");         latExt = GetStrArg(); break;      case 'F':         if (NextArg() != STRINGARG)            HError(3219,"HVite: Data File format expected");         if((dfmt = Str2Format(GetStrArg())) == ALIEN)            HError(-3289,"HVite: Warning ALIEN Input file format set");         break;      case 'G':         if (NextArg() != STRINGARG)            HError(3219,"HVite: Source Label File format expected");         if((ifmt = Str2Format(GetStrArg())) == ALIEN)            HError(-3289,"HVite: Warning ALIEN Input file format set");         break;      case 'H':         if (NextArg() != STRINGARG)            HError(3219,"HVite: MMF File name expected");         AddMMF(&hset,GetStrArg());          break;      case 'I':         if (NextArg() != STRINGARG)            HError(3219,"HVite: MLF file name expected");         LoadMasterFile(GetStrArg()); break;      case 'J':         if (NextArg()!=STRINGARG)            HError(3219,"HVite: MLLR transform file expected");         transFile = GetStrArg(); break;      case 'K':         if (NextArg()!=STRINGARG)            HError(3219,"HVite: MLLR transform output filename expected");         outTransFile = GetStrArg(); break;      case 'L':         if (NextArg()!=STRINGARG)            HError(3219,"HVite: Label/network file directory expected");         labInDir = GetStrArg(); break;      case 'P':         if (NextArg() != STRINGARG)            HError(3219,"HVite: Target Label File format expected");         if((ofmt = Str2Format(GetStrArg())) == ALIEN)            HError(-3289,"HVite: Warning ALIEN Label output file format set");         break;      case 'B':         saveBinary = TRUE;         break;      case 'T':         trace = GetChkedInt(0,511,s); break;      case 'X':         if (NextArg()!=STRINGARG)            HError(3219,"HVite: Input label/network file extension expected");         labInExt = GetStrArg(); break;      default:         HError(3219,"HVite: Unknown switch %s",s);      }   }      if (outTransFile != NULL && uid == NULL)      HError(3219,"HVite: User identifier expected when saving a TMF");   if (NextArg()!=STRINGARG)      HError(3219,"HVite: Dictionary file name expected");   dictFn = GetStrArg();   if (NextArg()!=STRINGARG)      HError(3219,"HVite: HMM list  file name expected");   hmmListFn = GetStrArg();   if ((states || models) && nToks>1)      HError(3230,"HVite: Alignment using multiple tokens is not supported");   if (NumArgs()==0 && wdNetFn==NULL)      HError(3230,"HVite: Network must be specified for recognition from audio");   if (loadNetworks && loadLabels)      HError(3230,"HVite: Must choose either alignment from network or labels");   if (nToks>1 && latExt==NULL && nTrans==1)      HError(-3230,"HVite: Performing nbest recognition with no nbest output");   Initialise();   /* Process the data */   if (wdNetFn==NULL)      DoAlignment();   else      DoRecognition();   /* Free up and we are done */   if (trace & T_MEM) {      printf("Memory State on Completion\n");      PrintAllHeapStats();   }   DeleteVRecInfo(vri);   ResetHeap(&netHeap);   FreePSetInfo(psi);   if (outTransFile != NULL)      SaveTransformSet(&hset, rt, outTransFile, NULL, uid, uname,                        chan, desc, FALSE, FALSE, saveBinary);   ResetHeap(&regHeap);   ResetHeap(&modelHeap);   Exit(0);   return (0);          /* never reached -- make compiler happy */}/* --------------------------- Initialisation ----------------------- *//* Initialise: set up global data structures */void Initialise(void){   Boolean loadTransStats=FALSE;   Boolean eSep;   int s;   /* Load hmms, convert to inverse DiagC */   if(MakeHMMSet(&hset,hmmListFn)<SUCCESS)       HError(3228,"Initialise: MakeHMMSet failed");   SetParmHMMSet(&hset);   if(LoadHMMSet(&hset,hmmDir,hmmExt)<SUCCESS)       HError(3228,"Initialise: LoadHMMSet failed");   ConvDiagC(&hset,TRUE);      /* Create observation and storage for input buffer */   SetStreamWidths(hset.pkind,hset.vecSize,hset.swidth,&eSep);   obs=MakeObservation(&gstack,hset.swidth,hset.pkind,                       hset.hsKind==DISCRETEHS,eSep);   if (transFile != NULL || update > 0) {      CreateHeap(&regHeap,   "regClassStore",  MSTAK, 1, 0.5, 1000, 8000 );      rt = (RegTransInfo *) New(&regHeap, sizeof(RegTransInfo));      rt->nBlocks = 0;      rt->classKind = DEF_REGCLASS;      rt->adptSil = TRI_UNDEF;      rt->nodeOccThresh = 0.0;      /* if online adaptation then initailise some extra structures */      if (update > 0) {         InitialiseTransform(&hset, &regHeap, rt, TRUE);         /* initialise structures for the f-b frame-state alignment pass */         utt = (UttInfo *) New(&regHeap, sizeof(UttInfo));         fbInfo = (FBInfo *) New(&regHeap, sizeof(FBInfo));              /* initialise a recogniser for frame/state alignment purposes */         alignpsi=InitPSetInfo(&hset);         alignvri=InitVRecInfo(alignpsi,1,TRUE,FALSE);         SetPruningLevels(alignvri,0,genBeam,-LZERO,0.0,tmBeam);         /* initialise core structures and memory for the adaptation process */         InitialiseAdapt(&hset, &regHeap, rt);         InitUttInfo(utt, FALSE);         InitialiseForBack(fbInfo, &regHeap, &hset, rt,                           (UPDSet) (UPADAPT|UPMIXES), genBeam*2.0, genBeam*2.0,                            genBeam*4.0+1.0, 10.0);         utt->twoDataFiles = FALSE;         utt->S = hset.swidth[0];       }      else         InitialiseTransform(&hset, &regHeap, rt, FALSE);   }       if (transFile != NULL) {      if (rt->rtree == NULL)         HError(3232, "Main: Error loading the MLLR transforms!\n");      LoadTransformSet(&hset, transFile, uid, rt, &loadTransStats);      if (rt->transId->name != NULL && rt->transId->uid != NULL)         printf("Loaded speaker transforms for %s (%s)\n", rt->transId->name,                rt->transId->uid);      ApplyTransforms(rt);   }   /* Create observation and storage for input buffer */   SetStreamWidths(hset.pkind,hset.vecSize,hset.swidth,&eSep);   obs=MakeObservation(&gstack,hset.swidth,hset.pkind,                       hset.hsKind==DISCRETEHS,eSep);   CreateHeap(&bufHeap,"Input Buffer heap",MSTAK,1,0.0,50000,50000);   CreateHeap(&repHeap,"Replay Buffer heap",MSTAK,1,0.0,50000,50000);      maxM = MaxMixInSet(&hset);   for (s=1; s<=hset.swidth[0]; s++)      maxMixInS[s] = MaxMixInSetS(&hset, s);   if (trace&T_TOP) {      printf("Read %d physical / %d logical HMMs\n",             hset.numPhyHMM,hset.numLogHMM);  fflush(stdout);   }      /* Initialise recogniser */   if (nToks>1) nBeam=genBeam;   psi=InitPSetInfo(&hset);   vri=InitVRecInfo(psi,nToks,models,states);   /* Read dictionary and create storage for lattice */   InitVocab(&vocab);      if(ReadDict(dictFn,&vocab)<SUCCESS)       HError(3213, "Main: ReadDict failed");   CreateHeap(&ansHeap,"Lattice heap",MSTAK,1,0.0,4000,4000);   if (trace & T_MEM){      printf("Memory State After Initialisation\n");      PrintAllHeapStats();   }}/* ------------------ Utterance Level Recognition  ----------------------- *//* ReplayAudio:  replay the last audio input */void ReplayAudio(BufferInfo info){   AudioOut ao;   if (info.a != NULL) {      ao = OpenAudioOutput(&repHeap,&(info.srcSampRate));      PlayReplayBuffer(ao, info.a);      while (SamplesToPlay(ao) > 0 );      CloseAudioOutput(ao);   }}/* DoOnlineAdaptation: Perform unsupervised online adaptation   using the recognition hypothesis as the transcription */int DoOnlineAdaptation(Lattice *lat, ParmBuf pbuf, int nFrames){   Transcription *modelTrans, *trans;   BufferInfo pbinfo;   Lattice *alignLat, *wordNet;   Network *alignNet;   int i;   GetBufferInfo(pbuf,&pbinfo);   trans=TranscriptionFromLattice(&netHeap,lat,1);   wordNet=LatticeFromLabels(GetLabelList(trans,1),bndId,                             &vocab,&netHeap);   alignNet=ExpandWordNet(&netHeap,wordNet,&vocab,&hset);   StartRecognition(alignvri,alignNet,0.0,0.0,0.0);        /* do forced alignment */   for (i = 0; i < nFrames; i++) {      ReadAsTable(pbuf, i, &obs);      ProcessObservation(alignvri,&obs,-1);   }       alignLat=CompleteRecognition(alignvri,                                pbinfo.tgtSampRate/10000000.0,                                &netHeap);           if (alignvri->noTokenSurvived) {      Dispose(&netHeap, trans);      /* Return value 0 to indicate zero frames process failed */      return 0;   }   modelTrans=TranscriptionFromLattice(&netHeap,alignLat,1);         /* format the transcription so that it contains just the models */   FormatTranscription(modelTrans,pbinfo.tgtSampRate,FALSE,TRUE,                       FALSE,FALSE,TRUE,FALSE,TRUE,TRUE, FALSE);   /* Now do the frame/state alignment accumulating MLLR statistics */   /* set the various values in the utterance storage */   utt->tr = modelTrans;   utt->pbuf = pbuf;   utt->Q = CountLabs(utt->tr->head);   utt->T = nFrames;   utt->ot = obs;     /* do frame state alignment and accumulate statistics */   if (!FBFile(fbInfo, utt, NULL))     nFrames = 0;   Dispose(&netHeap, trans);   if (trace&T_TOP) {      printf("Accumulated statistics...\n");       fflush(stdout);   }   return nFrames;} /* ProcessFile: process given file. If fn=NULL then direct audio */Boolean ProcessFile(char *fn, Network *net, int utterNum, LogDouble currGenBeam, Boolean restartable){   FILE *file;   ParmBuf pbuf;   BufferInfo pbinfo;   NetNode *d;   Lattice *lat;

⌨️ 快捷键说明

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