示例#1
0
/* EXPORT->ResetLbel: reset module */
void ResetLabel(void)
{
   ResetHeap(&mlfHeap);
   ResetHeap(&namecellHeap);
   
   return;
}
示例#2
0
            HError(-1189,"HList: Warning ALIEN src file format set");

         break;

      case 'T':

         trace = GetChkedInt(0,077,s); break;

      default:

         HError(1119,"HList: Unknown switch %s",s);

      }

   }

   if (NumArgs() == 0 ) 

      ListSpeech(NULL);

   else

      while (NumArgs() > 0 ) {

         if (NextArg() != STRINGARG)

            HError(1119,"HList: List file name expected");

         ListSpeech(GetStrArg());

      }

   Exit(0);

   return (0);          /* never reached -- make compiler happy */

}



/* -------------------- Display Routines  ------------------- */



typedef struct{   /* gather together basic header info */

   char *name;

   Boolean isSource;

   Boolean isAudio;

   FileFormat fmt;
示例#3
0
void InitNodeHeap(NBNodeHeap *nodeheap)
{
   ResetHeap(&nodeheap->nehHeap);
   nodeheap->count=nodeheap->exps=nodeheap->length=0;
   nodeheap->head=NULL;
   nodeheap->id=1;
}
示例#4
0
/* LoadMgeTrnHmmFile: */
static void LoadMgeTrnHmmFile(int nIter)
{
   char hext[15], hmmFile[255];

   ResetHeap(&hmmStack);
   CreateHeap(&hmmStack, "Model Stack", MSTAK, 1, 1.0, 80000, 400000);

   sprintf(hext, "mmf%d", nIter);
   MakeFN(mmfFn, outDir, hext, hmmFile);

   CreateHMMSet(&hset, &hmmStack, TRUE);
   AddMMF(&hset, hmmFile);
   if (trace & T_TOP)
      printf("Loading MGE-trained HMM in iteration %d ... ... \n", nIter);
   if (MakeHMMSet(&hset, hmmListFn) < SUCCESS)
      HError(2321, "Initialise: MakeHMMSet failed");
   if (LoadHMMSet(&hset, hmmDir, hmmExt) < SUCCESS)
      HError(2321, "Initialise: LoadHMMSet failed");
   SetParmHMMSet(&hset);
   /* variance inversion, MGE training only support INVDIAGC case */
   ConvDiagC(&hset, TRUE);

   if (funcType == MGE_TRAIN)
      AttachAccToModel();
}
示例#5
0
/* Initialise: set up global data storage */
void Initialise(char *datafn)
{
   ParmBuf pbuf;
   int s;
   Boolean eSep;

   CreateHeap(&iStack,"inBuf",     MSTAK, 1, 0.5, 100000, LONG_MAX);
   CreateHeap(&dStack,"seqStack",  MSTAK, 1, 0.5, 100000, LONG_MAX);
   CreateHeap(&cStack,"clustStack",MSTAK, 1, 0.5, 100000, LONG_MAX);

   /* Peek at first data file to get observation format */
   if((pbuf = OpenBuffer(&iStack, datafn, 0, UNDEFF, FALSE_dup, FALSE_dup))==NULL)
      HError(2550,"Initialise: Config parameters invalid");
   GetBufferInfo(pbuf, &info);
   CloseBuffer(pbuf);
   ResetHeap(&iStack);

   /* set/validate stream widths */
   if(swidth[0] > 0)
      CheckStreamWidths(info);
   else
      ZeroStreamWidths(1,swidth);

   /* Create an observation to hold the input parameters */
   SetStreamWidths(info.tgtPK,info.tgtVecSize,swidth,&eSep);
   obs = MakeObservation(&gstack,swidth,info.tgtPK,FALSE,eSep);

   if (segLab != NULL)
      segId = GetLabId(segLab,TRUE);

   /* Create sequences to hold all data*/
   for (s=1;s<=swidth[0];s++)
      dSeq[s] = CreateSequence(&dStack,4096);
}
/* 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);
}
/* Accumulate stats from an utterance file */
SpkrAcc *AccGenUtt(char *SpkrPattern, char *UttFileName, SpkrAcc *sa)
{
   char SpkrName[MAXSTRLEN];
   ParmBuf pbuf;
   BufferInfo info;
   short swidth[SMAX];
   Boolean eSep;
   Vector tempV;
   int i;

   if (MaskMatch(SpkrPattern,SpkrName,UttFileName)==TRUE){
      /* open buffer and construct observation */
      pbuf = OpenBuffer(&iStack,UttFileName,0,dff,FALSE_dup,FALSE_dup);
      GetBufferInfo(pbuf,&info);
      if ((info.tgtPK & HASZEROM) && strchr(oflags,'m')) {
         HError(-2021,"HCompV: AccGenUtt: qualifier _Z not appropriate when calculating means!\n");
      }
      /* treat as single stream system though a bit weird */
      ZeroStreamWidths(1,swidth);
      SetStreamWidths(info.tgtPK,info.tgtVecSize,swidth,&eSep);
      obs = MakeObservation(&gstack,swidth,info.tgtPK,FALSE,eSep);
      if (info.tgtVecSize != vSize){
         vSize = info.tgtVecSize;
         /* if needed init a SpkrAcc */
         sa = InitSpkrAcc();
         fprintf(stdout,"Target observation vector size set to %d ......\n",info.tgtVecSize);
         fflush(stdout);
      }
      ParmKind2Str(info.tgtPK,TargetPKStr);
      /* accumulate stats for current utterance file */
      StartBuffer(pbuf);
      while (BufferStatus(pbuf) != PB_CLEARED) 
         {
            /* copy current observation and set vector ptr to first stream */
            ReadAsBuffer(pbuf,&obs);
            tempV = obs.fv[1];
            for (i=1;i<=vSize;i++){
               sa->meanSum[i] += tempV[i];
               sa->squareSum[i] += tempV[i]*tempV[i];
            }
            sa->NumFrame += 1;
         }
      CloseBuffer(pbuf);
      strcpy(sa->SpkrName,SpkrName);
      if (trace&T_CMV){
         fprintf(stdout,"Utterance %s accumulate generated for speaker %s\n",UttFileName,sa->SpkrName);
         fflush(stdout);
      }
      ResetHeap(&iStack);
      return sa;
   }
   else {
      HError(2039,"HCompV: AccGenUtt: speaker pattern matching failure on file: %s\n",UttFileName);
      return NULL;
   }
}
示例#8
0
文件: HLVRec-LM.c 项目: didw/HTS
static void ResetLMCache (LMCache *cache)
{
   int i;
   
   ResetHeap (&cache->nodeHeap);
   for (i = 0; i < cache->nNode; ++i)
      cache->node[i] = NULL;

   cache->transHit = cache->transMiss = 0;
   cache->laHit = cache->laMiss = 0;
}
示例#9
0
/* ResetHeaps: Reset all heaps used for dynamic memory allocation */
void ResetHeaps(void)
{
   ResetHeap(&hmmStack);
   ResetHeap(&aSetStack);
   ResetHeap(&sSetStack);
   ResetHeap(&wsStack);
   ResetHeap(&labIdStack);
   ResetHeap(&wtAccStack);
   ResetHeap(&gstack);
}
示例#10
0
/* DoGeneration: Generate parameter sequences from HMMs */
void DoGeneration(char *labfn)
{
   char labFn[MAXFNAMELEN], buf[MAXSTRLEN];
   int t;
   Boolean eSep;
   Transcription *tr;

   if (trace & T_TOP) {
      printf(" Generating Label %s\n", NameOf(labfn, buf));
      fflush(stdout);
   }

   /* load a given input label file */
   ResetHeap(&utt->transStack);
   MakeFN(labfn, labDir, labExt, labFn);
   tr = LOpen(&genStack, labFn, lff);

   /* compose a sentence HMM corresponding to the input label */
   InitialiseGenInfo(genInfo, tr, FALSE);

   /* set utterance informations for forward-backward algorithm */
   SetStreamWidths(hmset.pkind, hmset.vecSize, hmset.swidth, &eSep);
   utt->tr = tr;
   utt->Q = genInfo->labseqlen;
   utt->T = genInfo->tframe;
   utt->twoDataFiles = FALSE;
   utt->o = (Observation *) New(&gstack, utt->T * sizeof(Observation));
   utt->o--;
   for (t = 1; t <= utt->T; t++)
      utt->o[t] = MakeObservation(&gstack, hmset.swidth, hmset.pkind, FALSE, eSep);

   /* parameter generation */
   ParamGen(genInfo, utt, fbInfo, type);

   /* output state durations and generated parameter sequences */
   if (!stateAlign)
      WriteStateDurations(labfn, genInfo);
   WriteParms(labfn, genInfo);

   /* free memory */
   Dispose(&gstack, ++utt->o);
   ResetGenInfo(genInfo);

   /* increment total number of generated frames */
   totalT += utt->T;
   totalPr += utt->pr;

   return;
}
示例#11
0
/* EXPORT->DeleteHeap: delete given heap */
void DeleteHeap(MemHeap *x)
{
   if (x->type == CHEAP) 
      HError(5172,"DeleteHeap: cant delete C Heap %s",x->name);
   if (trace&T_TOP)
      printf("HMem: DeleteHeap %s\n",x->name);
   /* free all data blocks */
   ResetHeap(x);
   if (x->heap != NULL){
      free(x->heap->data);
      free(x->heap);
   }
   /* expunge all trace of it */
   UnRecordHeap(x);
   /* free name */
   free(x->name);
}
示例#12
0
   HTime period;

   int sampSize;

   int numComps;

   long nSamples;

}HeadInfo;



