📄 hlrescore.c
字号:
case 'p': if (NextArg() != FLOATARG) HError (4019, "HLRescore: word insertion penalty expected"); wordPen = GetChkedFlt (-1000.0, 1000.0, s); break; case 's': if (NextArg() != FLOATARG) HError (4019, "HLRescore: grammar scale factor expected"); lmScale = GetChkedFlt (0.0, 1000.0, s); break; case 'a': if (NextArg() != FLOATARG) HError (4019, "HLRescore: acoustic scale factor expected"); acScale = GetChkedFlt (0.0, 1000.0, s); break; case 'r': if (NextArg() != FLOATARG) HError (4019, "HLRescore: pronunciation scale factor expected"); prScale = GetChkedFlt (0.0, 1000.0, s); break; case 'd': fixPronprobs = TRUE; break; case 't': if (NextArg() != FLOATARG) HError (4019, "HLRescore: lattice pruning threshold expected"); pruneInThresh = GetChkedFlt (0.0, 10000.0, s); pruneInLat = TRUE; if (NextArg() == FLOATARG) pruneInArcsPerSec = GetChkedFlt (0.0, 150000.0, s); break; case 'u': if (NextArg() != FLOATARG) HError (4019, "HLRescore: lattice pruning threshold expected"); pruneOutThresh = GetChkedFlt (0.0, 10000.0, s); pruneOutLat = TRUE; if (NextArg() == FLOATARG) pruneOutArcsPerSec = GetChkedFlt (0.0, 150000.0, s); break; case 'n': if (NextArg() != STRINGARG) HError (4019, "HLRescore: language model file name expected"); lmFile = GetStrArg(); expandLat = TRUE; break; case 'f': findBest = TRUE; break; case 'w': writeLat = TRUE; break; case 'c': calcStats = TRUE; break; case 'T': trace = GetChkedInt(0, 100, s); break; default: HError (4019, "HLRescore: Unknown switch %s",s); } } if (!writeLat && !findBest && !calcStats) HError (4019, "HLRescore: No operation specified. What do you want me to do?"); /* init Heaps */ CreateHeap (&latHeap, "Lattice heap", MSTAK, 1, 0, 8000, 80000); CreateHeap (&lmHeap, "LM heap", MSTAK, 1, 1.0, 10000, 100000); CreateHeap (&transHeap, "Transcription heap",MSTAK, 1, 0, 8000, 80000); if (NextArg() != STRINGARG) HError(4019, "Vocab file name expected"); dictfn = GetStrArg(); /* Read dictionary */ if (trace & T_TOP) printf ("Reading dictionary from %s\n", dictfn); InitVocab (&vocab); if (ReadDict (dictfn, &vocab)<SUCCESS) HError(4013, "HLRescore: ReadDict failed"); /* language model */ if (lmFile) { if (trace & T_TOP) printf ("Reading LM from %s\n", lmFile); lm = ReadLModel (&lmHeap, lmFile); } LatSetBoundaryWords (startWord, endWord, startLMWord, endLMWord); while (NumArgs() > 0) { if (NextArg() != STRINGARG) HError (4019, "HLRescore: Transcription file name expected"); latfn = GetStrArg(); if (trace & T_TOP) printf ("File: %s\n", latfn); fflush(stdout); ProcessLattice (latfn); } if (trace & T_MEM) { printf("Memory State on Completion\n"); PrintAllHeapStats(); } Exit (0); return(0); }/* ProcessLattice apply all the requested operations on lattice*/void ProcessLattice (char *latfn){ Lattice *lat; char lfn[MAXSTRLEN]; FILE *lf; Boolean isPipe; MakeFN (latfn, latInDir, latInExt, lfn); if ((lf = FOpen(lfn,NetFilter,&isPipe)) == NULL) HError(4010,"HLRescore: Cannot open Lattice file %s", lfn); lat = ReadLattice (lf, &latHeap, &vocab, FALSE, FALSE); FClose(lf, isPipe); if (!lat) HError (4013, "HLRescore: can't read lattice"); if (fixBadLats) FixBadLat (lat); if (fixPronprobs) FixPronProbs (lat, &vocab); if (trace & T_LAT) printf ("lattice size: %d nodes/ %d arcs\n", lat->nn, lat->na); lat->lmscale = lmScale; lat->wdpenalty = wordPen; lat->acscale = acScale; lat->prscale = prScale; /* prune original lattice */ if (pruneInLat) { lat = LatPrune (&latHeap, lat, pruneInThresh, pruneInArcsPerSec); } /* expand lattice with new LM */ if (expandLat) {#ifndef NO_LAT_LM lat = LatExpand (&latHeap, lat, lm);#else HError (4090, "LatExpand not supported. Recompile without NO_LAT_LM");#endif } /* find 1-best Transcription */ if (findBest) { Transcription *trans; trans = LatFindBest (&transHeap, lat, 1); if (trace & T_TRAN) PrintTranscription (trans, "1-best path"); /* write transcription */ if (labOutForm) FormatTranscription (trans, 1.0e7, FALSE, FALSE, strchr(labOutForm,'X')!=NULL, strchr(labOutForm,'N')!=NULL,strchr(labOutForm,'S')!=NULL, strchr(labOutForm,'C')!=NULL,strchr(labOutForm,'T')!=NULL, strchr(labOutForm,'W')!=NULL,strchr(labOutForm,'M')!=NULL); MakeFN (latfn, labOutDir, labOutExt, lfn); if (LSave (lfn, trans, ofmt) < SUCCESS) HError (4014, "ProcessLattice: Cannot save file %s", lfn); ResetHeap (&transHeap); } /* prune generated lattice */ if (pruneOutLat) { lat = LatPrune (&latHeap, lat, pruneOutThresh, pruneOutArcsPerSec); } /* calc lattice stats */ if (calcStats) { CalcStats (lat); } /* write lattice */ if (writeLat) { LatFormat form; int i; LNode *ln; if (sortLattice) LatSetScores (lat); else for(i=0, ln=lat->lnodes; i<lat->nn; i++, ln++) ln->score=0.0; MakeFN (latfn, labOutDir, latInExt, lfn); lf = FOpen (lfn, NetOFilter, &isPipe); if (!lf) HError (4014, "ProcessLattice: Could not open file '%s' for lattice output", lfn); if (!latOutForm) form = HLAT_DEFAULT|HLAT_PRLIKE; else { char *p; for (p = latOutForm, 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, lf, form) < SUCCESS) HError(4014, "ProcessLattice: WriteLattice failed"); FClose (lf, isPipe); } if (trace & T_MEM) { printf("Memory State after processing lattice\n"); PrintAllHeapStats(); } ResetHeap (&latHeap);}/* CC-mode style info for emacs Local Variables: c-file-style: "htk" End:*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -