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

📄 hlabel.c

📁 实现HMM算法
💻 C
📖 第 1 页 / 共 4 页
字号:
         n++;         if (trSym != TRSTR)            HError(6550,"LoadHTKList: Aux Label Name Expected");         auxLab[n] = GetLabId(trStr,TRUE);         if (trace&T_HTKL)            printf("HLabel:   adding aux lab %d = %s\n",n,auxLab[n]->name);         GetTrSym(src,TRUE);         if (trSym==TRNUM){            auxScore[n] = trNum;            if (trace&T_HTKL)               printf("HLabel:   adding aux score %d = %f\n",n,trNum);            GetTrSym(src,TRUE);         } else            auxScore[n] = 0.0;      }      if (ok && n>0) {/*当前n=0,故不执行此分支*/ /* need to add aux info */         if (n>maxAux) {            ExtendAux(x,ll,n);            maxAux = n;         } else while (n<maxAux) {            ++n;            auxLab[n] = NULL;            auxScore[n] = 0.0;         }         AddAuxLab(p,n,auxLab,auxScore);      }      if (trSym!=TREOF)	  GetTrSym(src,TRUE);   }   return ll;}/* LoadHTKLabels: load a HTK transcription */static void LoadHTKLabels(MemHeap *x, Transcription *t, Source *src){   LabList *ll;   int alt = 0;      InitTrScan();   GetTrSym(src,TRUE);   if (trSym==TRNUM || trSym==TRSTR){      ll = LoadHTKList(x,src,++alt);      AddLabelList(ll,t);      while (trSym == TRLEV){/*当前不执行此循环*/         GetTrSym(src,TRUE);         if (trSym != TREOL)            HError(6550,"LoadHTKList: End of Line after /// Expected");                GetTrSym(src,TRUE);         ll = LoadHTKList(x,src,++alt);         AddLabelList(ll,t);      }   }   while (trSym==TREOL)       GetTrSym(src,TRUE);   if (trSym != TREOF)      HError(6550,"LoadHTKLabels: Junk at end of HTK transcription");}/* --------------- TIMIT Label Format --------------------- *//* LoadTIMITLabels: load a TIMIT transcription */static void LoadTIMITLabels(MemHeap *x, Transcription *t, Source *src){   LabList *ll;   LabId labid;   HTime start,end;   float score;      ll = CreateLabelList(x,0);  AddLabelList(ll,t);   InitTrScan();   GetTrSym(src,FALSE);   while (trSym == TRNUM){          start = trNum*625;                 /* sample rate is 16KHz */      GetTrSym(src,FALSE);      if (trSym != TRNUM)          HError(6552,"LoadTIMITLabels: End Time expected in TIMIT Label File");      end   = trNum*625;      GetTrSym(src,FALSE);      if (trSym != TRSTR)          HError(6552,"LoadTIMITLabels: Label Name expected in TIMIT Label File");      labid = GetLabId(trStr,TRUE);      score = 0.0;      AddLabel(x,ll,labid,start,end,score);      GetTrSym(src,FALSE);      if (trSym == TREOL)         GetTrSym(src,FALSE);   }}/* --------------- ESPS Label Format --------------------- *//* LoadESPSLabels: read waves label file */static void LoadESPSLabels(MemHeap *x, Transcription *t, Source *src){   LabList *ll;   LabId labid;   HTime start,end;   float score;      ll = CreateLabelList(x,0);  AddLabelList(ll,t);   InitTrScan();   GetTrSym(src,FALSE);   while ( trStr[0] != '#' ) {      GetTrSym(src,FALSE);      if (trSym == TREOF)          HError(6553,"LoadESPSLabels: Unexpected EOF in ESPS Waves Label file.");      if ( strcmp( "nfields", trStr) == 0 ) {         GetTrSym(src,FALSE);         if ( trSym != TRNUM )            HError(6553,"LoadESPSLabels: Expecting field number");         if ( trNum != 1 )            HError(6553,"LoadESPSLabels: Can only read single field label files.");      }   }   end = start = 0.0; score = 0.0;   GetTrSym(src,FALSE);   while ( trSym != TRNUM && trSym != TREOF )      GetTrSym(src,FALSE);   while ( trSym == TRNUM ) {          start = end;   /* Get time stamp */      end = trNum * 1.0E7;       if ( start > end )         HError(-6553,"LoadESPSLabels: time stamps out of order.");      GetTrSym(src,FALSE);       /* Ignore color */      GetTrSym(src,FALSE);       /* Get field label for current level */      if ( trSym != TRSTR)          HError(6553,"LoadESPSLabels: Expecting label string in ESPS Waves Label file.");      labid = GetLabId( trStr,TRUE);       AddLabel(x,ll,labid,start,end,score);        GetTrSym(src,FALSE);      if ( trSym != TREOL )         HError(6553,"LoadESPSLabels: End-of-line expected in ESPS Waves Label file.");      GetTrSym(src,FALSE);   }}/* --------------- SCRIBE Label Format --------------------- */enum _ScribeLab {   S_LBB, S_LBA, S_UTS, S_EOF};typedef enum _ScribeLab ScribeLab;static char *scribeMap[] = {"LBB:", "LBA:", "UTS:"};/* GetScribeLab: get next scribe label in input */static ScribeLab GetScribeLab(Source *src){   char *s;   int i;      do {      do {         GetTrSym(src,FALSE);         if (trSym == TREOF) return S_EOF;      } while (trSym != TRSTR);      i = 0;      do {         s=scribeMap[i];          if (strcmp(trStr,s) == 0)             return (ScribeLab) i;         i++;      } while (i < S_EOF);   } while(TRUE);   return ((ScribeLab) 0);}/* LoadSCRIBELabels: load a SCRIBE (SAM) label file - searches for         first occurrence of a label symbol                LBA - acoustic label               LBB - broad class label               UTS - utterance          it loads this symbol and all subsequent labels of the         same type.  All other SAM label types are ignored */static void LoadSCRIBELabels(MemHeap *x, Transcription *t, Source *src){   LabList *ll;   LabId labid;   HTime start,end;   float score;   ScribeLab ltype, lx;   double sp;   char buf[256];      if (!GetConfFlt(cParm,numParm,"SOURCERATE",&sp))        sp = 500.0;   /* actual SCRIBE rate */   ll = CreateLabelList(x,0);  AddLabelList(ll,t);   InitTrScan();   do {  /* search for first label */      ltype = GetScribeLab(src);      if (ltype == S_EOF)         HError(6554,"LoadSCRIBELabels: Unexpected EOF");   } while (ltype != S_LBB && ltype != S_LBA && ltype != S_UTS);   do { /* load this and all subsequent ltype labels */      GetTrSym(src,FALSE);      if (trSym != TRNUM)         HError(6554,"LoadSCRIBELabels: Start Index expected [%d]\n",trSym);      start = trNum * sp;      GetTrSym(src,FALSE);      if (trSym != TRCOMMA)         HError(6554,"LoadSCRIBELabels: Comma expected [%d]\n",trSym);      GetTrSym(src,FALSE);      if (ltype == S_LBA || ltype == S_LBB) {   /* LBB and LBA have a centre field */         if (trSym != TRCOMMA)            HError(6554,"LoadSCRIBELabels: Comma expected [%d]\n",trSym);              GetTrSym(src,FALSE);      }      if (trSym != TRNUM)         HError(6554,"LoadSCRIBELabels: End Index expected [%d]\n",trSym);      end = trNum * sp;      GetTrSym(src,FALSE);      if (trSym != TRCOMMA)         HError(6554,"LoadSCRIBELabels: Comma expected [%d]\n",trSym);      GetTrSym(src,FALSE);      if (trSym != TRSTR)         HError(6554,"LoadSCRIBELabels: Label expected [%d]\n",trSym);      strcpy(buf,trStr);      GetTrSym(src,FALSE);      while (trSym == TRSTR){         strcat(buf,"_"); strcat(buf,trStr);         GetTrSym(src,FALSE);      }      labid = GetLabId(buf,TRUE);       score = 0.0;      AddLabel(x,ll,labid,start,end,score);       if (trSym != TREOL)         HError(6554,"LoadSCRIBELabels: End of Line expected [%d]\n",trSym);      lx = GetScribeLab(src);   } while (lx != S_EOF);}/* ----------------- TriPhone Stripping ------------------- *//* EXPORT->TriStrip: Remove contexts of form A- and +B from s */void TriStrip(char *s){   char buf[100],*p;      if ((p = strchr(s,'-')) == NULL) p = s; else ++p;   strcpy(buf,p);   if ((p = strrchr(buf,'+')) != NULL)       *p = '\0';   strcpy(s,buf);}/* EXPORT->LTriStrip: enable triphone stripping */void LTriStrip(Boolean enab){   stripTriPhones = enab;}/* ------------------ Master Label File Handling -------------------- *//* StoreMLFEntry: store the given MLF entry */static void StoreMLFEntry(MLFEntry *e){   e->next = NULL;   if (mlfHead == NULL)      mlfHead = mlfTail = e;   else {      mlfTail->next = e; mlfTail = e;   }   ++mlfUsed;}/* FindMLFStr: find the next quoted string in s */static Boolean FindMLFStr(char *s, char **st, char **en){   char *p,*q;      if (s==NULL || *s == '\0') return FALSE;   p = strchr(s,'"');//查找字符串s中首次出现字符""的位置   if (p==NULL || *(p+1)=='\0') return FALSE;   q = strchr(p+1,'"');   if (q==NULL) return FALSE;   *st = p; *en = q;   return TRUE;}/* FindMLFType: find a -> or => symbol in s if any */static MLFDefType FindMLFType(char *s, char **en){   char *p;      p=strchr(s+1,'>');   if (p!=NULL) {      *en = p;      if (*(p-1) == '-') return MLF_SIMPLE;      if (*(p-1) == '=') return MLF_FULL;   }   return MLF_IMMEDIATE;}/* NoMLFHeader: return true if s doesnt contain #!MLF!# */static Boolean NoMLFHeader(char *s){   int len;   char *e;      len = strlen(s);   while (isspace((int) *s) && len>7) {      --len; ++s;   }   e = s+len-1;   while (isspace((int) *e) && len>7) {      --len; --e;   }   if (len != 7) return TRUE;   *(e+1) = '\0';   return (strcmp(s,"#!MLF!#") != 0);}static Boolean incSpaces;/* IsDotLine: return true if line contains only a single dot */static Boolean IsDotLine(char *s){   int len;   char *e;   Boolean cut;   len = strlen(s);cut=FALSE;   if (s[len-1]=='\n') {      len--; s[len]=0;      if ((len>0) && (s[len-1]=='\r')) {         len--; s[len]=0;      }   }   if (compatMode) {      while (isspace((int) *s) && len>0) {         cut=TRUE;         --len; ++s;      }      e = s+len-1;      if (*e=='\n' && len>0) --len,--e;      while (isspace((int) *e) && len>0) {         cut=TRUE;         --len; --e;      }   }   if ((*s == '.') && (len == 1)) {      if (cut) incSpaces=TRUE;      return(TRUE);   }   if (compatMode && cut && len==strlen_LEVELSEP &&        strncmp(s,LEVELSEP,strlen_LEVELSEP)==0)      incSpaces=TRUE;   return(FALSE);}/* ClassifyMLFPattern: classify given pattern string */MLFPatType ClassifyMLFPattern(char *s){   char *t;      if (strchr(s,'?') != NULL) return PAT_GENERAL;   if (strchr(s,'*') == NULL) return PAT_FIXED;   if (strlen(s)<=2) return PAT_GENERAL;   if (s[0]!='*' || s[1]!=PATHCHAR) return PAT_GENERAL;   t = s+2;   if (strchr(t,'*') == NULL ) return PAT_ANYPATH;   return PAT_GENERAL;}/* MLFHash: hash the given string */static unsigned MLFHash(char *s){   unsigned hashval;   for (hashval=0; *s != '\0'; s++)      hashval = *s + 31*hashval;   return hashval;}/* EXPORT->LoadMasterFile: Load the Master Label File stored in fname                            and append the entries to the MLF table */void LoadMasterFile(char *fname){   char buf[1024];   char *men;        /* end of mode indicator */   char *pst,*pen;   /* start/end of pattern (inc quotes) */   char *dst,*den;   /* start/end of subdirectory (inc quotes) */   Boolean inEntry = FALSE;   /* ignore ".." within an entry */   MLFEntry *e;   FILE *f;      if (numMLFs == MAXMLFS)      HError(6520,"LoadMasterFile: MLF file limit reached [%d]",MAXMLFS);   if ((f = fopen(fname,"rb")) == NULL)      HError(6510,"LoadMasterFile: cannot open MLF %s",fname);   if (fgets(buf,1024,f) == NULL)      HError(6513,"LoadMasterFile: MLF file is empty");   if (NoMLFHeader(buf))

⌨️ 快捷键说明

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