/* PrBar: print a horizantal bar of length n including title */

void PrBar(char *title)

{

   int i,len,n;

   

   if (rawOut) return;

   len = strlen(title);

   n = (barwidth - len)/2;

   for (i=1; i<n; i++) putchar(barc);

   printf(" %s ",title);

   n = barwidth - n - len;

   for (i=1; i<n; i++) putchar(barc);

   putchar('\n');

}

   

/* SetBarWidth: set bar width according to nItems and item type */

void SetBarWidth(int itemWidth)
示例#13
0
/* PutTargetFile: close and store waveform or parm file */
void PutTargetFile(char *s)
{
   if(tgtPK == WAVEFORM) {
      if(CloseWaveOutput(wv,tgtFF,s)<SUCCESS)
         HError(1014,"PutTargetFile: Could not save waveform file %s", s);
   }
   else {
      if(SaveBuffer(pb,s,tgtFF)<SUCCESS)
         HError(1014,"PutTargetFile: Could not save parm file %s", s );
      CloseBuffer(pb);
   }
   if (trace & T_TOP){
      AppendTrace("->"); AppendTrace(s);
      PrintTrace();     
      ResetHeap(&tStack);
      trList.str = NULL;
   }
   if(trans != NULL)
      SaveLabs(s,trans);
}
示例#14
0
void ArcFromLat(ArcInfo *aInfo, HMMSet *hset){
   Lattice *lat;
   int larcid,seg;
   int start_time;
   HArc *arc;
   int l;
   float framedur;

   if(!StackInitialised)
      CreateHeap(&tempArcStack,    "tempArcStore",       MSTAK, 1, 0.5, 1000,  10000);

   aInfo->start=aInfo->end=0;
   aInfo->nArcs=0;
   if(IsLMScale)
      aInfo->lmScale = LMSCALE;
   else /* If none is specified use the one from the lattice. */
      aInfo->lmScale = aInfo->lat[0]->lmscale;
  
   /* Lattices actually never specify frame duration.  Usual source is config, FRAMEDUR. */
   /* if(lat->framedur != 0) framedur = lat->framedur / 10000000;   */
   if (FRAMEDUR) framedur = FRAMEDUR; /* config. */
   else framedur = 0.01;
   aInfo->framedur = framedur;

   if(!IsWdPen)
      aInfo->insPen = aInfo->lat[0]->wdpenalty;
   else aInfo->insPen = WDPEN;

   /*  Add all the arcs in the lattice into the Arc structure. */
   for(l=0;l<aInfo->nLats;l++) /* this handles multiple lattices so e.g. the correct lattice can be added to the recognition lattice
                                  in case it happens to be absent. */
      {
         lat = aInfo->lat[l];
         ZeroHooks(lat);
         FixLatTimes(lat); /* this can be deleted at some point. */
         for(larcid=0;larcid<lat->na;larcid++){
            start_time = TimeToNFrames(lat->larcs[larcid].start->time, aInfo);
      
            for(seg=0;seg<lat->larcs[larcid].nAlign;seg++){
               arc = CreateArc(aInfo->mem, lat, lat->larcs+larcid, start_time, seg, ++aInfo->nArcs, (seg==0?NULL:aInfo->end), aInfo->insPen, aInfo->lmScale, hset, aInfo);
               /* this creates the phone arc and also the transitions between them. (confusingly, phone 
                  arcs are actually nodes in the datastructure used here, and transitions are arcs)  */
	
               /*Insert into the linked list of arcs:*/
               if(!aInfo->start)  aInfo->start=arc;
               arc->prec = aInfo->end;
               arc->foll = NULL;
               if(aInfo->end) aInfo->end->foll = arc;
               aInfo->end = arc;
               start_time = aInfo->end->t_end;
            }
         }
      }
  

   SortArcs(aInfo);  /* Sort the arcs in order of start & end time
                        [ & in such a way that ones with identical HMMs are adjacent.] */

   if(BackTransitions(aInfo)){ /* A check-- should never be true if properly sorted */
      HError(1, "Error: file %s: back transitions exist.\n", (aInfo->lat[0]->utterance?aInfo->lat[0]->utterance:"[unknown]"));
   }


   /* Pool sets of identical models with identical start & end times. */
   for(arc=aInfo->start; arc; arc=arc->foll){
      HArc *arc2;
      if((arc2=arc->prec) != NULL && arc2->t_end==arc->t_end && arc2->t_start==arc->t_start && arc2->hmm==arc->hmm){
         if(arc2->calcArc == NULL) arc->calcArc = arc2;
         else arc->calcArc = arc2->calcArc;
      }
   }


   {  /*  Set up the structures which relate to the computation of model likelihoods. */
      int q=0,Q; MLink macroName;
      int T=0,t;
      for(arc=aInfo->start;arc;arc=arc->foll){
         if(arc->calcArc) arc->id = GHOST_ARC;
         else{ arc->id = ++q; }
         T=MAX(T,arc->t_end);
      }
      aInfo->Q = Q = q; /* num unique arcs. */
      aInfo->T = T; 
      aInfo->ac = (Acoustic*)New(aInfo->mem, sizeof(Acoustic) * (q+1)); 
      q=0;
      for(arc=aInfo->start;arc;arc=arc->foll){
         if(!arc->calcArc){  /* if this is one of the 'calculated' arcs */
            Acoustic *ac = arc->ac = aInfo->ac + ++q;

            ac->myArc=arc;
            ac->t_start=arc->t_start; ac->t_end=arc->t_end;
	
            if((macroName=FindMacroName(hset,'l',arc->phone))==NULL)
               HError(2321,"CreateArc: Unknown align label %s",arc->phone->name); 
            ac->hmm = (HLink)macroName->structure;  

            ac->Nq = ac->hmm->numStates; /* could be either HMM, same structure. */
            if(ac->t_start == ac->t_end+1){ 
               ac->SP=TRUE; 
               ac->alphat=ac->alphat1=NULL;ac->betaPlus=NULL;ac->otprob=NULL;
            } else {
               int j,s,SS,S = hset->swidth[0]; /* probably just 1. */
	       StreamElem *ste;

	       SS=(S==1)?1:S+1;
               ac->SP=FALSE;
               ac->alphat = CreateDVector(aInfo->mem, ac->Nq);
               ac->alphat1 = CreateDVector(aInfo->mem, ac->Nq);
               ac->betaPlus = ((DVector*)New(aInfo->mem, sizeof(DVector)*(ac->t_end-ac->t_start+1)))-ac->t_start;
               ac->otprob = ((float****)New(aInfo->mem, sizeof(float***)*(ac->t_end-ac->t_start+1)))-ac->t_start;
               for(t=ac->t_start;t<=ac->t_end;t++){
                  ac->betaPlus[t] = CreateDVector(aInfo->mem,ac->Nq);
		  ac->otprob[t] = ((float***)New(aInfo->mem,(ac->Nq-2)*sizeof(float **)))-2;
		  for(j=2;j<ac->Nq;j++){
                     ac->otprob[t][j] = (float**)New(aInfo->mem,SS*sizeof(float*)); /*2..Nq-1*/
		     ste = ac->hmm->svec[j].info->pdf+1;
		     if (S==1) {
		        ac->otprob[t][j][0] = NULL;
		     } else {
		        ac->otprob[t][j][0] = (float*)New(aInfo->mem,sizeof(float));
			ac->otprob[t][j][0][0] = LZERO;
			for (s=1;s<=S;s++,ste++)
			  ac->otprob[t][j][s] = NULL;
		     }
                  }
               }	
            }
         }
      }
      for(arc=aInfo->start;arc;arc=arc->foll)  if(arc->calcArc) arc->ac = arc->calcArc->ac;


      /* Set up arrays qLo[t] and qHi[t] which are used to speed up iterations over q. */
    
      aInfo->qLo = (int*)New(aInfo->mem, sizeof(int)*(aInfo->T+1));  /* For efficiency later, work out min & max q active at each time t. */
      aInfo->qHi = (int*)New(aInfo->mem, sizeof(int)*(aInfo->T+1));
      for(t=1;t<=T;t++){  aInfo->qLo[t] = T+1; aInfo->qHi[t] = -1;  }
      for(q=1;q<=Q;q++){
         for(t=aInfo->ac[q].t_start;t<=MAX(aInfo->ac[q].t_end,aInfo->ac[q].t_start);t++){ 
            /* the MAX above is to handle tee models, so they will be in beam at t==t_start. */
            aInfo->qLo[t] = MIN(aInfo->qLo[t], q);
            aInfo->qHi[t] = MAX(aInfo->qHi[t], q);
         }
      } 
   }

   if(trace&T_ARC && debug++ < 100){
      printf("[HArc:] %d arcs, depth %f, depth[reduced] %f\n", aInfo->nArcs, Depth(aInfo,TRUE), Depth(aInfo,FALSE));
      if(trace&T_ARC2)
         PrintArcs(stdout, aInfo->start);
   }
  
   ResetHeap(&tempArcStack);
}
示例#15
0
/* 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);
   }        
}
示例#16
0
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 mainHInit(int argc, char *argv[])
{
   static int ft=1;
   char *datafn, *s;
   int nSeg;
   zwangModify();
   if(InitShell(argc,argv,hinit_version,hinit_vc_id)<SUCCESS)
      HError(2100,"HInit: InitShell failed");
   if(ft)
   {
	   if(isMemInit==0)
	   {
		   InitMem();  
		   isMemInit=1;
	   }
	   InitLabel();
	   InitMath();  InitSigP();
	   InitWave();  InitAudio();
	   InitVQ();    InitModel();
	   if(InitParm()<SUCCESS)  
		  HError(2100,"HInit: InitParm failed");
	   InitTrain(); InitUtil();
	   ft=0;
	     /* Stacks for global structures requiring memory allocation */
	   CreateHeap(&segmentStack,"SegStore", MSTAK, 1, 0.0, 100000, LONG_MAX);
	   CreateHeap(&sequenceStack,"SeqStore", MSTAK, 1, 0.0, 1000, 1000);
	   CreateHeap(&clustSetStack,"ClustSetStore", MSTAK, 1, 0.0, 1000, 1000);
	   CreateHeap(&transStack,"TransStore", MSTAK, 1, 0.0, 1000, 1000);
	   CreateHeap(&traceBackStack,"TraceBackStore", MSTAK, 1, 0.0, 1000, 1000);
	   CreateHeap(&bufferStack,"BufferStore", MSTAK, 1, 0.0, 1000, 1000);

   }

    zwangHMemGetConf();
	zwangHWaveGetConf();
	zwangHLabelGetConf();
	zwangHMathGetConf();
	zwangHSigPGetConf();
	zwangHAudioGetConf();
	zwangHVQGetConf();
	zwangHModelGetConf();
	zwangHParmGetConf();
	zwangHTrainGetConf();
	zwangHUtilGetConf();

   SetConfParms();

	CreateHMMSet(&hset,&gstack,FALSE);
	
   while (NextArg() == SWITCHARG) {
      s = GetSwtArg();
      if (strlen(s)!=1) 
         HError(2119,"HInit: Bad switch %s; must be single letter",s);
      switch(s[0]){
      case 'e':
         epsilon = GetChkedFlt(0.0,1.0,s); break;
      case 'i':
         maxIter = GetChkedInt(0,100,s); break;
      case 'l':
         if (NextArg() != STRINGARG)
            HError(2119,"HInit: Segment label expected");
         segLab = GetStrArg();
         break;
      case 'm':
         minSeg = GetChkedInt(1,1000,s); break;
      case 'n':
         newModel = FALSE; break;
      case 'o':
         outfn = GetStrArg();
         break;
      case 'u':
         SetuFlags(); break;
      case 'v':
         minVar = GetChkedFlt(0.0,10.0,s); break;
      case 'w':
         mixWeightFloor = MINMIX * GetChkedFlt(0.0,10000.0,s); 
         break;
      case 'B':
         saveBinary = TRUE;
         break;
      case 'F':
         if (NextArg() != STRINGARG)
            HError(2119,"HInit: Data File format expected");
         if((dff = Str2Format(GetStrArg())) == ALIEN)
            HError(-2189,"HInit: Warning ALIEN Data file format set");
         break;
      case 'G':
         if (NextArg() != STRINGARG)
            HError(2119,"HInit: Label File format expected");
         if((lff = Str2Format(GetStrArg())) == ALIEN)
            HError(-2189,"HInit: Warning ALIEN Label file format set");
         break;
      case 'H':
         if (NextArg() != STRINGARG)
            HError(2119,"HInit: HMM macro file name expected");
         AddMMF(&hset,GetStrArg());
         break;
      case 'I':
         if (NextArg() != STRINGARG)
            HError(2119,"HInit: MLF file name expected");
         LoadMasterFile(GetStrArg());
         break;
      case 'L':
         if (NextArg()!=STRINGARG)
            HError(2119,"HInit: Label file directory expected");
         labDir = GetStrArg(); break;
      case 'M':
         if (NextArg()!=STRINGARG)
            HError(2119,"HInit: Output macro file directory expected");
         outDir = GetStrArg();
         break;
      case 'T':
         if (NextArg() != INTARG)
            HError(2119,"HInit: Trace value expected");
         trace = GetChkedInt(0,01777,s);
         break;
      case 'X':
         if (NextArg()!=STRINGARG)
            HError(2119,"HInit: Label file extension expected");
         labExt = GetStrArg(); break;
      default:
         HError(2119,"HInit: Unknown switch %s",s);
      }
   }
   if (NextArg()!=STRINGARG)
      HError(2119,"HInit: source HMM file name expected");
   hmmfn = GetStrArg();
   Initialise();
   do {
      if (NextArg()!=STRINGARG)
         HError(2119,"HInit: training data file name expected");
      datafn = GetStrArg();
      LoadFile(datafn);
   } while (NumArgs()>0);
   nSeg = NumSegs(segStore);
   if (nSeg < minSeg)
      HError(2121,"HInit: Too Few Observation Sequences [%d]",nSeg);
   EstimateModel();
   SaveModel(outfn);

   Dispose(hset.hmem,hset.mtab);
   ResetHeap(&gstack);
   ResetHeap(&segmentStack);
   ResetHeap(&sequenceStack);
   ResetHeap(&clustSetStack);
   ResetHeap(&transStack);
   ResetHeap(&traceBackStack);
   ResetHeap(&bufferStack);

   zwangInitParmClear();
   zwangInitShellClear();
   return (0);          /* never reached -- make compiler happy */
}
示例#18
0
int main(int argc, char *argv[])
{
   char *s;
   char *labfn;
   int numUtt;

   void Initialise(void);
   void DoGeneration(char *labfn);

   if (InitShell(argc, argv, hmgens_version, hmgens_vc_id) < SUCCESS)
      HError(2300, "HMGenS: InitShell failed");
   InitMem();
   InitMath();
   InitSigP();
   InitWave();
   InitLabel();
   InitModel();
   if (InitParm() < SUCCESS)
      HError(2300, "HMGenS: InitParm failed");
   InitUtil();
   InitFB();
   InitAdapt(&xfInfo_hmm, &xfInfo_dur);
   InitMap();
   InitGen();

   if (NumArgs() == 0)
      ReportUsage();

   CreateHeap(&genStack, "genStore", MSTAK, 1, 1.0, 80000, 400000);
   CreateHeap(&uttStack, "uttStore", MSTAK, 1, 0.5, 100, 1000);
   CreateHeap(&fbInfoStack, "FBInfoStore", MSTAK, 1, 0.5, 100, 1000);
   CreateHeap(&hmmStack, "HmmStore", MSTAK, 1, 1.0, 50000, 500000);
   CreateHeap(&dmStack, "dmStore", MSTAK, 1, 1.0, 50000, 500000);
   SetConfParms();
   CreateHMMSet(&hmset, &hmmStack, TRUE);
   CreateHMMSet(&dmset, &dmStack, TRUE);

   utt = (UttInfo *) New(&uttStack, sizeof(UttInfo));
   genInfo = (GenInfo *) New(&genStack, sizeof(GenInfo));
   fbInfo = (FBInfo *) New(&fbInfoStack, sizeof(FBInfo));

   while (NextArg() == SWITCHARG) {
      s = GetSwtArg();
      if (strlen(s) != 1)
         HError(9919, "HMGenS: Bad switch %s; must be single letter", s);
      switch (s[0]) {
      case 'a':
         xfInfo_hmm.useInXForm = TRUE;
         break;
      case 'b':
         xfInfo_dur.useInXForm = TRUE;
         break;
      case 'c':
         if (NextArg() != INTARG)
            HError(2119, "HMGenS: Parameter generation algorithm type value expected");
         type = (ParmGenType) GetChkedInt(CHOLESKY, FB, s);
         break;
      case 'd':
         if (NextArg() != STRINGARG)
            HError(2319, "HMGenS: HMM definition directory expected");
         hmmDir = GetStrArg();
         break;
      case 'e':
         useAlign = TRUE;
         break;
      case 'f':
         frameRate = (HTime) GetChkedFlt(0.0, 10000000.0, s);
         break;
      case 'g':
         minFrwdP = GetChkedFlt(0.0, 1000.0, s);
         break;
      case 'h':
         if (NextArg() != STRINGARG)
            HError(1, "Speaker name pattern expected");
         xfInfo_hmm.inSpkrPat = xfInfo_dur.inSpkrPat = GetStrArg();
         if (NextArg() == STRINGARG)
            xfInfo_hmm.paSpkrPat = xfInfo_dur.paSpkrPat = GetStrArg();
         if (NextArg() != SWITCHARG)
            HError(2319, "HMGenS: cannot have -h as the last option");
         break;
      case 'm':
         modelAlign = TRUE;
         break;
      case 'n':
         if (NextArg() != STRINGARG)
            HError(2319, "HMGenS: duration model definition directory expected");
         dmDir = GetStrArg();
         break;
      case 'p':
         outPdf = TRUE;
         break;
      case 'r':
         if (NextArg() != FLOATARG)
            HError(2119, "HMGenS: Speaking rate value (float) expected");
         speakRate = GetChkedFlt(0.0, 3.0, s);
         break;
      case 's':
         stateAlign = TRUE;
         break;
      case 't':
         pruneInit = GetChkedFlt(0.0, 1.0E20, s);
         if (NextArg() == FLOATARG || NextArg() == INTARG) {
            pruneInc = GetChkedFlt(0.0, 1.0E20, s);
            pruneLim = GetChkedFlt(0.0, 1.0E20, s);
         } else {
            pruneInc = 0.0;
            pruneLim = pruneInit;
         }
         break;
      case 'v':
         MSDthresh = GetChkedFlt(0.0, 1.0, s);
         break;
      case 'x':
         if (NextArg() != STRINGARG)
            HError(2319, "HMGenS: HMM file extension expected");
         hmmExt = GetStrArg();
         break;
      case 'y':
         if (NextArg() != STRINGARG)
            HError(2319, "HMGenS: duration model file extension expected");
         dmExt = GetStrArg();
         break;
      case 'B':
         inBinary = TRUE;
         break;
      case 'E':
         if (NextArg() != STRINGARG)
            HError(2319, "HMGenS: parent transform directory expected");
         xfInfo_hmm.usePaXForm = TRUE;
         xfInfo_hmm.paXFormDir = GetStrArg();
         if (NextArg() == STRINGARG)
            xfInfo_hmm.paXFormExt = GetStrArg();
         if (NextArg() != SWITCHARG)
            HError(2319, "HMGenS: cannot have -E as the last option");
         break;
      case 'G':
         if (NextArg() != STRINGARG)
            HError(2119, "HMGenS: Label File format expected");
         if ((lff = Str2Format(GetStrArg())) == ALIEN)
            HError(-2189, "HMGenS: Warning ALIEN Label file format set");
         break;
      case 'H':
         if (NextArg() != STRINGARG)
            HError(3219, "HMGenS: HMM MMF File name expected");
         AddMMF(&hmset, GetStrArg());
         break;
      case 'I':
         if (NextArg() != STRINGARG)
            HError(2319, "HMGenS: MLF file name expected");
         LoadMasterFile(GetStrArg());
         break;
      case 'J':
         if (NextArg() != STRINGARG)
            HError(2319, "HMGenS: input transform directory expected");
         AddInXFormDir(&hmset, GetStrArg());
         if (NextArg() == STRINGARG)
            xfInfo_hmm.inXFormExt = GetStrArg();
         if (NextArg() != SWITCHARG)
            HError(2319, "HMGenS: cannot have -J as the last option");
         break;
      case 'L':
         if (NextArg() != STRINGARG)
            HError(2319, "HMGenS: Label file directory expected");
         labDir = GetStrArg();
         break;
      case 'M':
         if (NextArg() != STRINGARG)
            HError(2319, "HMGenS: Output macro file directory expected");
         genDir = GetStrArg();
         break;
      case 'N':
         if (NextArg() != STRINGARG)
            HError(3219, "HMGenS: Duration MMF File name expected");
         AddMMF(&dmset, GetStrArg());
         break;
      case 'T':
         if (NextArg() != INTARG)
            HError(2119, "HMGenS: Trace value expected");
         trace = GetChkedInt(0, 0002, s);
         break;
      case 'W':
         if (NextArg() != STRINGARG)
            HError(2319, "HMGenS: parent duration transform directory expected");
         xfInfo_dur.usePaXForm = TRUE;
         xfInfo_dur.paXFormDir = GetStrArg();
         if (NextArg() == STRINGARG)
            xfInfo_dur.paXFormExt = GetStrArg();
         if (NextArg() != SWITCHARG)
            HError(2319, "HMGenS: cannot have -W as the last option");
         break;
      case 'X':
         if (NextArg() != STRINGARG)
            HError(2319, "HMGenS: Label file extension expected");
         labExt = GetStrArg();
         break;
      case 'Y':
         if (NextArg() != STRINGARG)
            HError(2319, "HMGenS: input duration transform directory expected");
         AddInXFormDir(&dmset, GetStrArg());
         if (NextArg() == STRINGARG) {
            if (xfInfo_dur.inXFormExt == NULL)
               xfInfo_dur.inXFormExt = GetStrArg();
            else
               HError(2319, "MGenS: only one input duration transform extension may be specified");
         }
         if (NextArg() != SWITCHARG)
            HError(2319, "HMGenS: cannot have -Y as the last option");
         break;
      default:
         HError(9919, "HMGenS: Unknown switch %s", s);
      }
   }
   if (NextArg() != STRINGARG)
      HError(2319, "HMGenS: file name of vocabulary list expected");

   Initialise();
   InitUttInfo(utt, FALSE);
   numUtt = 1;

   if (trace & T_TOP)
      SetTraceGen();

   /* generate parameter sequences */
   do {
      if (NextArg() != STRINGARG)
         HError(2319, "HMGenS: data file name expected");
      labfn = GetStrArg();

      /* track speakers */
      if (UpdateSpkrStats(&hmset, &xfInfo_hmm, labfn)) {
         if (!xfInfo_hmm.useInXForm)
            xfInfo_hmm.inXForm = NULL;
      }
      if (UpdateSpkrStats(&dmset, &xfInfo_dur, labfn)) {
         if (!xfInfo_dur.useInXForm)
            xfInfo_dur.inXForm = NULL;
         else
            ResetDMMPreComps(&dmset);
      }

      fbInfo->xfinfo_hmm = &xfInfo_hmm;
      fbInfo->xfinfo_dur = &xfInfo_dur;
      fbInfo->inXForm_hmm = xfInfo_hmm.inXForm;
      fbInfo->inXForm_dur = xfInfo_dur.inXForm;
      fbInfo->al_inXForm_hmm = xfInfo_hmm.al_inXForm;
      fbInfo->al_inXForm_dur = xfInfo_dur.al_inXForm;
      fbInfo->paXForm_hmm = xfInfo_hmm.paXForm;
      fbInfo->paXForm_dur = xfInfo_dur.paXForm;

      /* generate parameters */
      DoGeneration(labfn);
      numUtt++;
   } while (NumArgs() > 0);

   if (trace & T_TOP) {
      printf("Generation complete - average log prob per frame = %e (%d frames)\n", totalPr / totalT, totalT);
   }

   /* Reset stacks */
   Dispose(&fbInfoStack, fbInfo);
   Dispose(&genStack, genInfo);
   Dispose(&uttStack, utt);
   ResetHeap(&fbInfoStack);
   ResetHeap(&uttStack);
   ResetHeap(&genStack);
   ResetHeap(&dmStack);
   ResetHeap(&hmmStack);

   /* Reset modules */
   ResetGen();
   ResetAdapt(&xfInfo_hmm, &xfInfo_dur);
   ResetFB();
   ResetUtil();
   ResetParm();
   ResetModel();
   ResetLabel();
   ResetWave();
   ResetSigP();
   ResetMath();
   ResetMem();
   ResetShell();

   Exit(0);
   return (0);                  /* never reached -- make compiler happy */
}
/* main func */
int mainHCompV(int argc, char *argv[])
{
   static int ft=1;
   char *datafn, *s;
   void SetCovs(void);
   void PutVFloor(void);
   SpkrAcc *sa = NULL;
	zwangModify();
   if(InitShell(argc,argv,hcompv_version,hcompv_vc_id)<SUCCESS)
      HError(2000,"HCompV: InitShell failed");
   if(ft)
   {
	   if(isMemInit==0)
	   {
		   InitMem();  
		   isMemInit=1;
	   }
	   InitLabel();
	   InitMath();  InitSigP();
	   InitWave();  InitAudio();
	   InitVQ();    InitModel();
	   if(InitParm()<SUCCESS)  
		  HError(2000,"HCompV: InitParm failed");   
	   ft=0;
	   CreateHeap(&iStack,"InBuf", MSTAK, 1, 0.5, 100000, LONG_MAX);
   }
   zwangHMemGetConf();
	zwangHWaveGetConf();
	zwangHLabelGetConf();
	zwangHMathGetConf();
	zwangHSigPGetConf();
	zwangHAudioGetConf();
	zwangHVQGetConf();
	zwangHModelGetConf();
	zwangHParmGetConf();

   SetConfParms();
CreateHMMSet(&hset,&gstack,FALSE);
   pathPattern[0]='\0';
   while (NextArg() == SWITCHARG) {
      s = GetSwtArg();
      if (strlen(s)!=1) 
         HError(2019,"HCompV: Bad switch %s; must be single letter",s);
      switch(s[0]){
      case 'f':
         if (NextArg() != FLOATARG)
            HError(2019,"HCompV: Variance floor scale expected");
         vFloorScale = GetChkedFlt(0.0,100.0,s);
         break;
      case 'l':
         if (NextArg() != STRINGARG)
            HError(2019,"HCompV: Segment label expected");
         segLab = GetStrArg();
         break;
      case 'm':
         meanUpdate = TRUE;
         break;
      case 'o':
         outfn = GetStrArg();
         break;     
      case 'v':
         if (NextArg() != FLOATARG)
            HError(2019,"HCompV: Minimum variance level expected");
         minVar = GetChkedFlt(0.0,100.0,s);
         break;
      case 'k':
         if (NextArg() != STRINGARG)
            HError(2019,"HCompV: speaker pattern expected");
         strcpy(spPattern,GetStrArg());
         if (strchr(spPattern,'%')==NULL)
            HError(2019,"HCompV: Speaker mask invalid");
         break;
      case 'c':
         if (NextArg() != STRINGARG)
            HError(2019,"HCompV: CMV output dir expected");
         strcpy(cmDir,GetStrArg());
         DoCMV = TRUE;
         break;
      case 'p':
         if (NextArg() != STRINGARG)
            HError(2019,"HCompV: path pattern expected");
         strcpy(pathPattern,GetStrArg());
         if (strchr(pathPattern,'%')==NULL)
            HError(2019,"HCompV: Path mask invalid");
         break;
      case 'q':
         if (NextArg() != STRINGARG)
            HError(2019,"HCompV: output flags (nmv)");
         strcpy(oflags,GetStrArg());
         break;
      case 'B':
         saveBinary = TRUE;
         break;
      case 'F':
         if (NextArg() != STRINGARG)
            HError(2019,"HCompV: Data File format expected");
         if((dff = Str2Format(GetStrArg())) == ALIEN)
            HError(-2089,"HCompV: Warning ALIEN Data file format set");
         break;
      case 'G':
         if (NextArg() != STRINGARG)
            HError(2019,"HCompV: Label File format expected");
         if((lff = Str2Format(GetStrArg())) == ALIEN)
            HError(-2089,"HCompV: Warning ALIEN Label file format set");
         break;
      case 'H':
         if (NextArg() != STRINGARG)
            HError(2019,"HCompV: HMM macro file name expected");
         AddMMF(&hset,GetStrArg());
         break;
      case 'I':
         if (NextArg() != STRINGARG)
            HError(2019,"HCompV: MLF file name expected");
         LoadMasterFile(GetStrArg());
         break;
      case 'L':
         if (NextArg()!=STRINGARG)
            HError(2019,"HCompV: Label file directory expected");
         labDir = GetStrArg();
         break;
      case 'M':
         if (NextArg()!=STRINGARG)
            HError(2019,"HCompV: Output macro file directory expected");
         outDir = GetStrArg();
         break;
      case 'T':
         if (NextArg() != INTARG)
            HError(2019,"HCompV: Trace value expected");
         trace = GetChkedInt(0,077,s); 
         break;
      case 'X':
         if (NextArg()!=STRINGARG)
            HError(2019,"HCompV: Label file extension expected");
         labExt = GetStrArg();
         break;
      default:
         HError(2019,"HCompV: Unknown switch %s",s);
      }
   }

   /* if not doing CMV, do standard HCompV */
   if (DoCMV == FALSE){
      if (NextArg()!=STRINGARG)
         HError(2019,"HCompV: Source HMM file name expected");
      hmmfn = GetStrArg();
      Initialise();
      do {
         if (NextArg()!=STRINGARG)
            HError(2019,"HCompV: Training data file name expected");
         datafn = GetStrArg();
         LoadFile(datafn);
      } while (NumArgs()>0);
      SetCovs();
      FixGConsts(hmmLink);
      SaveModel(outfn);   
      if (trace&T_TOP)
         printf("Output written to directory %s\n",(outDir==NULL)?"./":outDir);
      if (vFloorScale>0.0)
         PutVFloor();
   }
   else {
      /* report export data type */
      ReportOutput();
      /* init input buffer mem heap */
      CreateHeap(&iStack,"BufferIn",MSTAK,1,0.5,100000,5000000);
      do {
         if (NextArg()!=STRINGARG){
            HError(2019,"HCompV: Training data file name expected");
         }
         datafn = GetStrArg();       
         /* accumulate stats for current utterance file and update speaker list */
         sa = AccGenUtt(spPattern,datafn,sa);
         salist = UpdateSpkrAccList(salist,sa);
         /* reset for next utterance */
         ClrSpkrAcc(sa);
      } while (NumArgs()>0);
      /* compute the means and variances for each speaker */
      UpdateMeanVar(salist);
      /* export NMV for each speaker */
      ExportNMV(salist,cmDir,TargetPKStr);
   }
   Dispose(hset.hmem,hset.mtab);
   ResetHeap(&gstack);
   ResetHeap(&iStack);
   zwangInitParmClear();
zwangInitShellClear();
   //Exit(0);
   return (0);          /* never reached -- make compiler happy */
}
示例#20
0
int main(int argc, char *argv[])
{
   int i;
   char *c,*s,*fn;
   char sBuf[256],fmt[256];

   void       Initialise(void);
   void       ProcessText(char *fn,bool lastFile);
   bool    Exists(char *fn);
   BackOffLM *CombineModels(MemHeap *heap,LMInfo *lmi,int nLModel,int nSize,WordMap *wl) ;

   InitShell(argc,argv,ladapt_version,ladapt_vc_id);
   InitMem();
   InitMath();
   InitWave();
   InitLabel();
   InitLUtil();
   InitWMap();
   InitGBase();
   InitLModel();
   InitPCalc();
   InitPMerge();

   SetConfParms();

   if (!InfoPrinted() && NumArgs() == 0)
      ReportUsage();
   if (NumArgs() == 0) Exit(EXIT_SUCCESS);

   InitBuildInfo(&binfo); 
   binfo.dctype = DC_ABSOLUTE;
   nLModel = 1;
   while (NextArg() == SWITCHARG) {
      s = GetSwtArg();
      if (strlen(s)!=1) 
         HError(16419,"Bad switch %s; must be single letter",s);
      switch(s[0]){
         case 'a':
            newWords = GetChkedInt(10,10000000,s); break;
         case 'b':
            ngbSize = GetChkedInt(10,10000000,s); break;
         case 'c':
            i = GetChkedInt(2,LM_NSIZE,s); 
	    binfo.cutOff[i] = GetChkedInt(0,1000,s);
	    break;
         case 'd':
            if (NextArg()!=STRINGARG)
               HError(16419,"Gram base root file name expected");
            rootFN = GetStrArg(); 
	    break;
         case 'f':
	    strcpy(fmt, GetStrArg());
	    for (c=fmt; *c; *c=toupper(*c), c++); /* To uppercase */
	    if (strcmp(fmt, LM_TXT_TEXT)==0)
	      binfo.saveFmt = LMF_TEXT;
	    else if (strcmp(fmt, LM_TXT_BINARY)==0)
	       binfo.saveFmt = LMF_BINARY;
	    else if (strcmp(fmt, LM_TXT_ULTRA)==0)
	       binfo.saveFmt = LMF_ULTRA;
	    else
	       HError(16419,"Unrecognised LM format, should be one of [%s, %s, %s]",
		      LM_TXT_TEXT, LM_TXT_BINARY, LM_TXT_ULTRA);
	    break;
         case 'g':
            processText = FALSE; break;
	 case 'i':
            if (NextArg()!=FLOATARG)
	       HError(16419,"Interpolation weight expected");
	    lmInfo[nLModel].weight = GetChkedFlt(0.0,1.0,s);
            if (NextArg()!=STRINGARG)
	       HError(16419,"Interpolation LM filename expected");
	    lmInfo[nLModel].fn = GetStrArg();
	    nLModel++;
	    break;
         case 'j':
            i = GetChkedInt(2,LM_NSIZE,s); 
	    binfo.wdThresh[i] = GetChkedFlt(0.0,1E10,s);
	    break;
         case 'n':
            nSize = GetChkedInt(1, MAXNG, s); break;
#ifdef HTK_TRANSCRIBER
         case 's':
            if (NextArg()!=STRINGARG)
               HError(16419,"Gram file text source descriptor expected");
            txtSrc = GetStrArg(); break;
         case 't':
	    binfo.dctype = DC_KATZ; break;
#endif
         case 'w':
            if (NextArg()!=STRINGARG)
               HError(16419,"Word list file name expected");
            wlistFN = GetStrArg(); break;
#ifndef HTK_TRANSCRIBER
         case 'x':
            binfo.ptype = LMP_COUNT; break;
#endif
         case 'T':
            trace = GetChkedInt(0,077,s); break;
         default:
            HError(16419,"LAdapt: Unknown switch %s",s);
      }
   }
#ifdef HTK_TRANSCRIBER
   if (nLModel==1) {  /* must interpolate with at least one model */
      HError(16419,"LAdapt: at least one model must be specified with -i option");
   }
   if (binfo.saveFmt==LMF_TEXT) { /* save fomat cannot be TEXT */ 
      binfo.saveFmt=LMF_BINARY;
   }
#endif
   if (NextArg() != STRINGARG)
      HError(16419,"LAdapt: language model file name expected");
   outFN = CopyString(&gstack,GetStrArg());

   Initialise();
   if (processText) {
      if (NextArg() != STRINGARG)
	 ProcessText(NULL,TRUE);       /* input from stdin */
      else
	 while (NextArg() == STRINGARG) {
	    /* !! copy string argument since it gets overwritten 
	       by NextArg() when reading from script file */
	    fn = CopyString(&gstack,GetStrArg());
	    ProcessText(fn,NextArg() != STRINGARG);
	 }
      if (NumArgs() != 0)
	 HError(-16419,"LAdapt: unused args left on cmd line");
      for (i=0; i<stdBuf.ngb->fndx; i++) {
	 sprintf(sBuf,"%s.%d",stdBuf.ngb->fn,i);  
	 AddInputGFile(&inSet,sBuf,1.0);
      }
      ResetHeap(&langHeap);
   } else {
      for (i=0; i<MAX_NGRAM_FILES; i++) {
	 sprintf(sBuf,"%s.%d",rootFN,i);
	 if (!Exists(sBuf))
	    break;
	 AddInputGFile(&inSet,sBuf,1.0);
      }
      if (i==MAX_NGRAM_FILES)
      {
	HError(-16419, "LAdapt: Only %d n-gram files read (recompile with different setting\nof MAX_NGRAM_FILES");
      }
   }
   if (nLModel==1) {
      adpLM = GenerateModel(&langHeap,&binfo);
   } else {
      if (binfo.ptype==LMP_COUNT) 
	 binfo.ptype = LMP_FLOAT;
      newLM = GenerateModel(&langHeap,&binfo);
      lmInfo[0].lm = newLM;
      lmInfo[0].fn = "unknown";
      /* combine all models into one */
      adpLM = CombineModels(&langHeap,lmInfo,nLModel,nSize,tgtVoc);
   }
#ifdef HTK_TRANSCRIBER
#ifdef HTK_CRYPT
   adpLM->encrypt = TRUE;     /* force to write encrypted model */
#endif
#endif
   SaveLangModel(outFN,adpLM);

   Exit(EXIT_SUCCESS);
   return EXIT_SUCCESS; /* never reached -- make compiler happy */
}
示例#21
0
/* EXPORT->ResetVQ: reset a heap created in InitVQ */
void ResetVQ (void)
{
   ResetHeap(&vqHeap);
   
   return;
}
示例#22
0
/* LoadFile: load whole file or segments into segStore */
void LoadFile(char *fn)
{
   BufferInfo info;
   char labfn[80];
   Transcription *trans;
   long segStIdx,segEnIdx;
   static int segIdx=1;  /* Between call handle on latest seg in segStore */  
   static int prevSegIdx=1;
   HTime tStart, tEnd;
   int i,k,s,ncas,nObs=0,segLen;
   LLink p;
   Observation obs;

   if((pbuf=OpenBuffer(&bufferStack, fn, 10, dff, FALSE_dup, FALSE_dup))==NULL)
      HError(2150,"LoadFile: Config parameters invalid");
   GetBufferInfo(pbuf,&info);
   CheckData(fn,info);
   if (firstTime) InitSegStore(&info);

   if (segId == NULL)  {   /* load whole parameter file */
      nObs = ObsInBuffer(pbuf);
      tStart = 0.0;
      tEnd = (info.tgtSampRate * nObs);
      LoadSegment(segStore, tStart, tEnd, pbuf);
      segIdx++;
   }
   else {                  /* load segment of parameter file */
      MakeFN(fn,labDir,labExt,labfn);
      trans = LOpen(&transStack,labfn,lff);
      ncas = NumCases(trans->head,segId);
      if ( ncas > 0) {
         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 (segEnIdx >= ObsInBuffer(pbuf))
               segEnIdx = ObsInBuffer(pbuf)-1;
            if (segEnIdx - segStIdx + 1 >= nStates-2) {
               LoadSegment(segStore, p->start, p->end, pbuf);
               if (trace&T_LD1)
                  printf("  loading seg %s %f[%ld]->%f[%ld]\n",segId->name,
                         p->start,segStIdx,p->end,segEnIdx);
               nObs += SegLength(segStore, segIdx);
               segIdx++;
            }else if (trace&T_LD1)
               printf("   seg %s %f->%f ignored\n",segId->name,
                      p->start,p->end);
         }        
      }  
   }
   if (hset.hsKind == DISCRETEHS){
      for (k=prevSegIdx; k<segIdx; k++){
         segLen = SegLength(segStore, k);
         for (i=1; i<=segLen; i++){
            obs = GetSegObs(segStore, k, i);
            for (s=1; s<=nStreams; s++){
               if( (obs.vq[s] < 1) || (obs.vq[s] > maxMixInS[s]))
                  HError(2150,"LoadFile: Discrete data value [ %d ] out of range in stream [ %d ] in file %s",obs.vq[s],s,fn);
            }
         }
      }
      prevSegIdx=segIdx;
   }

   if (trace&T_LD0)
      printf(" %d observations loaded from %s\n",nObs,fn);
   CloseBuffer(pbuf);
   ResetHeap(&transStack);
}
示例#23
0
   barwidth = itemWidth*(nItems+1);

}



/* PrintHeading: print the info in given HeadInfo record */

void PrintHeading(HeadInfo h)

{

   char buf[MAXSTRLEN];

   

   if (h.isSource){

      if (h.isAudio)

         strcpy(buf,"Source: Direct Audio");    

      else

         sprintf(buf,"Source: %s", h.name);

   }else

      strcpy(buf,"Target");

   PrBar(buf);

   printf("  Sample Bytes:  %-7d", h.sampSize);

   if (barwidth < 60 ) printf("\n");

   printf("  Sample Kind:   %s\n", ParmKind2Str(h.kind,buf));

   printf("  Num Comps:     %-7d", h.numComps);

   if (barwidth < 60 ) printf("\n");

   printf("  Sample Period: %.1f us\n", h.period/10.0);     

   if (!h.isAudio) {

      printf("  Num Samples:   %-7ld", h.nSamples);

      if (barwidth < 60 ) printf("\n");

      printf("  File Format:   %s\n", Format2Str(h.fmt));

   }

}



/* PrintWaveLine: print line of waveform samples */

void PrintWaveLine(short *data, int nItems, long idx)

{

   int i;

   

   if (!rawOut) printf("%5ld: ",idx);

   for (i=0; i<nItems; i++)  printf("%7d",*data++);

   printf("\n");

}



