?? hlabel.c
字號:
printf("\n");}/* PrintList: print the given label list */static void PrintList(LabList *ll){ int i; LLink p; for (p=ll->head->succ,i=1; p->succ!= NULL; p=p->succ,i++) { printf("%4d. ",i); PrintLabel(p,ll->maxAuxLab); }}/* EXPORT->PrintTranscription: for diagnostics */void PrintTranscription(Transcription *t, char *title){ int i; LabList *ll; printf("Transcription: %s [%d lists]\n",title,t->numLists); ll = t->head; for (i=1; i<=t->numLists; i++) { printf(" List %d\n",i); PrintList(ll); ll = ll->next; }}/* FilterLevel: remove all but given level from transcription */static void FilterLevel(Transcription *t, int lev){ LabList *ll; LLink p; for (ll = t->head; ll != NULL; ll = ll->next) { if (ll->maxAuxLab < lev) HError(6570,"FilterLevel: level %d > max[%d]",lev,ll->maxAuxLab); if (lev > 0) { for (p=ll->head->succ; p->succ!=NULL; p=p->succ) { if (p->auxLab[lev] != NULL) { p->labid = p->auxLab[lev]; p->score = p->auxScore[lev]; p->end = AuxLabEndTime(p,lev); } else DeleteLabel(p); } } ll->maxAuxLab = 0; }}/* --------------- Format Specific Label File Input Routines --------------- */#define LEVELSEP "///"#define strlen_LEVELSEP 3#define COMMCHAR ';'#define LFEED '\012'#define CRETURN '\015'enum _TrSymbol{TRNULL,TRNUM,TRSTR,TREOL,TRLEV,TRCOMMA,TREOF};typedef enum _TrSymbol TrSymbol;static int curch = ' ';static TrSymbol trSym = TRNULL;static double trNum;static char trStr[256];/* IsNumeric: returns true if given string is a number */Boolean IsNumeric(char *s){ int i,len; #ifdef WIN32 if(*s < 0) return FALSE;#endif len = strlen(s)-1; if (!(isdigit(s[0])||s[0]=='+'||s[0]=='-')) return FALSE; if (!(isdigit(s[len]))) return FALSE; for (i=1; i<len; i++) if (!(isdigit(s[i]) || s[i]=='.' || s[i]=='-' || s[i]=='+' || s[i]=='e' || s[i]=='E' )) return FALSE; return TRUE;}/* InitTrScan: initialise the scanner */static void InitTrScan(void){ curch = ' '; trSym = TRNULL;}/* GetTrSym: get next symbol from f, remember that f might be an MLF in which case EOF is a period on its own line */static void GetTrSym(Source *src, Boolean htk){ int nxtch; Boolean trSOL; trNum = 0.0; trStr[0]='\0'; if (trSym==TRNULL) curch = GetCh(src); if (trSym==TREOL || trSym==TRNULL) trSOL=TRUE; else trSOL=FALSE; while (curch == ' ' || curch == '\t') { trSOL=FALSE; curch = GetCh(src); } if (!htk && curch == COMMCHAR) SkipLine(src); switch (curch) { case EOF: trSym = TREOF; break; case LFEED: curch = GetCh(src); trSym = TREOL; break; case CRETURN: curch = GetCh(src); if (curch == LFEED) curch = GetCh(src); trSym = TREOL; break; case ',': if (!htk) { curch = GetCh(src); trSym = TRCOMMA; break; } case '.': if (curch=='.' && trSOL==TRUE && mlfUsed>0 && htk) { nxtch = GetCh(src); if (nxtch == LFEED || nxtch == CRETURN) { trSym = TREOF; break; } UnGetCh(nxtch,src); /* Requires more than one character pushback */ } default: if (htk) { UnGetCh(curch,src); if (!ReadString(src,trStr)) { trSym=TREOF; break; } curch=GetCh(src); if (trSOL && strcmp(LEVELSEP,trStr)==0) { if (curch == LFEED || curch == CRETURN) { trSym = TRLEV; break; } } } else { nxtch=0; do { if (nxtch>=255) break; trStr[nxtch++]=curch; curch=GetCh(src); } while (!isspace(curch) && curch != ',' && curch != EOF); trStr[nxtch]='\0'; src->wasQuoted=FALSE; } if (!src->wasQuoted && IsNumeric(trStr)){ sscanf(trStr,"%lf",&trNum); trSym = TRNUM; break; } if (htk && compatMode && (strcmp(LEVELSEP,trStr)==0 || strcmp(".",trStr)==0)) { src->wasNewline=FALSE; SkipWhiteSpace(src); if (src->wasNewline) { curch = CRETURN; trSym=(strcmp(LEVELSEP,trStr)==0?TRLEV:TREOF); break; } curch = GetCh(src); } if (stripTriPhones) TriStrip(trStr); trSym = TRSTR; break; }}/* -------------------- HTK Label Format ------------------ *//* ExtendAux: extend the aux arrays in given lab list to n elems New elems are set to NULL/0.0 */static void ExtendAux(MemHeap *x, LabList *ll, int n){ int i,oldn; LabId *id; float *s; LLink p; if (n>=99) HError(6570, "ExtendAux: Too many auxiliary fields in label file"); oldn = ll->maxAuxLab; ll->maxAuxLab = n; for (p=ll->head->succ; p->succ!=NULL; p=p->succ){ id = (LabId *)New(x,sizeof(LabId)*n) - 1; s = (float *)New(x,sizeof(float)*n) - 1; for (i=1; i<=oldn; i++){ id[i] = p->auxLab[i]; s[i] = p->auxScore[i]; } for (i=oldn+1; i<=n; i++){ id[i] = NULL; s[i] = 0.0; } p->auxLab = id; p->auxScore = s; } if (trace&T_HTKL) printf("HLabel: aux extended from %d to %d\n",oldn,n);}/* LoadHTKList: load a single HTK label list - dont create anything if transAlt>0 and alt != transAlt */static LabList * LoadHTKList(MemHeap *x, Source *src, int alt){ LabList *ll = NULL; LabId labid, auxLab[100]; LLink p; HTime start,end; float score, auxScore[100]; int n,maxAux = 0; Boolean ok; ok = (transAlt==0) || (transAlt == alt); if (ok) ll = CreateLabelList(x,maxAux); /* assume no aux labels */ if (trace&T_HTKL) printf("HLabel: looking for lab list\n"); while (trSym==TRNUM || trSym==TRSTR){ start = -1; end = -1; score = 0.0; if (trSym==TRNUM) { start = trNum; GetTrSym(src,TRUE); if (trSym==TRNUM) { end = trNum; GetTrSym(src,TRUE); } } if (trSym != TRSTR) HError(6550,"LoadHTKList: Label Name Expected"); labid = GetLabId(trStr,TRUE); GetTrSym(src,TRUE); if (trSym==TRNUM){ score = trNum; GetTrSym(src,TRUE); } if (trace&T_HTKL) printf("HLabel: adding %.0f %.0f %s %f\n",start,end,labid->name,score); if (ok) p = AddLabel(x,ll,labid,start,end,score); /* Any aux labels ? */ n = 0; while (trSym != TREOL && trSym!=TREOF) { 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) { /* 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;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -