/* LoadFile: load whole file or segments and accumulate variance */ static void LoadFile(char *fn) { ParmBuf pbuf; BufferInfo info; char labfn[80]; Transcription *trans; long segStIdx,segEnIdx; int i,j,ncas,nObs; LLink p; if (segId == NULL) { /* load whole parameter file */ if((pbuf=OpenBuffer(&iStack, fn, 0, dff, FALSE_dup, FALSE_dup))==NULL) HError(2050,"LoadFile: Config parameters invalid"); GetBufferInfo(pbuf,&info); CheckData(fn,info); nObs = ObsInBuffer(pbuf); for (i=0; i<nObs; i++){ ReadAsTable(pbuf,i,&obs); AccVar(obs); } if (trace&T_LOAD) { printf(" %d observations loaded from %s\n",nObs,fn); fflush(stdout); } CloseBuffer(pbuf); } else { /* load segment of parameter file */ MakeFN(fn,labDir,labExt,labfn); trans = LOpen(&iStack,labfn,lff); ncas = NumCases(trans->head,segId); if ( ncas > 0) { if((pbuf=OpenBuffer(&iStack, fn, 0, dff, FALSE_dup, FALSE_dup))==NULL) HError(2050,"LoadFile: Config parameters invalid"); GetBufferInfo(pbuf,&info); CheckData(fn,info); for (i=1,nObs=0; i<=ncas; i++) { p = GetCase(trans->head,segId,i); segStIdx= (long) (p->start/info.tgtSampRate); segEnIdx = (long) (p->end/info.tgtSampRate); if (trace&T_SEGS) printf(" loading seg %s [%ld->%ld]\n", segId->name,segStIdx,segEnIdx); if (segEnIdx >= ObsInBuffer(pbuf)) segEnIdx = ObsInBuffer(pbuf)-1; if (segEnIdx >= segStIdx) { for (j=segStIdx;j<=segEnIdx;j++) { ReadAsTable(pbuf,j,&obs); AccVar(obs); ++nObs; } } } CloseBuffer(pbuf); if (trace&T_LOAD) printf(" %d observations loaded from %s\n",nObs,fn); } } ResetHeap(&iStack); }
/* AppendParm: append the src file to current Buffer pb. Return appended len */ HTime AppendParm(char *src) { int i; char bf1[MAXSTRLEN]; char bf2[MAXSTRLEN]; short swidth[SMAX]; Boolean eSep; ParmBuf b, cb; Observation o; BufferInfo info; if((b = OpenBuffer(&iStack,src,0,srcFF,TRI_UNDEF,TRI_UNDEF))==NULL) HError(1050,"AppendParm: Config parameters invalid"); GetBufferInfo(b,&info); if(trace & T_KINDS ){ printf("Appending file %s format: %s [%s]->[%s]\n",src, Format2Str(info.srcFF), ParmKind2Str(info.srcPK,bf1), ParmKind2Str(info.tgtPK,bf2)); } if (tgtSampRate != info.tgtSampRate) HError(1032,"AppendParm: Input file %s has inconsistent sample rate",src); if ( BaseParmKind(tgtPK) != BaseParmKind(info.tgtPK)) HError(1032,"AppendParm: Input file %s has inconsistent tgt format",src); cb = (chopF)?ChopParm(b,st,en,info.tgtSampRate) : b; ZeroStreamWidths(swidth0,swidth); SetStreamWidths(info.tgtPK,info.tgtVecSize,swidth,&eSep); o = MakeObservation(&iStack, swidth, info.tgtPK, saveAsVQ, eSep); for (i=0; i < ObsInBuffer(cb); i++){ ReadAsTable(cb, i, &o); AddToBuffer(pb, o); } CloseBuffer(cb); return(i*info.tgtSampRate); }
/* 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,xfInfo.inXForm); } 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 */ fbInfo->inXForm = xfInfo.inXForm; fbInfo->al_inXForm = xfInfo.inXForm; fbInfo->paXForm = xfInfo.paXForm; if (!FBFile(fbInfo, utt, NULL)) nFrames = 0; Dispose(&netHeap, trans); if (trace&T_TOP) { printf("Accumulated statistics...\n"); fflush(stdout); } return nFrames; }
/* ChopParm: return parm chopped to st and end. end = 0 means all */ ParmBuf ChopParm(ParmBuf b, HTime start, HTime end, HTime sampRate) { int stObs, endObs, nObs, i; HTime length; short swidth[SMAX]; Boolean eSep; ParmBuf cb; Observation o; BufferInfo info; length = ObsInBuffer(b) * sampRate; ClampStEn(length,&start,&end); if(start >= length) HError(1030,"ChopParm: Src file too short to get data from %.0f",start); if(trace & T_SEGMENT) printf("ChopParm: Extracting segment %.0f to %.0f\n",start,end); stObs = (int) (start/sampRate); endObs = (int) (end/sampRate); nObs = endObs -stObs; if(nObs <= 0) HError(1030,"ChopParm: Truncation options result in zero-length file"); GetBufferInfo(b,&info); ZeroStreamWidths(swidth0,swidth); SetStreamWidths(tgtPK,info.tgtVecSize,swidth,&eSep); o = MakeObservation(&cStack, swidth, info.tgtPK, saveAsVQ, eSep); if (saveAsVQ){ if (info.tgtPK&HASNULLE){ info.tgtPK=DISCRETE+HASNULLE; }else{ info.tgtPK=DISCRETE; } } cb = EmptyBuffer(&cStack, nObs, o, info); for (i=stObs; i < endObs; i++){ ReadAsTable(b, i, &o); AddToBuffer(cb, o); } CloseBuffer(b); if(chopF && labF) ChopLabs(tr,start,end); return(cb); }
/* OpenParmFile: open source parm file and return length */ HTime OpenParmFile(char *src) { int i; ParmBuf b, cb; short swidth[SMAX]; Boolean eSep; Observation o; BufferInfo info; if((b = OpenBuffer(&iStack,src,0,srcFF,TRI_UNDEF,TRI_UNDEF))==NULL) HError(1050,"OpenParmFile: Config parameters invalid"); GetBufferInfo(b,&info); srcSampRate = info.srcSampRate; tgtSampRate = info.tgtSampRate; srcPK = info.srcPK; tgtPK = info.tgtPK; cb = chopF?ChopParm(b,st,en,info.tgtSampRate):b; ZeroStreamWidths(swidth0,swidth); SetStreamWidths(info.tgtPK,info.tgtVecSize,swidth,&eSep); o = MakeObservation(&oStack, swidth, info.tgtPK, saveAsVQ, eSep); if (saveAsVQ){ if (info.tgtPK&HASNULLE){ info.tgtPK=DISCRETE+HASNULLE; }else{ info.tgtPK=DISCRETE; } } pb = EmptyBuffer(&oStack, ObsInBuffer(cb), o, info); for(i=0; i < ObsInBuffer(cb); i++){ ReadAsTable(cb, i, &o); AddToBuffer(pb, o); } CloseBuffer(cb); if( info.nSamples > 0 ) return(info.nSamples*srcSampRate); else return(ObsInBuffer(pb)*info.tgtSampRate); }
/* LoadFile: load whole file or segments and accumulate variance */ void LoadFile(char *fn) { ParmBuf pbuf; BufferInfo info; char labfn[80]; Transcription *trans; long segStIdx,segEnIdx; int i,s,j,ncas,nObs=0; LLink p; if (segId == NULL) { /* load whole parameter file */ if((pbuf=OpenBuffer(&iStack, fn, 0, dff, FALSE_dup, FALSE_dup))==NULL) HError(2550,"LoadFile: Config parameters invalid"); GetBufferInfo(pbuf,&info); CheckData(fn,info); nObs = ObsInBuffer(pbuf); for (i=0; i<nObs; i++) { for(s=1;s<=swidth[0];s++) obs.fv[s] = CreateVector(&dStack,swidth[s]); ReadAsTable(pbuf,i,&obs); for(s=1;s<=swidth[0];s++) StoreItem(dSeq[s],(Ptr)obs.fv[s]); } CloseBuffer(pbuf); } else { /* load segment of parameter file */ MakeFN(fn,labDir,labExt,labfn); trans = LOpen(&iStack,labfn,lff); ncas = NumCases(trans->head,segId); if ( ncas > 0) { if((pbuf=OpenBuffer(&iStack, fn, 0, dff, FALSE_dup, FALSE_dup))==NULL) HError(2550,"LoadFile: Config parameters invalid"); GetBufferInfo(pbuf,&info); CheckData(fn,info); for (i=1,nObs=0; i<=ncas; i++) { p = GetCase(trans->head,segId,i); segStIdx= (long) (p->start/info.tgtSampRate); segEnIdx = (long) (p->end/info.tgtSampRate); if (trace&T_SEGS) printf(" loading seg %s [%ld->%ld]\n", segId->name,segStIdx,segEnIdx); if (segEnIdx >= ObsInBuffer(pbuf)) segEnIdx = ObsInBuffer(pbuf)-1; if (segEnIdx >= segStIdx) { for (j=segStIdx;j<=segEnIdx;j++) { /* SJY: The HInit code I copied this from had no */ /* SJY: CreateVector call here -- a bug? */ for(s=1;s<=swidth[0];s++) obs.fv[s] = CreateVector(&dStack,swidth[s]); ReadAsTable(pbuf,j,&obs); for(s=1;s<=swidth[0];s++) StoreItem(dSeq[s],(Ptr)obs.fv[s]); ++nObs; } } } CloseBuffer(pbuf); } } ResetHeap(&iStack); if (trace&T_LOAD) { printf(" %5d obs loaded from %s, streams: ",nObs,fn); for(s=1;s<=swidth[0];s++) printf("[%d]" ,swidth[s]); printf("\n"); fflush(stdout); } }