/* PrintRawVec: print vector components */

void PrintRawVec(Vector v)

{

   int i;

   

   for (i=1; i<=VectorSize(v); i++)  printf("%e ",v[i]);

   printf("\n");
示例#24
0
/* ViterbiAlign: align the segNum'th segment.  For each frame k, store aligned
   state in states and mostly likely mix comp in mixes.  Return logP. */
LogFloat ViterbiAlign(int segNum,int segLen, IntVec states, IntVec *mixes)
{
   int currState,prevState,bestPrevState;
   int segIdx;
   LogFloat  bestP,currP,tranP,prevP;
   Observation obs;

   if (trace & T_VIT)
      printf(" Aligning Segment Number %d\n",segNum);
   MakeTraceBack(segLen);
   
   /* From entry state 1: Column 1 */
   obs = GetSegObs(segStore, segNum, 1);
   if (hset.hsKind == TIEDHS)
      PrecomputeTMix(&hset, &obs, 50.0, 0);
   for (currState=2;currState<nStates;currState++) {
      tranP = hmmLink->transP[1][currState];
      if (tranP<LSMALL) 
         lastP[currState] = LZERO;
      else
         lastP[currState] = tranP + OutP(&obs,hmmLink,currState);
      traceBack[1][currState] = 1;
   }
   if (trace & T_VIT) ShowP(1,lastP);  
   
   /* Columns[2] -> Columns[segLen] -- this is the general case */
   for (segIdx=2; segIdx<=segLen; segIdx++) {
      obs = GetSegObs(segStore, segNum, segIdx);
      if (hset.hsKind == TIEDHS)
         PrecomputeTMix(&hset, &obs, 50.0, 0);      
      for (currState=2;currState<nStates;currState++) {
         bestPrevState=2;
         tranP = hmmLink->transP[2][currState]; prevP = lastP[2];
         bestP = (tranP<LSMALL) ? LZERO : tranP+prevP;
         for (prevState=3;prevState<nStates;prevState++) {
            tranP = hmmLink->transP[prevState][currState];
            prevP = lastP[prevState];
            currP = (tranP<LSMALL) ? LZERO : tranP+prevP;
            if (currP > bestP) {
               bestPrevState=prevState; bestP=currP;
            }
         }
         if (bestP<LSMALL)
            currP = thisP[currState] = LZERO;
         else {
            currP = OutP(&obs,hmmLink,currState);
            thisP[currState] = bestP+currP;
         }
         if (trace&T_OBP)
            printf("OutP[s=%d,t=%d] = %f\n",currState,segIdx,currP);
         traceBack[segIdx][currState]=bestPrevState;
      }
      CopyVector(thisP,lastP);
      if (trace & T_VIT) ShowP(segIdx,lastP);   
   }
   
   /* column[segLen]--> exit state(numStates) */
   bestPrevState=2;
   tranP = hmmLink->transP[2][nStates]; prevP = lastP[2];
   bestP=(tranP<LSMALL) ? LZERO : tranP+prevP;
   for (prevState=3;prevState<nStates;prevState++) {
      tranP = hmmLink->transP[prevState][nStates]; prevP = lastP[prevState];
      currP = (tranP<LSMALL) ? LZERO : tranP+prevP;
      if (currP > bestP) {
         bestPrevState=prevState; bestP=currP;
      }
   }  

   /* bestPrevState now gives last internal state along best state sequence */
   if (bestP<LSMALL)
      HError(2126,"ViterbiAlign: No path found in %d'th segment",segNum);
   if (trace & T_VIT) {
      ShowTraceBack(segLen,traceBack);
      printf(" bestP = %12.5f via state %d\n",bestP,bestPrevState);
      fflush(stdout);
   }
   DoTraceBack(segLen,states,bestPrevState);
   if (mixes!=NULL)  /* ie not DISCRETE */
      FindBestMixes(segNum,segLen,states,mixes);
   ResetHeap( &traceBackStack );
   return bestP;  
}
示例#25
0
文件: HLVRec.c 项目: didw/HTS
/* 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);
}
示例#26
0
/* EXPORT->ResetMem: reset module */
void ResetMem(void)
{
   ResetHeap(&gstack);
   
   return;
}
示例#27
0
/* UniformSegment: and cluster within each state/segment */
void UniformSegment(void)
{
   Sequence **seqMat;   /* Matrix [2..numStates-1][1..numStreams]*/
   Sequence seq;
   int count,size,i,s,n,m,M,j,k;
   long int vqidx;
   ClusterSet *cset;
   Cluster *c;
   StreamElem *ste;
   Covariance cov;
   CovKind ck;
   MixPDF *mp;
   TMixRec *tmRec = NULL;
   ShortVec dw;
   float x,z;
   Vector floor;

   if (trace & T_UNI)
      printf(" Uniform Segmentation\n");
   seqMat = CreateSeqMat();
   cov.var = NULL;      /* dummy */
   UCollectData(seqMat);
   if (trace&T_UNI) ShowSeqMat(seqMat);

   /* Cluster Each State/Stream and Init HMM Parms */
   for (n=2; n<nStates; n++) {
      if (trace&T_UNI) printf(" state %d ",n);
      for (s=1; s<=nStreams; s++){
         size = hset.swidth[s];
         floor = vFloor[s];
         ste = hmmLink->svec[n].info->pdf+s;
         if (hset.hsKind == TIEDHS){
            tmRec = &(hset.tmRecs[s]);
            M = tmRec->nMix;
            tmRec->topM = tmRec->nMix;
         }
         else
            M = ste->nMix; 
         if (trace&T_UNI) printf(" stream %d\n",s);
         seq = seqMat[n][s];
         switch (hset.hsKind){
         case PLAINHS:
         case SHAREDHS:
            ck = ste->spdf.cpdf[1].mpdf->ckind;
            cset = FlatCluster(&clustSetStack,seq,M,NULLC,ck,cov);
            if (trace&T_UNI) ShowClusterSet(cset);
            for (m=1; m<=M; m++){
               mp = ste->spdf.cpdf[m].mpdf;
               if (mp->ckind != ck)
                  HError(2123,"UniformSegment: different covkind within a mix\n");
               c = cset->cl+m;
               if (uFlags&UPMIXES)
                  ste->spdf.cpdf[m].weight = (float)c->csize/(float)seq->nItems;
               if (uFlags&UPMEANS)
                  CopyVector(c->vCtr,mp->mean);
               if (uFlags&UPVARS)
                  switch(ck){
                  case DIAGC:
                     for (j=1; j<=size; j++){
                        z= c->cov.var[j];
                        mp->cov.var[j] = (z<floor[j])?floor[j]:z;
                     }
                     break;
                  case FULLC:
                     for (j=1; j<=size; j++){
                        for (k=1; k<j; k++) {
                           mp->cov.inv[j][k] = c->cov.inv[j][k];
                        }
                        z = c->cov.inv[j][j];
                        mp->cov.inv[j][j] = (z<floor[j])?floor[j]:z;
                     }
                     break;
                  default:
                     HError(2124,"UniformSegment: bad cov kind %d\n",ck);
                  }
            }
            break;
         case DISCRETEHS:
            count = 0; dw = ste->spdf.dpdf;
            ZeroShortVec(dw);             
            for (i=1; i<=seq->nItems; i++){
               vqidx = (long int)GetItem(seq,i);
               if (vqidx<1 || vqidx>M)
                  HError(2170,"UniformSegment: vqidx out of range[%ld]",vqidx);
               ++dw[vqidx]; ++count;
            }
            for (m=1; m<=M; m++){
               x = (float)dw[m]/(float)count;
               if (x<mixWeightFloor) x = mixWeightFloor;
               dw[m] = DProb2Short(x);
            }
            break;
         case TIEDHS:
            ck = tmRec->mixes[1]->ckind;
            cset = FlatCluster(&clustSetStack,seq,M,NULLC,ck,cov);
            if (trace&T_UNI) ShowClusterSet(cset);
            for (m=1; m<=M; m++){
               mp = tmRec->mixes[m];
               if (mp->ckind != ck)
                  HError(2123,"UniformSegment: different covkind within a mix\n");
               c = cset->cl+m;
               if (uFlags&UPMIXES)
                  ste->spdf.tpdf[m] = (float)c->csize/(float)seq->nItems;
               if (uFlags&UPMEANS)
                  CopyVector(c->vCtr,mp->mean);
               if (uFlags&UPVARS)
                  switch(ck){
                  case DIAGC:
                     for (j=1; j<=size; j++){
                        z= c->cov.var[j];
                        mp->cov.var[j] = (z<floor[j])?floor[j]:z;
                     }
                     break;
                  case FULLC:
                     for (j=1; j<=size; j++){
                        for (k=1; k<j; k++) {
                           mp->cov.inv[j][k] = c->cov.inv[j][k];
                        }
                        z = c->cov.inv[j][j];
                        mp->cov.inv[j][j] = (z<floor[j])?floor[j]:z;
                     }
                     break;                     
                  default:
                     HError(2124,"UniformSegment: bad cov kind %d\n",ck);
                  }                 
            }
            break;       
         }
         ResetHeap(&clustSetStack);
      }
      if ((hset.hsKind == PLAINHS) || (hset.hsKind == SHAREDHS))
         FixGConsts(hmmLink);
   }
   ResetHeap(&sequenceStack);
}
示例#28
0
/* main: */
int main(int argc, char *argv[])
{
   char *s;
   char fname[MAXSTRLEN];

   InitShell(argc, argv, hmgetool_version, hmgetool_vc_id);
   InitMem();
   InitMath();
   InitSigP();
   InitWave();
   InitLabel();
   InitModel();
   InitTrain();
   InitParm();
   InitUtil();
   InitFB();
   InitGen();
   InitAdapt(&xfInfo, NULL);
   InitMTrain();

   /* process argument */
   if (NumArgs() == 0)
      ReportUsage();
   CreateHeap(&hmmStack, "Model Stack", MSTAK, 1, 1.0, 80000, 4000000);
   CreateHeap(&orighmmStack, "Model Stack", MSTAK, 1, 1.0, 80000, 4000000);
   CreateHeap(&accStack, "Acc Stack", MSTAK, 1, 1.0, 80000, 400000);
   CreateHeap(&genStack, "Gen Stack", MSTAK, 1, 1.0, 80000, 400000);
   CreateHeap(&mgeStack, "MGE Train Stack", MSTAK, 1, 1.0, 80000, 400000);

   SetConfParms();
   CreateHMMSet(&hset, &hmmStack, TRUE);
   CreateHMMSet(&orighset, &orighmmStack, TRUE);

   statInfo = (MTStatInfo *) New(&gstack, sizeof(MTStatInfo));
   memset(statInfo, 0, sizeof(MTStatInfo));

   genInfo = (GenInfo *) New(&genStack, sizeof(GenInfo));
   memset(genInfo, 0, sizeof(GenInfo));
   genInfo->hset = &hset;
   genInfo->genMem = &genStack;

   mtInfo = (MgeTrnInfo *) New(&mgeStack, sizeof(MgeTrnInfo));
   memset(mtInfo, 0, sizeof(MgeTrnInfo));
   mtInfo->genInfo = genInfo;
   mtInfo->statInfo = statInfo;
   mtInfo->hset = &hset;
   mtInfo->orighset = &orighset;
   mtInfo->mgeMem = &mgeStack;

   while (NextArg() == SWITCHARG) {
      s = GetSwtArg();
      if (strlen(s) != 1)
         HError(6601, "HMgeTool: Bad switch %s; must be single letter", s);
      switch (s[0]) {
      case 'a':
         nMaxBAIter = GetChkedInt(1, 1000, s);
         nMaxBALen = GetChkedInt(1, 1000, s);
         break;
      case 'b':
         mtInfo->bBoundAdj = TRUE;
         nBAEndIter = GetChkedInt(0, 1000, s);
         nBoundAdjWin = GetChkedInt(1, 1000, s);
         break;
      case 'c':
         outProcData = TRUE;
         break;
      case 'd':
         if (NextArg() != STRINGARG)
            HError(6601, "HMgeTool: HMM definition directory expected");
         hmmDir = GetStrArg();
         break;
      case 'e':
         mtInfo->bStepLimit = TRUE;
         break;
      case 'f':
         frameRate = (HTime) GetChkedFlt(0.0, 10000000.0, s);
         break;
      case 'g':
         mtInfo->bMVar = TRUE;
         break;
      case 'i':
         startIter = GetChkedInt(0, 1000, s);
         endIter = GetChkedInt(startIter, 1000, s);
         break;
      case 'j':
         funcType = GetChkedInt(0, 2, s);
         mtInfo->funcType = funcType;
         break;
      case 'l':
         if (NextArg() != STRINGARG)
            HError(6601, "HMgeTool: Label file output directory expected");
         outLabDir = GetStrArg();
         break;
      case 'o':
         if (NextArg() != STRINGARG)
            HError(6601, "HMgeTool: HMM file extension expected");
         outExt = GetStrArg();
         break;
      case 'p':
         A_STEP = GetChkedFlt(0.0, 10000000.0, s);
         B_STEP = GetChkedFlt(0.0, 10000000.0, s);
         break;
      case 'r':
         mtInfo->bOrigHmmRef = TRUE;
         if (NextArg() != STRINGARG)
            HError(6601, "HMgeTool: HMM macro file name expected");
         s = GetStrArg();
         AddMMF(&orighset, s);
         break;
      case 's':                /* updating scale file */
         scalefn = GetStrArg();
         break;
      case 'u':
         SetuFlags();
         break;
      case 'v':
         MSDthresh = GetChkedFlt(0.0, 1.0, s);
         break;
      case 'w':
         fGVDistWght = GetChkedFlt(0.0, 1000.0, s);
         break;
      case 'x':
         if (NextArg() != STRINGARG)
            HError(6601, "HMgeTool: HMM file extension expected");
         hmmExt = GetStrArg();
         break;
      case 'B':
         inBinary = TRUE;
         break;
      case 'G':
         mtInfo->nGainStreamIndex = GetChkedInt(1, SMAX, s);
         mtInfo->nGainDimIndex = GetChkedInt(1, 1000, s);
         if (NextArg() == FLOATARG || NextArg() == INTARG)
            mtInfo->fGainWghtComp = GetChkedFlt(-10000.0, 1000000.0, s);
         break;
      case 'H':
         if (NextArg() != STRINGARG)
            HError(6601, "HMgeTool: HMM macro file name expected");
         mmfFn = GetStrArg();
         AddMMF(&hset, mmfFn);
         break;
      case 'I':
         if (NextArg() != STRINGARG)
            HError(6601, "HMgeTool: MLF file name expected");
         LoadMasterFile(GetStrArg());
         break;
      case 'J':                /* regression class and tree */
         if (NextArg() != STRINGARG)
            HError(6601, "HMgeTool: HMM regression class/tree file name expected");
         s = GetStrArg();
         AddMMF(&hset, s);
         AddMMF(&orighset, s);
         break;
      case 'K':
         if (NextArg() != STRINGARG)
            HError(6601, "HMgeTool: HMM transform file name expected");
         xformfn = GetStrArg();
         break;
      case 'L':
         if (NextArg() != STRINGARG)
            HError(6601, "HMgeTool: Label file directory expected");
         labDir = GetStrArg();
         break;
      case 'M':
         if (NextArg() != STRINGARG)
            HError(6601, "HMgeTool: Output macro file directory expected");
         outDir = GetStrArg();
         break;
      case 'T':
         trace = GetChkedInt(0, 0100000, s);
         break;
      case 'X':
         if (NextArg() != STRINGARG)
            HError(2319, "HMGenS: Label file extension expected");
         labExt = GetStrArg();
         break;
      default:
         HError(6601, "HMgeTool: Unknown switch %s", s);
      }
   }

   if (NextArg() != STRINGARG)
      HError(6601, "HMgeTool: file name of model list expected");
   hmmListFn = GetStrArg();
   Initialise();

   if (funcType == MGE_EVAL) {
      PerformMgeEval();
   } else if (funcType == MGE_TRAIN) {
      PerformMgeTrain();
      if (endIter > 0 && bMgeUpdate) {
         /* output HMM files */
         ConvDiagC(&hset, TRUE);
         SaveHMMSet(&hset, outDir, outExt, NULL, inBinary);
      }
   } else if (funcType == MGE_ADAPT) {
      PerformMgeAdapt();
      if (endIter > 0 && bMgeUpdate) {
         MakeFN(xformfn, outDir, NULL, fname);
         SaveOneXForm(&hset, hset.curXForm, fname, FALSE);
      }
   }

   ResetHeap(&hmmStack);
   ResetHeap(&orighmmStack);
   ResetHeap(&accStack);
   ResetHeap(&genStack);
   ResetHeap(&mgeStack);

   return 0;
}
示例#29
0
/* SetConfParms: set conf parms relevant to HCompV  */

void SetConfParms(void)

{

   int i;

   Boolean b;

   double f;

   char buf[MAXSTRLEN];

   

   nParm = GetConfig("HEREST", TRUE, cParm, MAXGLOBS);

   if (nParm>0) {

      if (GetConfInt(cParm,nParm,"TRACE",&i)) trace = i;

      if (GetConfFlt(cParm,nParm,"VARFLOORPERCENTILE",&f)) varFloorPercent = f;

      if (GetConfBool(cParm,nParm,"SAVEBINARY",&b)) saveBinary = b;

      if (GetConfBool(cParm,nParm,"BINARYACCFORMAT",&b)) ldBinary = b;

      /* 2-model reestimation alignment model set */

      if (GetConfStr(cParm,nParm,"ALIGNMODELMMF",buf)) {

          strcpy(al_hmmMMF,buf); al_hmmUsed = TRUE;

      }

      if (GetConfStr(cParm,nParm,"ALIGNHMMLIST",buf)) {

          strcpy(al_hmmLst,buf); al_hmmUsed = TRUE;

      }

      /* allow multiple individual model files */

      if (GetConfStr(cParm,nParm,"ALIGNMODELDIR",buf)) {

          strcpy(al_hmmDir,buf); al_hmmUsed = TRUE;

      }

      if (GetConfStr(cParm,nParm,"ALIGNMODELEXT",buf)) {

          strcpy(al_hmmExt,buf); al_hmmUsed = TRUE;

      }

      if (GetConfStr(cParm,nParm,"ALIGNXFORMEXT",buf)) {

         xfInfo.alXFormExt = CopyString(&hmmStack,buf);

      }

      if (GetConfStr(cParm,nParm,"ALIGNXFORMDIR",buf)) {

         xfInfo.alXFormDir = CopyString(&hmmStack,buf);

      }

      if (GetConfStr(cParm,nParm,"INXFORMMASK",buf)) {

         xfInfo.inSpkrPat = CopyString(&hmmStack,buf);

      }

      if (GetConfStr(cParm,nParm,"PAXFORMMASK",buf)) {

         xfInfo.paSpkrPat = CopyString(&hmmStack,buf);

      }

      if (GetConfStr(cParm,nParm,"LABFILEMASK",buf)) {

         labFileMask = (char*)malloc(strlen(buf)+1); 

         strcpy(labFileMask, buf);

      }



      if (GetConfStr(cParm,nParm,"UPDATEMODE",buf)) {

         if (!strcmp (buf, "DUMP")) updateMode = UPMODE_DUMP;

         else if (!strcmp (buf, "UPDATE")) updateMode = UPMODE_UPDATE;

         else if (!strcmp (buf, "BOTH")) updateMode = UPMODE_BOTH;

         else HError(2319, "Unknown UPDATEMODE specified (must be DUMP, UPDATE or BOTH)");

      }

   }

}



void ReportUsage(void)

{

   printf("\nUSAGE: HERest [options] hmmList dataFiles...\n\n");

   printf(" Option                                       Default\n\n");

   printf(" -a      Use an input linear transform        off\n");

   printf(" -c f    Mixture pruning threshold            10.0\n");

   printf(" -d s    dir to find hmm definitions          current\n");

   printf(" -h s    set output speaker name pattern   *.%%%%%%\n");

   printf("         to s, optionally set input and parent patterns\n");

   printf(" -l N    set max files per speaker            off\n");

   printf(" -m N    set min examples needed per model    3\n");

   printf(" -o s    extension for new hmm files          as src\n");

   printf(" -p N    set parallel mode to N               off\n");

   printf(" -r      Enable Single Pass Training...       \n");

   printf("         ...using two parameterisations       off\n");

   printf(" -s s    print statistics to file s           off\n");

   printf(" -t f [i l] set pruning to f [inc limit]      inf\n");

   printf(" -u tmvwap  update t)rans m)eans v)ars w)ghts tmvw\n");

   printf("                a)daptation xform p)rior used     \n");

   printf("                s)semi-tied xform                 \n");

   printf(" -v f    set minimum variance to f            0.0\n");

   printf(" -w f    set mix weight floor to f*MINMIX     0.0\n");

   printf(" -x s    extension for hmm files              none\n");

   printf(" -z s    Save all xforms to TMF file s        TMF\n");

   PrintStdOpts("BEFGHIJKLMSTX");

   printf("\n\n");

}



void SetuFlags(void)

{

   char *s;

   

   s=GetStrArg();

   uFlags=(UPDSet) 0;        

   while (*s != '\0')

      switch (*s++) {

      case 't': uFlags = (UPDSet) (uFlags+UPTRANS); break;

      case 'm': uFlags = (UPDSet) (uFlags+UPMEANS); break;

      case 'v': uFlags = (UPDSet) (uFlags+UPVARS); break;

      case 'w': uFlags = (UPDSet) (uFlags+UPMIXES); break;

      case 's': uFlags = (UPDSet) (uFlags+UPSEMIT); break;

      case 'a': uFlags = (UPDSet) (uFlags+UPXFORM); break;

      case 'p': uFlags = (UPDSet) (uFlags+UPMAP); break;

      default: HError(2320,"SetuFlags: Unknown update flag %c",*s);

         break;

      }

}



/* ScriptWord: return next word from script */

char *ScriptWord(FILE *script, char *scriptBuf)

{

   int ch,qch,i;

   

   i=0; ch=' ';

   while (isspace(ch)) ch = fgetc(script);

   if (ch==EOF) {

      scriptBuf=NULL;

      return NULL;

   }

   if (ch=='\'' || ch=='"'){

      qch = ch;

      ch = fgetc(script);

      while (ch != qch && ch != EOF) {

         scriptBuf[i++] = ch; 

         ch = fgetc(script);

      }

      if (ch==EOF)

         HError(5051,"ScriptWord: Closing quote missing in script file");

   } else {

      do {

         scriptBuf[i++] = ch; 

         ch = fgetc(script);

      }while (!isspace(ch) && ch != EOF);

   }

   scriptBuf[i] = '\0';



   return scriptBuf;

}



void CheckUpdateSetUp()

{

  AdaptXForm *xf;
示例#30
0
/* 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);
         }
      }
   }
}