コード例 #1
0
ファイル: Tool_HCopy.c プロジェクト: cfxccn/HTKLib
/* 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);
}
コード例 #2
0
ファイル: HInit.c プロジェクト: songzhengxuan/kata
/* CheckData: check data file consistent with HMM definition */
void CheckData(char *fn, BufferInfo info) 
{

   char tpk[80];
   char mpk[80];
   
   if (info.tgtPK != hset.pkind)
      HError(2150,"CheckData: Parameterisation in %s[%s] is incompatible with hmm %s[%s]",
             fn,ParmKind2Str(info.tgtPK,tpk),hmmfn,ParmKind2Str(hset.pkind,mpk));
   if (info.tgtVecSize!=hset.vecSize)
      HError(2150,"CheckData: Vector size in %s[%d] is incompatible with hmm %s[%d]",
             fn,info.tgtVecSize,hmmfn,hset.vecSize);
}
コード例 #3
0
/* 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;
   }
}
コード例 #4
0
ファイル: Tool_HCopy.c プロジェクト: cfxccn/HTKLib
/* OpenSpeechFile: open waveform or parm file */
void OpenSpeechFile(char *s)
{
   HTime len;
   char buf[MAXSTRLEN];
   
   if (labF) tr = LoadTransLabs(s);   
   if(IsWave(s))  
      len = OpenWaveFile(s);
   else  
      len = OpenParmFile(s);
   if(labF) AppendLabs(tr,len);
   if (trace & T_TOP) AppendTrace(s);
   if (tgtPK == ANON) tgtPK = srcPK;      
   if(trace & T_KINDS){
      printf("Source file format: %s [%s]\n",
             Format2Str(srcFF), ParmKind2Str(srcPK,buf));
      printf("Target file format: %s [%s]\n",
             Format2Str(tgtFF), ParmKind2Str(tgtPK,buf));
      printf("Source rate: %.0f Target rate: %.0f \n",
             srcSampRate,tgtSampRate);
   }
}
コード例 #5
0
ファイル: HList.c プロジェクト: BackupTheBerlios/artbody-svn
   

int main(int argc, char *argv[])

{

   char *s,buf[MAXSTRLEN];

   void ListSpeech(char *src);

   

   if(InitShell(argc,argv,hlist_version,hlist_vc_id)<SUCCESS)

      HError(1100,"HList: InitShell failed");

   InitMem();

   InitMath();  InitSigP();

   InitWave();  InitAudio();

   InitVQ(); InitLabel();
コード例 #6
0
ファイル: fileio.C プロジェクト: alongwithyou/PhnRec
 //***************************************************************************
 //***************************************************************************
 void ReadCepsNormFile(
   const char *  pFileName, 
   char **       pLastFileName, 
   FLOAT **      vec_buff,
   int           sampleKind, 
   CNFileType    type, 
   int           coefs)
 {
   FILE *  fp;
   int     i;
   char    s1[9];
   char    s2[64];
   char *  typeStr = (char*) (type == CNF_Mean     ? "MEAN" :
                   type == CNF_Variance ? "VARIANCE" : "VARSCALE");
 
   char *  typeStr2 = (char*) (type == CNF_Mean     ? "CMN" :
                   type == CNF_Variance ? "CVN" : "VarScale");
 
   if (*pLastFileName != NULL && !strcmp(*pLastFileName, pFileName)) {
     return;
   }
   free(*pLastFileName);
   *pLastFileName=strdup(pFileName);
   *vec_buff = (FLOAT*) realloc(*vec_buff, coefs * sizeof(FLOAT));
 
   if (*pLastFileName == NULL || *vec_buff== NULL) 
     Error("Insufficient memory");
   
   if ((fp = fopen(pFileName, "r")) == NULL) 
     Error("Cannot open %s pFileName: '%s'", typeStr2, pFileName);
   
   if ((type != CNF_VarScale
       && (fscanf(fp, " <%64[^>]> <%64[^>]>", s1, s2) != 2
         || strcmp(strtoupper(s1), "CEPSNORM")
         || ReadParmKind(s2, false) != sampleKind))
       || fscanf(fp, " <%64[^>]> %d", s1, &i) != 2
       || strcmp(strtoupper(s1), typeStr)
       || i != coefs) 
   {
     ParmKind2Str(sampleKind, s2);
     Error("%s%s%s <%s> %d ... expected in %s pFileName %s",
           type == CNF_VarScale ? "" : "<CEPSNORM> <",
           type == CNF_VarScale ? "" : s2,
           type == CNF_VarScale ? "" : ">",
           typeStr, coefs, typeStr2, pFileName);
   }
   
   for (i = 0; i < coefs; i++) 
   {
     if (fscanf(fp, " "FLOAT_FMT, *vec_buff+i) != 1) 
     {
       if (fscanf(fp, "%64s", s2) == 1) 
       {
         Error("Decimal number expected but '%s' found in %s file %s",
               s2, typeStr2, pFileName);
       } 
       else if (feof(fp)) 
       {
         Error("Unexpected end of %s file %s", typeStr2, pFileName);
       } 
       else 
       {
         Error("Cannot read %s file %s", typeStr2, pFileName);
       }
     }
     
     if (type == CNF_Variance)      
       (*vec_buff)[i] = 1 / sqrt((*vec_buff)[i]);
     else if (type == CNF_VarScale) 
       (*vec_buff)[i] =     sqrt((*vec_buff)[i]);
   }
   
   if (fscanf(fp, "%64s", s2) == 1) 
   {
     Error("End of file expected but '%s' found in %s file %s",
           s2, typeStr2, pFileName);
   }
 } // ReadCepsNormFile(...)
コード例 #7
0
ファイル: fileio.C プロジェクト: alongwithyou/PhnRec
 //***************************************************************************
 //***************************************************************************
 FLOAT *ReadHTKFeatures(
   char *                pFileName,
   bool                  swap,
   int                   extLeft,
   int                   extRight,
   int                   targetKind,
   int                   derivOrder,
   int *                 derivWinLen,
   HtkHeader *           pHeader,
   const char *          pCmnFile,
   const char *          pCvnFile,
   const char *          pCvgFile,
   RHFBuffer *           pBuff)
 {
   FLOAT *               fea_mx;
   int                   from_frame;
   int                   to_frame;
   int                   tot_frames;
   int                   trg_vec_size;
   int                   src_vec_size;
   int                   src_deriv_order;
   int                   lo_src_tgz_deriv_order;
   int                   i;
   int                   j;
   int                   k;
   int                   e;
   int                   coefs;
   int                   trg_E;
   int                   trg_0;
   int                   trg_N;
   int                   src_E;
   int                   src_0;
   int                   src_N;
   int                   comp;
   int                   coef_size;
   char *                chptr;
   //IStkStream            istr;
 
   // remove final spaces from file name
   for (i = strlen(pFileName) - 1; i >= 0 && isspace(pFileName[i]); i--)
   { 
     pFileName[i] = '\0';
   }
     
  
   // read frame range definition if any ( physical_file.fea[s,e] )
   if ((chptr = strrchr(pFileName, '[')) == NULL ||
       ((i=0), sscanf(chptr, "[%d,%d]%n", &from_frame, &to_frame, &i), chptr[i] != '\0')) 
   {
     chptr = NULL;
   }
   
   if (chptr != NULL) 
     *chptr = '\0';
 
   if ((strcmp(pFileName, "-"))
   &&  (pBuff->mpLastFileName != NULL) 
   &&  (!strcmp(pBuff->mpLastFileName, pFileName))) 
   {
     *pHeader = pBuff->last_header;
   } 
   else 
   {
     if (pBuff->mpLastFileName) 
     {
       if (pBuff->mpFp != stdin) 
         fclose(pBuff->mpFp);
       
       free(pBuff->mpLastFileName);
       pBuff->mpLastFileName = NULL;
     }
     
     
     if (!strcmp(pFileName, "-")) 
       pBuff->mpFp = stdin;
     else 
       pBuff->mpFp = fopen(pFileName, "rb");
     
     if (pBuff->mpFp == NULL) 
       Error("Cannot open feature file: '%s'", pFileName);
     
     /*
     istr.open(pFileName, ios::binary);
     if (!istr.good())
       Error("Cannot open feature file: '%s'", pFileName);
     pBuff->mpFp = istr.file();  
     */
     
     if (ReadHTKHeader(pBuff->mpFp, pHeader, swap)) 
       Error("Invalid HTK header in feature file: '%s'", pFileName);
     
     if (pHeader->mSampleKind & PARAMKIND_C) 
     {
       // File is in compressed form, scale and pBias vectors
       // are appended after HTK header.
 
       int coefs = pHeader->mSampleSize/sizeof(INT_16);
       pBuff->A = (FLOAT*) realloc(pBuff->A, coefs * sizeof(FLOAT_32));
       pBuff->B = (FLOAT*) realloc(pBuff->B, coefs * sizeof(FLOAT_32));
       if (pBuff->A == NULL || pBuff->B == NULL) Error("Insufficient memory");
 
       e  = ReadHTKFeature(pBuff->mpFp, pBuff->A, coefs, swap, 0, 0, 0);
       e |= ReadHTKFeature(pBuff->mpFp, pBuff->B, coefs, swap, 0, 0, 0);
       
       if (e) 
         Error("Cannot read feature file: '%s'", pFileName);
       
       pHeader->mNSamples -= 2 * sizeof(FLOAT_32) / sizeof(INT_16);
     }
     
     if ((pBuff->mpLastFileName = strdup(pFileName)) == NULL) 
       Error("Insufficient memory");
     
     pBuff->last_header = * pHeader;
   }
   
   if (chptr != NULL) 
     *chptr = '[';
 
   if (chptr == NULL) 
   { // Range [s,e] was not specified
     from_frame = 0;
     to_frame   = pHeader->mNSamples-1;
   }
   
   src_deriv_order = PARAMKIND_T & pHeader->mSampleKind ? 3 :
                     PARAMKIND_A & pHeader->mSampleKind ? 2 :
                     PARAMKIND_D & pHeader->mSampleKind ? 1 : 0;
   src_E =  (PARAMKIND_E & pHeader->mSampleKind) != 0;
   src_0 =  (PARAMKIND_0 & pHeader->mSampleKind) != 0;
   src_N = ((PARAMKIND_N & pHeader->mSampleKind) != 0) * (src_E + src_0);
   comp =    PARAMKIND_C & pHeader->mSampleKind;
   
   pHeader->mSampleKind &= ~PARAMKIND_C;
 
   if (targetKind == PARAMKIND_ANON) 
   {
     targetKind = pHeader->mSampleKind;
   } 
   else if ((targetKind & 077) == PARAMKIND_ANON) 
   {
     targetKind &= ~077;
     targetKind |= pHeader->mSampleKind & 077;
   }
   
   trg_E = (PARAMKIND_E & targetKind) != 0;
   trg_0 = (PARAMKIND_0 & targetKind) != 0;
   trg_N =((PARAMKIND_N & targetKind) != 0) * (trg_E + trg_0);
 
   coef_size     = comp ? sizeof(INT_16) : sizeof(FLOAT_32);
   coefs         = (pHeader->mSampleSize/coef_size + src_N) / 
                   (src_deriv_order+1) - src_E - src_0;
   src_vec_size  = (coefs + src_E + src_0) * (src_deriv_order+1) - src_N;
 
   //Is coefs dividable by 1 + number of derivatives specified in header
   if (src_vec_size * coef_size != pHeader->mSampleSize) 
   {
     Error("Invalid HTK header in feature file: '%s'. "
           "mSampleSize do not match with parmKind", pFileName);
   }
   
   if (derivOrder < 0) 
     derivOrder = src_deriv_order;
 
 
   if ((!src_E && trg_E) || (!src_0 && trg_0) || (src_N && !trg_N) ||
       (trg_N && !trg_E && !trg_0) || (trg_N && !derivOrder) ||
       (src_N && !src_deriv_order && derivOrder) ||
       ((pHeader->mSampleKind & 077) != (targetKind & 077) &&
        (pHeader->mSampleKind & 077) != PARAMKIND_ANON)) 
   {
     char srcParmKind[64], trgParmKind[64];
     ParmKind2Str(pHeader->mSampleKind, srcParmKind);
     ParmKind2Str(targetKind,       trgParmKind);
     Error("Cannot convert %s to %s", srcParmKind, trgParmKind);
   }
 
   lo_src_tgz_deriv_order = LOWER_OF(src_deriv_order, derivOrder);
   trg_vec_size  = (coefs + trg_E + trg_0) * (derivOrder+1) - trg_N;
   
   i =  LOWER_OF(from_frame, extLeft);
   from_frame  -= i;
   extLeft     -= i;
 
   i =  LOWER_OF(pHeader->mNSamples-to_frame-1, extRight);
   to_frame    += i;
   extRight    -= i;
 
   if (from_frame > to_frame || from_frame >= pHeader->mNSamples || to_frame < 0)
     Error("Invalid frame range for feature file: '%s'", pFileName);
   
   tot_frames = to_frame - from_frame + 1 + extLeft + extRight;
   fea_mx = (FLOAT *) malloc((trg_vec_size * tot_frames + 1) * sizeof(FLOAT));
   // + 1 needed for safe reading unwanted _E and _0
   
   if (fea_mx == NULL) 
     Error("Insufficient memory");
   
   for (i = 0; i <= to_frame - from_frame; i++) 
   {
     FLOAT *A = pBuff->A, *B = pBuff->B;
     FLOAT *mxPtr = fea_mx + trg_vec_size * (i+extLeft);
     
     fseek(pBuff->mpFp, sizeof(HtkHeader) + 
                        (comp ? src_vec_size * 2 * sizeof(FLOAT_32) : 0) +
                        (from_frame + i) * src_vec_size * coef_size, 
           SEEK_SET);
 
     e  = ReadHTKFeature(pBuff->mpFp, mxPtr, coefs, swap, comp, A, B);
     
     mxPtr += coefs; 
     A     += coefs; 
     B     += coefs;
       
     if (src_0 && !src_N) e |= ReadHTKFeature(pBuff->mpFp, mxPtr, 1, swap, comp, A++, B++);
     if (trg_0 && !trg_N) mxPtr++;
     if (src_E && !src_N) e |= ReadHTKFeature(pBuff->mpFp, mxPtr, 1, swap, comp, A++, B++);
     if (trg_E && !trg_N) mxPtr++;
 
     for (j = 0; j < lo_src_tgz_deriv_order; j++) 
     {
       e |= ReadHTKFeature(pBuff->mpFp, mxPtr, coefs, swap, comp, A, B);
       mxPtr += coefs; 
       A     += coefs; 
       B     += coefs;
       
       if (src_0) e |= ReadHTKFeature(pBuff->mpFp, mxPtr, 1, swap, comp, A++, B++);
       if (trg_0) mxPtr++;
       if (src_E) e |= ReadHTKFeature(pBuff->mpFp, mxPtr, 1, swap, comp, A++, B++);
       if (trg_E) mxPtr++;
     }
     
     if (e) 
       Error("Cannot read feature file: '%s' frame %d/%d", pFileName, i, to_frame - from_frame + 1);
   }
 
   // From now, coefs includes also trg_0 + trg_E !
   coefs += trg_0 + trg_E; 
 
   for (i = 0; i < extLeft; i++) 
   {
     memcpy(fea_mx + trg_vec_size * i,
           fea_mx + trg_vec_size * extLeft,
           (coefs * (1+lo_src_tgz_deriv_order) - trg_N) * sizeof(FLOAT));
   }
   
   for (i = tot_frames - extRight; i < tot_frames; i++) 
   {
     memcpy(fea_mx + trg_vec_size * i,
           fea_mx + trg_vec_size * (tot_frames - extRight - 1),
           (coefs * (1+lo_src_tgz_deriv_order) - trg_N) * sizeof(FLOAT));
   }
   
   // Sentence cepstral mean normalization
   if(pCmnFile == NULL && 
     !(PARAMKIND_Z & pHeader->mSampleKind) && 
       (PARAMKIND_Z & targetKind)) 
   {
     // for each coefficient
     for(j=0; j < coefs; j++) 
     {          
       FLOAT norm = 0.0;
       for(i=0; i < tot_frames; i++)      // for each frame
         norm += fea_mx[i*trg_vec_size - trg_N + j];
 
       norm /= tot_frames;
 
       for(i=0; i < tot_frames; i++)      // for each frame
         fea_mx[i*trg_vec_size - trg_N + j] -= norm;
     }
   }
   
   // Compute missing derivatives
   for (; src_deriv_order < derivOrder; src_deriv_order++) 
   {
     int winLen = derivWinLen[src_deriv_order];
     FLOAT norm = 0.0;
     
     for (k = 1; k <= winLen; k++) 
     {
       norm += 2 * k * k;
     }
     
     // for each frame
     for (i=0; i < tot_frames; i++) 
     {        
       // for each coefficient
       for (j=0; j < coefs; j++) 
       {          
         FLOAT *src = fea_mx + i*trg_vec_size + src_deriv_order*coefs - trg_N + j;
         *(src + coefs) = 0.0;
         
         if (i < winLen || i >= tot_frames-winLen) 
         { // boundaries need special treatment
           for (k = 1; k <= winLen; k++) 
           {  
             *(src+coefs) += k*(src[ LOWER_OF(tot_frames-1-i,k)*trg_vec_size]
                               -src[-LOWER_OF(i,            k)*trg_vec_size]);
           }
         } 
         else 
         { // otherwice use more efficient code
           for (k = 1; k <= winLen; k++) 
           {  
             *(src+coefs) += k*(src[ k * trg_vec_size]
                               -src[-k * trg_vec_size]);
           }
         }
         *(src + coefs) /= norm;
       }
     }
   }
   
   pHeader->mNSamples    = tot_frames;
   pHeader->mSampleSize  = trg_vec_size * sizeof(FLOAT_32);
   pHeader->mSampleKind  = targetKind & ~(PARAMKIND_D | PARAMKIND_A | PARAMKIND_T);
 
   /////////////// Cepstral mean and variance normalization ///////////////////
 
   if (pCmnFile != NULL) 
   {
     ReadCepsNormFile(pCmnFile, &pBuff->mpLastCmnFile, &pBuff->cmn,
                     pHeader->mSampleKind & ~PARAMKIND_Z, CNF_Mean, coefs);
                     
     for (i=0; i < tot_frames; i++) 
     {
       for (j=trg_N; j < coefs; j++) 
       {
         fea_mx[i*trg_vec_size + j - trg_N] -= pBuff->cmn[j];
       }
     }
   }
 
   pHeader->mSampleKind |= derivOrder==3 ? PARAMKIND_D | PARAMKIND_A | PARAMKIND_T :
                           derivOrder==2 ? PARAMKIND_D | PARAMKIND_A :
                           derivOrder==1 ? PARAMKIND_D : 0;
 
   if (pCvnFile != NULL) 
   {
     ReadCepsNormFile(pCvnFile, &pBuff->mpLastCvnFile, &pBuff->cvn,
                     pHeader->mSampleKind, CNF_Variance, trg_vec_size);
                     
     for (i=0; i < tot_frames; i++) 
     {
       for (j=trg_N; j < trg_vec_size; j++) 
       {
         fea_mx[i*trg_vec_size + j - trg_N] *= pBuff->cvn[j];
       }
     }
   }
   
   if (pCvgFile != NULL) 
   {
     ReadCepsNormFile(pCvgFile, &pBuff->mpLastCvgFile, &pBuff->cvg,
                     -1, CNF_VarScale, trg_vec_size);
                     
     for (i=0; i < tot_frames; i++) 
     {
       for (j=trg_N; j < trg_vec_size; j++) 
       {
         fea_mx[i*trg_vec_size + j - trg_N] *= pBuff->cvg[j];
       }
     }
   }
   
   return fea_mx;
 }
コード例 #8
0
ファイル: HVite.c プロジェクト: 2hanson/voice_dialling
/* 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;
}