main_decode_anytopo.c
来自「CMU大名鼎鼎的SPHINX-3大词汇量连续语音识别系统」· C语言 代码 · 共 1,466 行 · 第 1/4 页
C
1,466 行
{ "-bestpath", ARG_INT32, "0", "Whether to run bestpath DAG search after forward Viterbi pass" }, { "-min_endfr", ARG_INT32, "3", "Nodes ignored during search if they persist for fewer than so many end frames" }, { "-dagfudge", ARG_INT32, "2", "(0..2); 1 or 2: add edge if endframe == startframe; 2: if start == end-1" }, { "-bestpathlw", ARG_FLOAT32, NULL, "Language weight for bestpath DAG search (default: same as -lw)" }, { "-inspen", ARG_FLOAT32, "0.65", "Word insertion penalty" }, { "-silpen", ARG_FLOAT32, "0.1", "Language model 'probability' of silence word" }, { "-noisepen", ARG_FLOAT32, "0.05", "Language model 'probability' of each non-silence filler word" }, { "-fillpen", ARG_STRING, NULL, "Filler word probabilities input file (used in place of -silpen and -noisepen)" }, { "-ctl", ARG_STRING, NULL, "Input control file listing utterances to be decoded" }, { "-ctloffset", ARG_INT32, "0", "No. of utterances at the beginning of -ctl file to be skipped" }, { "-ctlcount", ARG_INT32, NULL, "No. of utterances in -ctl file to be processed (after -ctloffset). Default: Until EOF" }, { "-cepdir", ARG_STRING, ".", "Directory for utterances in -ctl file (if relative paths specified)." }, { "-cepext", ARG_STRING, ".mfc", "File extension appended to utterances listed in -ctl file" }, { "-mllrctl", ARG_STRING, NULL, "Input control file listing MLLR input data; parallel to -ctl argument file" }, { "-topn", ARG_INT32, "4", "No. of top scoring densities computed in each mixture gaussian codebook" }, { "-beam", ARG_FLOAT64, "1e-64", "Main pruning beam applied to triphones in forward search" }, { "-nwbeam", ARG_FLOAT64, "1e-27", "Pruning beam applied in forward search upon word exit" }, { "-phonepen", ARG_FLOAT32, "1.0", "Penalty applied for each phone transition" }, { "-tracewhmm", ARG_STRING, NULL, "Word whose active HMMs are to be traced (for debugging/diagnosis/analysis)" }, { "-hmmdumpsf", ARG_INT32, NULL, "Starting frame for dumping all active HMMs (for debugging/diagnosis/analysis)" }, { "-worddumpsf", ARG_INT32, NULL, "Starting frame for dumping all active words (for debugging/diagnosis/analysis)" }, { "-inlatdir", ARG_STRING, NULL, "Input word-lattice directory with per-utt files for restricting words searched" }, { "-inlatwin", ARG_INT32, "50", "Input word-lattice words starting within +/- <this argument> of current frame considered during search" }, { "-outlatdir", ARG_STRING, NULL, "Directory for writing word lattices (one file/utterance); optional ,NODES suffix to write only the nodes" }, { "-latext", ARG_STRING, "lat.gz", "Word-lattice filename extension (.gz or .Z extension for compression)" }, { "-bestscoredir", ARG_STRING, NULL, "Directory for writing best score/frame (used to set beamwidth; one file/utterance)" }, { "-hyp", ARG_STRING, NULL, "Recognition result output file (pre-1995 NIST format) (optional ,EXACT suffix)" }, { "-hypseg", ARG_STRING, NULL, "Exact recognition result file with word segmentations and scores" }, { "-logfn", ARG_STRING, NULL, "Log file (default stdout/stderr)" }, { "-backtrace", ARG_INT32, "1", "Whether detailed backtrace information (word segmentation/scores) shown in log" }, { "-bptblsize", ARG_INT32, "32767", "Number of BPtable entries to allocate initially (grown as necessary)" }, { "-bptbldump", ARG_INT32, "0", "Whether BPTable should be dumped to log output (for debugging)" }, { NULL, ARG_INT32, NULL, NULL }};/* * Load and cross-check all models (acoustic/lexical/linguistic). */static void models_init ( void ){ float32 varfloor, mixwfloor, tpfloor; int32 i; char *arg; /* HMM model definition */ mdef = mdef_init ((char *) cmd_ln_access("-mdef")); /* Dictionary */ dict = dict_init (mdef, (char *) cmd_ln_access("-dict"), (char *) cmd_ln_access("-fdict"), 0); /* HACK!! Make sure SILENCE_WORD, START_WORD and FINISH_WORD are in dictionary */ silwid = dict_wordid (dict, S3_SILENCE_WORD); startwid = dict_wordid (dict,S3_START_WORD); finishwid = dict_wordid (dict, S3_FINISH_WORD); if (NOT_S3WID(silwid) || NOT_S3WID(startwid) || NOT_S3WID(finishwid)) { E_FATAL("%s, %s, or %s missing from dictionary\n", S3_SILENCE_WORD, S3_START_WORD, S3_FINISH_WORD); } if ((dict->filler_start > dict->filler_end) || (! dict_filler_word (dict,silwid))) E_FATAL("%s must occur (only) in filler dictionary\n", S3_SILENCE_WORD); /* No check that alternative pronunciations for filler words are in filler range!! */ /* Codebooks */ varfloor = *((float32 *) cmd_ln_access("-varfloor")); g = gauden_init ((char *) cmd_ln_access("-mean"), (char *) cmd_ln_access("-var"), varfloor); /* Verify codebook feature dimensions against libfeat */ if (feat_n_stream(fcb) != g->n_feat) { E_FATAL("#feature mismatch: feat= %d, mean/var= %d\n", feat_n_stream(fcb), g->n_feat); } for (i = 0; i < feat_n_stream(fcb); i++) { if (feat_stream_len(fcb,i) != g->featlen[i]) { E_FATAL("featlen[%d] mismatch: feat= %d, mean/var= %d\n", i, feat_stream_len(fcb, i), g->featlen[i]); } } /* Senone mixture weights */ mixwfloor = *((float32 *) cmd_ln_access("-mwfloor")); sen = senone_init ((char *) cmd_ln_access("-mixw"), (char *) cmd_ln_access("-senmgau"), mixwfloor); /* Verify senone parameters against gauden parameters */ if (sen->n_feat != g->n_feat) E_FATAL("#Feature mismatch: gauden= %d, senone= %d\n", g->n_feat, sen->n_feat); if (sen->n_cw != g->n_density) E_FATAL("#Densities mismatch: gauden= %d, senone= %d\n", g->n_density, sen->n_cw); if (sen->n_gauden > g->n_mgau) E_FATAL("Senones need more codebooks (%d) than present (%d)\n", sen->n_gauden, g->n_mgau); if (sen->n_gauden < g->n_mgau) E_ERROR("Senones use fewer codebooks (%d) than present (%d)\n", sen->n_gauden, g->n_mgau); /* Verify senone parameters against model definition parameters */ if (mdef->n_sen != sen->n_sen) E_FATAL("Model definition has %d senones; but #senone= %d\n", mdef->n_sen, sen->n_sen); /* CD/CI senone interpolation weights file, if present */ if ((arg = (char *) cmd_ln_access ("-lambda")) != NULL) { interp = interp_init (arg); /* Verify interpolation weights size with senones */ if (interp->n_sen != sen->n_sen) E_FATAL("Interpolation file has %d weights; but #senone= %d\n", interp->n_sen, sen->n_sen); } else interp = NULL; /* Transition matrices */ tpfloor = *((float32 *) cmd_ln_access("-tpfloor")); tmat = tmat_init ((char *) cmd_ln_access("-tmat"), tpfloor); /* Verify transition matrices parameters against model definition parameters */ if (mdef->n_tmat != tmat->n_tmat) E_FATAL("Model definition has %d tmat; but #tmat= %d\n", mdef->n_tmat, tmat->n_tmat); if (mdef->n_emit_state != tmat->n_state) E_FATAL("#Emitting states in model definition = %d, #states in tmat = %d\n", mdef->n_emit_state, tmat->n_state); /* LM */ { char *lmfile; lmfile = (char *) cmd_ln_access("-lm"); if (! lmfile) E_FATAL("-lm argument missing\n"); lm = lm_read (lmfile, *(float32 *)cmd_ln_access("-lw"), *(float32 *)cmd_ln_access("-inspen"), *(float32 *)cmd_ln_access("-ugwt")); /* Filler penalties */ fpen = fillpen_init (dict, (char *) cmd_ln_access("-fillpen"), *(float32 *)cmd_ln_access("-silpen"), *(float32 *)cmd_ln_access("-noisepen"), *(float32 *)cmd_ln_access("-lw"), *(float32 *)cmd_ln_access("-inspen")); } dict2lmwid = wid_dict_lm_map(dict, lm, *(float32*) cmd_ln_access("-lw"));}/* * Write exact hypothesis. Format * <id> S <scl> T <scr> A <ascr> L <lscr> {<sf> <wascr> <wlscr> <word>}... <ef> * where: * scl = acoustic score scaling for entire utterance * scr = ascr + (lscr*lw+N*wip), where N = #words excluding <s> * ascr = scaled acoustic score for entire utterance * lscr = LM score (without lw or wip) for entire utterance * sf = start frame for word * wascr = scaled acoustic score for word * wlscr = LM score (without lw or wip) for word * ef = end frame for utterance. */static void log_hypseg (char *uttid, FILE *fp, /* Out: output file */ srch_hyp_t *hypptr, /* In: Hypothesis */ int32 nfrm, /* In: #frames in utterance */ int32 scl, /* In: Acoustic scaling for entire utt */ float64 lwf) /* In: LM score scale-factor (in dagsearch) */{ srch_hyp_t *h; int32 ascr, lscr, tscr; ascr = lscr = tscr = 0; for (h = hypptr; h; h = h->next) { ascr += h->ascr; if (dict_basewid(dict,h->wid) != startwid) { lscr += lm_rawscore (lm,h->lscr, lwf); } else { assert (h->lscr == 0); } tscr += h->ascr + h->lscr; } fprintf (fp, "%s S %d T %d A %d L %d", uttid, scl, tscr, ascr, lscr); if (! hypptr) /* HACK!! */ fprintf (fp, " (null)\n"); else { for (h = hypptr; h; h = h->next) { lscr = (dict_basewid(dict,h->wid) != startwid) ? lm_rawscore (lm,h->lscr, lwf) : 0; fprintf (fp, " %d %d %d %s", h->sf, h->ascr, lscr, dict_wordstr (dict,h->wid)); } fprintf (fp, " %d\n", nfrm); } fflush (fp);}/* Write hypothesis in old (pre-Nov95) NIST format */static void log_hypstr (FILE *fp, srch_hyp_t *hypptr, char *uttid, int32 exact, int32 scr){ srch_hyp_t *h; s3wid_t w; if (! hypptr) /* HACK!! */ fprintf (fp, "(null)"); for (h = hypptr; h; h = h->next) { w = h->wid; if (! exact) { w = dict_basewid (dict,w); if ((w != startwid) && (w != finishwid) && (! dict_filler_word (dict,w))) fprintf (fp, "%s ", dict_wordstr(dict,w)); } else fprintf (fp, "%s ", dict_wordstr(dict,w)); } if (scr != 0) fprintf (fp, " (%s %d)\n", uttid, scr); else fprintf (fp, " (%s)\n", uttid); fflush (fp);}/* Log hypothesis in detail with word segmentations, acoustic and LM scores */static void log_hyp_detailed (FILE *fp, srch_hyp_t *hypptr, char *uttid, char *LBL, char *lbl){ srch_hyp_t *h; int32 f, scale, ascr, lscr; ascr = 0; lscr = 0; fprintf (fp, "%s:%s> %20s %5s %5s %11s %10s\n", LBL, uttid, "WORD", "SFrm", "EFrm", "AScr", "LMScore"); for (h = hypptr; h; h = h->next) { scale = 0; for (f = h->sf; f <= h->ef; f++) scale += senscale[f]; fprintf (fp, "%s:%s> %20s %5d %5d %11d %10d\n", lbl, uttid, h->word, h->sf, h->ef, h->ascr + scale, h->lscr); ascr += h->ascr + scale; lscr += h->lscr; } fprintf (fp, "%s:%s> %20s %5s %5s %11d %10d\n", LBL, uttid, "TOTAL", "", "", ascr, lscr);}static void write_bestscore (char *dir, char *uttid, int32 *score, int32 nfr)
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?