int main_HCopy(int argc, char *argv[]) { char *s; /* next file to process */ void OpenSpeechFile(char *s); void AppendSpeechFile(char *s); void PutTargetFile(char *s); if(InitShell(argc,argv,hcopy_version,hcopy_vc_id)<SUCCESS) HError(1000,"HCopy: InitShell failed"); InitMem(); InitLabel(); InitMath(); InitSigP(); InitWave(); InitAudio(); InitVQ(); InitModel(); if(InitParm()<SUCCESS) HError(1000,"HCopy: InitParm failed"); if (!InfoPrinted() && NumArgs() == 0) ReportUsageHCopy(); if (NumArgs() == 0) return(0); SetConfParmsHCopy(); /* initial trace string is null */ trList.str = NULL; CreateHeap(&iStack, "InBuf", MSTAK, 1, 0.0, STACKSIZE, LONG_MAX); CreateHeap(&oStack, "OutBuf", MSTAK, 1, 0.0, STACKSIZE, LONG_MAX); CreateHeap(&cStack, "ChopBuf", MSTAK, 1, 0.0, STACKSIZE, LONG_MAX); CreateHeap(&lStack, "LabBuf", MSTAK, 1, 0.0, 10000, LONG_MAX); CreateHeap(&tStack, "Trace", MSTAK, 1, 0.0, 100, 200); while (NextArg() == SWITCHARG) { s = GetSwtArg(); if (strlen(s)!=1) HError(1019,"HCopy: Bad switch %s; must be single letter",s); switch(s[0]){ case 'a': if (NextArg() != INTARG) HError(1019,"HCopy: Auxiliary label index expected"); auxLab = GetChkedInt(1,100000,s) - 1; break; case 'e': /* end time in seconds, max 10e5 secs */ en = GetChkedFlt(-MAXTIME,MAXTIME,s); stenSet = TRUE; chopF = TRUE; break; case 'i': if (NextArg() != STRINGARG) HError(1019,"HCopy: Output MLF name expected"); if(SaveToMasterfile(GetStrArg())<SUCCESS) HError(1014,"HCopy: Cannot write to MLF"); useMLF = TRUE; labF = TRUE; break; case 'l': if (NextArg() != STRINGARG) HError(1019,"HCopy: Target label file directory expected"); outLabDir = GetStrArg(); labF = TRUE; break; case 'm': xMargin = GetChkedFlt(-MAXTIME,MAXTIME,s); chopF = TRUE; break; case 'n': if (NextArg() != INTARG) HError(1019,"HCopy: Label index expected"); labstidx= GetChkedInt(-100000,100000,s); if (NextArg() == INTARG) labenidx = GetChkedInt(-100000,100000,s); chopF = TRUE; break; case 's': /* start time in seconds */ st = GetChkedFlt(0,MAXTIME,s); stenSet = TRUE; chopF = TRUE; break; case 't': if (NextArg() != INTARG) HError(1019,"HCopy: Trace line width expected"); traceWidth= GetChkedInt(10,100000,s); break; case 'x': if (NextArg() != STRINGARG) HError(1019,"HCopy: Label name expected"); labName = GetLabId(GetStrArg(),TRUE); if (NextArg() == INTARG) labRep = GetChkedInt(1,100000,s); chopF = TRUE; labF = TRUE; break; case 'F': if (NextArg() != STRINGARG) HError(1019,"HCopy: Source file format expected"); if((srcFF = Str2Format(GetStrArg())) == ALIEN) HError(-1089,"HCopy: Warning ALIEN src file format set"); break; case 'G': if (NextArg() != STRINGARG) HError(1019,"HCopy: Source label File format expected"); if((srcLabFF = Str2Format(GetStrArg())) == ALIEN) HError(-1089,"HCopy: Warning ALIEN Label output file format set"); labF= TRUE; break; case 'I': if (NextArg() != STRINGARG) HError(1019,"HCopy: MLF file name expected"); LoadMasterFile(GetStrArg()); labF = TRUE; break; case 'L': if (NextArg()!=STRINGARG) HError(1019,"HCopy: Label file directory expected"); labDir = GetStrArg(); labF = TRUE; break; case 'P': if (NextArg() != STRINGARG) HError(1019,"HCopy: Label File format expected"); if((tgtLabFF = Str2Format(GetStrArg())) == ALIEN) HError(-1089,"HCopy: Warning ALIEN Label file format set"); labF = TRUE; break; case 'O': if (NextArg() != STRINGARG) HError(1019,"HCopy: Target file format expected"); if((tgtFF = Str2Format(GetStrArg())) == ALIEN) HError(-1089,"HCopy: Warning ALIEN target file format set"); break; case 'T': trace = GetChkedInt(0,16,s); break; case 'X': if (NextArg()!=STRINGARG) HError(1019,"HCopy: Label file extension expected"); labExt = GetStrArg(); labF = TRUE; break; default: HError(1019,"HCopy: Unknown switch %s",s); } } if (NumArgs() == 1) HError(1019,"HCopy: Target file or + operator expected"); FixOptions(); while (NumArgs()>1) { /* process group S1 + S2 + ... TGT */ off = 0.0; if (NextArg()!=STRINGARG) HError(1019,"HCopy: Source file name expected"); s = GetStrArg(); OpenSpeechFile(s); /* Load initial file S1 */ if (NextArg()!=STRINGARG) HError(1019,"HCopy: Target file or + operator expected"); s = GetStrArg(); while (strcmp(s,"+") == 0) { /* Append + S2 + S3 ... */ if (NextArg()!=STRINGARG) HError(1019,"HCopy: Append file name expected"); s = GetStrArg(); AppendSpeechFile(s); if (NextArg()!=STRINGARG) HError(1019,"HCopy: Target file or + operator expected"); s = GetStrArg(); } PutTargetFile(s); if(trace & T_MEM) PrintAllHeapStats(); if(trans != NULL){ trans = NULL; ResetHeap(&lStack); } ResetHeap(&iStack); ResetHeap(&oStack); if(chopF) ResetHeap(&cStack); } if(useMLF) CloseMLFSaveFile(); if (NumArgs() != 0) HError(-1019,"HCopy: Unused args ignored"); return (0); /* never reached -- make compiler happy */ }
int main(int argc, char *argv[]) { char * labFn, *listfn, *s; int i,fidx; MLFEntry *me = NULL; Transcription *t; void InitStats(char *listfn); void GatherStats(Transcription *t); void OutputStats(void); if(InitShell(argc,argv,hlstats_version,hlstats_vc_id)<SUCCESS) HError(1300,"HLStats: InitShell failed"); InitMem(); InitMath(); InitWave(); InitLabel(); InitLM(); if (!InfoPrinted() && NumArgs() == 0) ReportUsage(); if (NumArgs() == 0) Exit(0); SetConfParms(); enterId=GetLabId("!ENTER",TRUE); /* All sentences should or are coerced */ exitId=GetLabId("!EXIT",TRUE); /* to start enterId and end exitId */ nullId=GetLabId("!NULL",TRUE); /* Name for words not in list */ while (NextArg() == SWITCHARG) { s = GetSwtArg(); if (strlen(s)!=1) HError(1319,"HLStats: Bad switch %s; must be single letter",s); switch(s[0]){ case 'b': doBigram = TRUE; if (NextArg() != STRINGARG) HError(1319,"HLStats: Ngram output file name expected"); bigFile = GetStrArg(); break; case 'c': doLCount = TRUE; lCountLimit = GetChkedInt(0,100000,s); break; case 'd': doDurs = TRUE; break; case 'f': bigFloor = GetChkedFlt(0.0,1000.0,s); break; case 'h': hSize = GetChkedInt(1,2,s); break; case 'l': doList = TRUE; if (NextArg() != STRINGARG) HError(1319,"HLStats: Output label list file name expected"); listFile = GetStrArg(); break; case 'o': doBOff = TRUE; break; case 'p': doPCount = TRUE; pCountLimit = GetChkedInt(0,100000,s); break; case 's': if (NextArg() != STRINGARG) HError(1319,"HLStats: ENTER label name expected"); enterId=GetLabId(GetStrArg(),TRUE); if (NextArg() != STRINGARG) HError(1319,"HLStats: EXIT label name expected"); exitId=GetLabId(GetStrArg(),TRUE); break; case 't': bigThresh = GetChkedInt(0,100,s); break; case 'u': uniFloor = GetChkedFlt(0.0,1000.0,s); break; case 'G': if (NextArg() != STRINGARG) HError(1319,"HLStats: Input label File format expected"); if((ff = Str2Format(GetStrArg())) == ALIEN) HError(-1389,"HLStats: Warning ALIEN Label file format set"); break; case 'I': if (NextArg() != STRINGARG) HError(1319,"HLStats: Input MLF file name expected"); LoadMasterFile(GetStrArg()); break; case 'T': if (NextArg() != INTARG) HError(1319,"HLStats: Trace value expected"); trace = GetChkedInt(0,017,s); break; default: HError(1319,"HLStats: Unknown switch %s",s); } } if (NextArg()!=STRINGARG) HError(1319,"HLStats: Label list file name expected"); listfn = GetStrArg(); if (!(doDurs || doBigram || doList || doLCount || doPCount)) HError(1330,"HLStats: Nothing to do!"); InitStats(listfn); i=0; while (NumArgs()>0) { if (NextArg()!=STRINGARG) HError(1319,"HLStats: Input label file name expected"); labFn = GetStrArg(); if (IsMLFFile(labFn)) { fidx = NumMLFFiles(); if ((me=GetMLFTable()) != NULL) { while(me->next != NULL) me=me->next; LoadMasterFile(labFn); me=me->next; } else { LoadMasterFile(labFn); me=GetMLFTable(); } while (me != NULL) { if (me->type == MLF_IMMEDIATE && me->def.immed.fidx == fidx) { if (trace&T_FIL) { printf(" Processing file %s\n",me->pattern); fflush(stdout); } t = LOpen(&tmpHeap,me->pattern,ff); if (t->numLists<1) HError(-1330,"HLStats: Empty file %s",me->pattern); else GatherStats(t),i++; Dispose(&tmpHeap,t); } me = me->next; if ((trace&T_BAS) && !(trace&T_FIL) && NumMLFEntries()>5000 && i%1000==0) printf(". "),fflush(stdout); } if ((trace&T_BAS) && !(trace&T_FIL) && NumMLFEntries()>5000) printf("\n"); } else { if (trace&T_FIL) { printf(" Processing file %s\n",labFn); fflush(stdout); } t = LOpen(&tmpHeap,labFn,ff); if (t->numLists<1) HError(-1330,"HLStats: Empty file %s",me->pattern); else GatherStats(t),i++; Dispose(&tmpHeap,t); } } if (trace&T_MEM) PrintAllHeapStats(); OutputStats(); if (trace&T_MEM) PrintAllHeapStats(); Exit(0); return (0); /* never reached -- make compiler happy */ }
/* InitDecoderInst Initialise previously created decoder instance. This needs to be called before each utterance. */ void InitDecoderInst (DecoderInst *dec, LexNet *net, HTime sampRate, LogFloat beamWidth, LogFloat relBeamWidth, LogFloat weBeamWidth, LogFloat zsBeamWidth, int maxModel, LogFloat insPen, float acScale, float pronScale, float lmScale, LogFloat fastlmlaBeam) { int i; dec->net = net; if (dec->nLayers) { Dispose (&dec->heap,dec->instsLayer); } /* alloc InstsLayer start pointers */ dec->nLayers = net->nLayers; dec->instsLayer = (LexNodeInst **) New (&dec->heap, net->nLayers * sizeof (LexNodeInst *)); /* reset inst (i.e. reset pruning, etc.) purge all heaps */ ResetHeap (&dec->nodeInstanceHeap); ResetHeap (&dec->weHypHeap); if (dec->latgen) ResetHeap (&dec->altweHypHeap); #ifdef MODALIGN if (dec->modAlign) ResetHeap (&dec->modendHypHeap); #endif ResetHeap (&dec->nodeInstanceHeap); for (i = 0; i < dec->maxNStates; ++i) ResetHeap (&dec->tokSetHeap[i]); ResetHeap (&dec->relTokHeap); if (trace & T_MEM) { printf ("memory stats at start of recognition\n"); PrintAllHeapStats (); } dec->frame = 0; dec->frameDur = sampRate / 1.0e7; dec->maxModel = maxModel; dec->beamWidth = beamWidth; dec->weBeamWidth = weBeamWidth; dec->zsBeamWidth = zsBeamWidth; dec->curBeamWidth = dec->beamWidth; dec->relBeamWidth = - relBeamWidth; dec->beamLimit = LZERO; if (fastlmlaBeam < -LSMALL) { dec->fastlmla = TRUE; dec->fastlmlaBeam = - fastlmlaBeam; } else { dec->fastlmla = FALSE; dec->fastlmlaBeam = LZERO; } dec->tokSetIdCount = 0; dec->insPen = insPen; dec->acScale = acScale; dec->pronScale = pronScale; dec->lmScale = lmScale; dec->maxLMLA = dec->lmScale * maxLMLA; /* HRec computes interval of possible predecessor states j for each destination state i in each transition matrix (seIndexes). */ /* alloc temp tokenset arrays for use in PropagateInternal */ for (i=1; i <= dec->maxNStates; ++i) dec->tempTS[i] = NewTokSetArray (dec, i); /* alloc winTok array for MergeTokSet */ dec->winTok = (RelToken *) New (&dec->heap, 2 * dec->nTok * sizeof (RelToken)); /* init lists of active LexNode Instances */ for (i = 0; i < dec->nLayers; ++i) dec->instsLayer[i] = NULL; /* deactivate all nodes */ for (i = 0; i < dec->net->nNodes; ++i) { dec->net->node[i].inst = NULL; #ifdef COLLECT_STATS_ACTIVATION dec->net->node[i].eventT = -1; #endif } ActivateNode (dec, dec->net->start); dec->net->start->inst->ts[0].n = 1; dec->net->start->inst->ts[0].score = 0.0; dec->net->start->inst->ts[0].relTok[0] = startTok; dec->net->start->inst->ts[0].relTok[0].lmState = LMInitial (dec->lm); #ifdef COLLECT_STATS dec->stats.nTokSet = 0; dec->stats.sumTokPerTS = 0; dec->stats.nActive = 0; dec->stats.nActivate = 0; dec->stats.nDeActivate = 0; dec->stats.nFrames = 0; dec->stats.nLMlaCacheHit = 0; dec->stats.nLMlaCacheMiss = 0; #ifdef COLLECT_STATS_ACTIVATION dec->stats.lnINF = 0; { int i; for (i = 0; i <= STATS_MAXT; ++i) dec->stats.lnDeadT[i] = dec->stats.lnLiveT[i] = 0; } #endif #endif /* LM lookahead cache */ dec->lmCache = CreateLMCache (dec, &dec->heap); /* invalidate OutP cache */ ResetOutPCache (dec->outPCache); }
/* 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)) && (hset.semiTied == NULL)) { 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); } } } }
/* 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; LArc *arc,*cur; LNode *node; Transcription *trans; MLink m; LogFloat lmlk,aclk; int s,j,tact,nFrames; LatFormat form; char *p,lfn[255],buf1[80],buf2[80],thisFN[MAXSTRLEN]; Boolean enableOutput = TRUE, isPipe; if (fn!=NULL) strcpy(thisFN,fn); else if (fn==NULL && saveAudioOut) CounterFN(roPrefix,roSuffix,++roCounter,4,thisFN); else enableOutput = FALSE; if((pbuf = OpenBuffer(&bufHeap,fn,50,dfmt,TRI_UNDEF,TRI_UNDEF))==NULL) HError(3250,"ProcessFile: Config parameters invalid"); /* Check pbuf same as hset */ GetBufferInfo(pbuf,&pbinfo); if (pbinfo.tgtPK!=hset.pkind) HError(3231,"ProcessFile: Incompatible sample kind %s vs %s", ParmKind2Str(pbinfo.tgtPK,buf1), ParmKind2Str(hset.pkind,buf2)); if (pbinfo.a != NULL && replay) AttachReplayBuf(pbinfo.a, (int) (3*(1.0E+07/pbinfo.srcSampRate))); StartRecognition(vri,net,lmScale,wordPen,prScale); SetPruningLevels(vri,maxActive,currGenBeam,wordBeam,nBeam,tmBeam); tact=0;nFrames=0; StartBuffer(pbuf); while(BufferStatus(pbuf)!=PB_CLEARED) { ReadAsBuffer(pbuf,&obs); if (trace&T_OBS) PrintObservation(nFrames,&obs,13); 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); } /* only output 1-best transcription if generating lattices */ if (nTrans > 1 && latExt != NULL) trans=TranscriptionFromLattice(&ansHeap,lat,1); /* output N-best transcriptions as usual */ else 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; }
/* Initialise: set up global data structures */ void Initialise(void) { Boolean eSep; int s; /* Load hmms, convert to inverse DiagC */ if(MakeHMMSet(&hset,hmmListFn)<SUCCESS) HError(3228,"Initialise: MakeHMMSet failed"); 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); /* sort out masks just in case using adaptation */ if (xfInfo.inSpkrPat == NULL) xfInfo.inSpkrPat = xfInfo.outSpkrPat; if (xfInfo.paSpkrPat == NULL) xfInfo.paSpkrPat = xfInfo.outSpkrPat; if (xfInfo.useOutXForm || (update>0)) { CreateHeap(®Heap, "regClassStore", MSTAK, 1, 0.5, 1000, 8000 ); /* This initialises things - temporary hack - THINK!! */ CreateAdaptXForm(&hset, "tmp"); /* initialise structures for the f-b frame-state alignment pass */ utt = (UttInfo *) New(®Heap, sizeof(UttInfo)); fbInfo = (FBInfo *) New(®Heap, 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); InitUttInfo(utt, FALSE); InitialiseForBack(fbInfo, ®Heap, &hset, (UPDSet) (UPXFORM), genBeam*2.0, genBeam*2.0, genBeam*4.0+1.0, 10.0); utt->twoDataFiles = FALSE; utt->S = hset.swidth[0]; AttachPreComps(&hset,hset.hmem); } 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(); } }
int main(int argc, char *argv[]) { char *s; void Initialise(void); void DoRecognition(void); void DoAlignment(void); if(InitShell(argc,argv,hvite_version,hvite_vc_id)<SUCCESS) HError(3200,"HVite: InitShell failed"); InitMem(); InitLabel(); InitMath(); InitSigP(); InitWave(); InitAudio(); InitVQ(); InitModel(); if(InitParm()<SUCCESS) HError(3200,"HVite: InitParm failed"); InitDict(); InitNet(); InitRec(); InitUtil(); InitAdapt(&xfInfo); InitMap(); if (!InfoPrinted() && NumArgs() == 0) ReportUsage(); if (NumArgs() == 0) Exit(0); SetConfParms(); CreateHeap(&modelHeap, "Model heap", MSTAK, 1, 0.0, 100000, 800000 ); CreateHMMSet(&hset,&modelHeap,TRUE); while (NextArg() == SWITCHARG) { s = GetSwtArg(); if (strlen(s)!=1) HError(3219,"HVite: Bad switch %s; must be single letter",s); switch(s[0]){ case 'a': loadLabels=TRUE; break; case 'b': if (NextArg()!=STRINGARG) HError(3219,"HVite: Utterance boundary word expected"); bndId = GetLabId(GetStrArg(),TRUE); break; case 'c': tmBeam = GetChkedFlt(0.0,1000.0,s); break; case 'd': if (NextArg()!=STRINGARG) HError(3219,"HVite: HMM definition directory expected"); hmmDir = GetStrArg(); break; case 'e': saveAudioOut=TRUE; break; case 'f': states=TRUE; break; case 'g': replay=TRUE; break; case 'i': if (NextArg()!=STRINGARG) HError(3219,"HVite: Output MLF file name expected"); /* if(SaveToMasterfile(GetStrArg())<SUCCESS) HError(3214,"HCopy: Cannot write to MLF"); */ SaveToMasterfile(GetStrArg()); break; case 'k': xfInfo.useInXForm = TRUE; break; case 'j': if (NextArg()!=INTARG) HError(3219,"HVite: No. of files per online adaptation step expected"); update = GetChkedInt(1,256,s); break; case 'l': if (NextArg()!=STRINGARG) HError(3219,"HVite: Label file directory expected"); labDir = GetStrArg(); break; case 'm': models=TRUE; break; case 'n': nToks = GetChkedInt(2,MAX_TOKS,s); if (NextArg()==FLOATARG || NextArg()==INTARG) nTrans = GetChkedInt(1,10000,s); else nTrans = 1; break; case 'o': if (NextArg()!=STRINGARG) HError(3219,"HVite: Output label format expected"); labForm = GetStrArg(); break; case 'p': wordPen = GetChkedFlt(-1000.0,1000.0,s); break; case 'q': if (NextArg()!=STRINGARG) HError(3219,"HVite: Output lattice format expected"); latForm = GetStrArg(); break; case 'r': 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 '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; case 'h': if (NextArg()!=STRINGARG) HError(1,"Speaker name pattern expected"); xfInfo.outSpkrPat = GetStrArg(); if (NextArg()==STRINGARG) { xfInfo.inSpkrPat = GetStrArg(); if (NextArg()==STRINGARG) xfInfo.paSpkrPat = GetStrArg(); } if (NextArg() != SWITCHARG) HError(2319,"HERest: cannot have -h as the last option"); break; case 'E': if (NextArg()!=STRINGARG) HError(2319,"HERest: parent transform directory expected"); xfInfo.usePaXForm = TRUE; xfInfo.paXFormDir = GetStrArg(); if (NextArg()==STRINGARG) xfInfo.paXFormExt = GetStrArg(); if (NextArg() != SWITCHARG) HError(2319,"HVite: cannot have -E as the last option"); break; case 'J': if (NextArg()!=STRINGARG) HError(2319,"HERest: input transform directory expected"); AddInXFormDir(&hset,GetStrArg()); if (NextArg()==STRINGARG) xfInfo.inXFormExt = GetStrArg(); if (NextArg() != SWITCHARG) HError(2319,"HVite: cannot have -J as the last option"); break; case 'K': if (NextArg()!=STRINGARG) HError(2319,"HVite: output transform directory expected"); xfInfo.outXFormDir = GetStrArg(); xfInfo.useOutXForm = TRUE; if (NextArg()==STRINGARG) xfInfo.outXFormExt = GetStrArg(); if (NextArg() != SWITCHARG) HError(2319,"HVite: cannot have -K as the last option"); break; default: HError(3219,"HVite: Unknown switch %s",s); } } 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(); #ifndef PHNALG if ((states || models) && nToks>1) HError(3230,"HVite: Alignment using multiple tokens is not supported"); #endif 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"); if (nToks > 1 && latExt != NULL && nTrans > 1) HError(-3230,"HVite: Performing nbest recognition with 1-best and latttices output"); if ((update>0) && (!xfInfo.useOutXForm)) HError(3230,"HVite: Must use -K option with incremental adaptation"); 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); UpdateSpkrStats(&hset,&xfInfo, NULL); ResetHeap(®Heap); ResetHeap(&modelHeap); Exit(0); return (0); /* never reached -- make compiler happy */ }