search_bestfirst_main.c
来自「julius version 4.12.about sound recognit」· C语言 代码 · 共 2,134 行 · 第 1/5 页
C
2,134 行
* @param framenum [in] 掐蜗フレ〖ム墓 * </JA> * <EN> * Update the score envelope using forward score of the given hypothesis. * * @param s [i/o] work area for 2nd pass * @param n [in] hypothesis * @param framenum [in] input frame length * </EN> */static voidenvl_update(StackDecode *s, NODE *n, int framenum){ int t; for(t=framenum-1;t>=0;t--) { if (s->framemaxscore[t] < n->g[t]) s->framemaxscore[t] = n->g[t]; }}#endif /* SCAN_BEAM *//**********************************************************************//********** Short pause segmentation **********************************//**********************************************************************//** * <JA> * 千急冯蔡から·肌の掐蜗惰粗の千急を倡幌する狠の介袋帽胳旺悟をセットする. * 譬册胳および簿棱の脚剩を雇胃して介袋帽胳旺悟が疯年される. * * @param hypo [in] 附哼の掐蜗惰粗の千急冯蔡としての矢铬输 * @param r [in] 千急借妄インスタンス * </JA> * <EN> * Set the previous word context for the recognition of the next input * segment from the current recognition result. The initial context word * will be chosen from the current recognition result skipping transparent * word and multiplied words. * * @param hypo [in] sentence candidate as a recognition result of current * input segment * @param r [in] recognition process instance * </EN> * * @callgraph * @callergraph * */voidsegment_set_last_nword(NODE *hypo, RecogProcess *r){ int i; WORD_ID w; if (r->sp_break_last_nword_allow_override) { for(i=0;i<hypo->seqnum;i++) { w = hypo->seq[i]; if (w != r->sp_break_last_word && !is_sil(w, r) && !r->lm->winfo->is_transparent[w] ) { r->sp_break_last_nword = w; break; } }#ifdef SP_BREAK_DEBUG printf("sp_break_last_nword=%d[%s]\n", r->sp_break_last_nword, r->lm->winfo->woutput[r->sp_break_last_nword]);#endif } else { r->sp_break_last_nword = WORD_INVALID; }}/**********************************************************************//********* Debug output of hypothesis while search ********************//**********************************************************************//** * <JA> * デバッグ脱に簿棱の帽胳误を山绩する. * * @param hypo [in] 簿棱 * @param winfo [in] 帽胳辑今 * </JA> * <EN> * Output word sequence of a hypothesis for debug. * * @param hypo [in] hypothesis * @param winfo [in] word dictionary * </EN> */static voidput_hypo_woutput(NODE *hypo, WORD_INFO *winfo){ int i,w; if (hypo != NULL) { for (i=hypo->seqnum-1;i>=0;i--) { w = hypo->seq[i]; jlog(" %s", winfo->woutput[w]); } } jlog("\n"); }/** * <JA> * デバッグ脱に簿棱の帽胳N-gramエントリ叹∈Julianではカテゴリ戎规∷を叫蜗する. * * @param hypo [in] 簿棱 * @param winfo [in] 帽胳辑今 * </JA> * <EN> * Output N-gram entries (or DFA category IDs) of a hypothesis for debug. * * @param hypo [in] hypothesis * @param winfo [in] word dictionary * </EN> */static voidput_hypo_wname(NODE *hypo, WORD_INFO *winfo){ int i,w; if (hypo != NULL) { for (i=hypo->seqnum-1;i>=0;i--) { w = hypo->seq[i]; jlog(" %s", winfo->wname[w]); } } jlog("\n"); }/** * <EN> * Save a hypothesis as a recognition result f 2nd pass. * </EN> * <JA> * 妈2パスの冯蔡として簿棱を瘦赂する. * </JA> * * @param hypo [in] hypothesis to save * @param r [in] recognition process instance * */static voidstore_result_pass2(NODE *hypo, RecogProcess *r){ int i; Sentence *s; s = &(r->result.sent[r->result.sentnum]); s->word_num = hypo->seqnum; for (i = 0; i < hypo->seqnum; i++) { s->word[i] = hypo->seq[hypo->seqnum - 1 - i]; }#ifdef CONFIDENCE_MEASURE for (i = 0; i < hypo->seqnum; i++) { s->confidence[i] = hypo->cmscore[hypo->seqnum - 1 - i]; }#endif s->score = hypo->score; s->score_lm = hypo->totallscore; s->score_am = hypo->score - hypo->totallscore; if (r->lmtype == LM_DFA) { /* output which grammar the hypothesis belongs to on multiple grammar */ /* determine only by the last word */ if (multigram_get_all_num(r->lm) > 0) { s->gram_id = multigram_get_gram_from_category(r->lm->winfo->wton[hypo->seq[0]], r->lm); } else { s->gram_id = 0; } } r->result.sentnum++; /* add to tail */}/**********************************************************************//******** Output top 'ncan' hypotheses in a stack and free all ********//**********************************************************************//** * <JA> * スタックから惧疤の簿棱を艰り叫し·千急冯蔡として叫蜗する. さらに· * スタックに呈羌されている链ての簿棱を豺庶する. * * 评られた矢铬输は·いったん冯蔡呈羌脱のスタックに呈羌される. 玫瑚姜 * 位∈"-n" の眶だけ矢铬输が斧つかるか·玫瑚が面们される∷の稿·冯蔡弄 * に评られた矢铬输の面から惧疤N改∈"-output" で回年された眶∷の簿棱を * 叫蜗する. * * 回年があればアラインメントもここで悸乖する. * * @param r_start [i/o] 冯蔡呈羌脱スタックの黎片ノ〖ドへのポインタ * @param r_bottom [i/o] 冯蔡呈羌脱スタックの撵ノ〖ドへのポインタ * @param r_stacknum [i/o] スタックに呈羌されているノ〖ド眶へのポインタ * @param ncan [in] 叫蜗する惧疤簿棱眶 * @param r [in] 千急借妄インスタンス * @param param [in] 掐蜗パラメ〖タ * </JA> * <EN> * Output top N-best hypotheses in a stack as a recognition result, and * free all hypotheses. * * The sentence candidates found at the 2nd pass will be pushed to the * "result stack" instead of immediate output. After recognition is * over (in case the number of found sentences reaches the number * specified by "-n", or search has been terminated in other reason), * the top N sentence candidates in the stack will be output as a * final result (where N should be specified by "-output"). After * then, all the hypotheses in the stack will be freed. * * Additionally, forced alignment for the recognized sentence * will be executed here if required. * * @param r_start [i/o] pointer to the top node of the result stack * @param r_bottom [i/o] pointer to the bottom node of the result stack * @param r_stacknum [i/o] number of candidates in the current result stack * @param ncan [in] number of sentence candidates to be output * @param r [in] recognition process instance * @param param [in] input parameter * </EN> */static voidresult_reorder_and_output(NODE **r_start, NODE **r_bottom, int *r_stacknum, int ncan, RecogProcess *r, HTK_Param *param){ NODE *now; int num;#ifdef CM_NBEST /* compute CM from the N-best sentence candidates */ cm_compute_from_nbest(&(r->pass2), *r_start, *r_stacknum, r->config);#endif num = 0; while ((now = get_best_from_stack(r_start,r_stacknum)) != NULL && num < ncan) { num++; /* output result */ store_result_pass2(now, r); /* if in sp segmentation mode, */ /* set the last context-aware word for next recognition */ if (r->lmtype == LM_PROB && r->config->successive.enabled && num == 1) segment_set_last_nword(now, r); free_node(now); } /* free the rest */ if (now != NULL) free_node(now); free_all_nodes(*r_start);} /** * <EN> * @brief Post-process of 2nd pass when no result is obtained. * * This is a post-process for the 2nd pass which should be called when * the 2nd pass has no result. This will occur when the 2nd pass was * executed but failed with no sentence candidate, or skipped by * an option. * * When the 2nd argument is set to TRUE, the result of the 1st pass * will be copied as final result of 2nd pass and the recognition * status flag is set to SUCCESS. If FALSE, recognition status will * be set to FAILED. On sp-segment decoding, the initial hypothesis * marker for the next input segment will be set up from the 1st pass * result also. * * @param r [in] recognition process instance * @param use_1pass_as_final [in] when TRUE the 1st pass result will be used as final recognition result of 2nd pass. * * </EN> * <JA> * @brief 妈2パスの豺が评られない眷圭の姜位借妄 * * 妈2パスが己窃した眷圭や妈2パスが悸乖されない肋年の眷圭の * 千急姜位借妄を乖うˉuse_1pass_as_final が TRUE のとき· * 妈1パスの冯蔡を妈2パスの冯蔡としてコピ〖して呈羌し·千急喇根とするˉ * FALSE箕は千急己窃とするˉ * また·sp-segment 箕は·肌の千急惰粗脱の介袋簿棱肋年も妈1パスの * 冯蔡から乖うˉ * * @param r [in] 千急借妄インスタンス * @param use_1pass_as_final [in] TRUE 箕妈1パスの冯蔡を妈2パス冯蔡に呈羌する * * </JA> */voidpass2_finalize_on_no_result(RecogProcess *r, boolean use_1pass_as_final){ NODE *now; int i, j; /* 玫瑚己窃 */ /* search failed */ /* make temporal hypothesis data from the result of previous 1st pass */ now = newnode(r); for (i=0;i<r->pass1_wnum;i++) { now->seq[i] = r->pass1_wseq[r->pass1_wnum-1-i]; } now->seqnum = r->pass1_wnum; now->score = r->pass1_score;#ifdef CONFIDENCE_MEASURE /* fill in null values */#ifdef CM_MULTIPLE_ALPHA for(j=0;j<jconf->annotate.cm_alpha_num;j++) { for(i=0;i<now->seqnum;i++) now->cmscore[i][j] = 0.0; }#else for(i=0;i<now->seqnum;i++) now->cmscore[i] = 0.0;#endif#endif /* CONFIDENCE_MEASURE */ if (r->lmtype == LM_PROB && r->config->successive.enabled) { /* if in sp segment mode, */ /* find segment restart words from 1st pass result */ segment_set_last_nword(now, r); } if (use_1pass_as_final) { /* 妈1パスの冯蔡をそのまま叫蜗する */ /* output the result of the previous 1st pass as a final result. */ store_result_pass2(now, r); r->result.status = J_RESULT_STATUS_SUCCESS; } else { /* store output as failure */ r->result.status = J_RESULT_STATUS_FAIL; //callback_exec(CALLBACK_RESULT, r); } free_node(now);}/**********************************************************************//********* Main stack decoding function *******************************//**********************************************************************//** * <JA> * 妈2玫瑚パスであるスタックデコ〖ディングを乖うメイン簇眶 * * 苞眶のうち cate_bgn, cate_num は帽胳N-gramでは痰浑される. * * @param param [in] 掐蜗パラメ〖タベクトル误 * @param r [i/o] 千急借妄インスタンス * @param cate_bgn [in] 鸥倡滦据とすべきカテゴリの倡幌戎规 * @param cate_num [in] 鸥倡滦据とすべきカテゴリの眶 * </JA> * <EN> * Main function to perform stack decoding of the 2nd search pass. * * The cate_bgn and cate_num (third and fourth argument) will have * no effect when N-gram is used. * * @param param [in] input parameter vector * @param r [i/o] recognition process instance * @param cate_bgn [in] category id to allow word expansion from (ignored in Julius) * @param cate_num [in] num of category to allow word expansion from (ignored in Julius) * </EN> * * @callgraph * @callergraph * */voidwchmm_fbs(HTK_Param *param, RecogProcess *r, int cate_bgn, int cate_num){ /* 矢簿棱スタック */ /* hypothesis stack (double-linked list) */ int stacknum; /* current stack size */ NODE *start = NULL; /* top node */ NODE *bottom = NULL; /* bottom node */ /* 千急冯蔡呈羌スタック(冯蔡はここへいったん礁められる) */ /* result sentence stack (found results will be stored here and then re-ordered) */ int r_stacksize; int r_stacknum; NODE *r_start = NULL; NODE *r_bottom = NULL; /* ワ〖クエリア */ /* work area */ NEXTWORD fornoise; /* Dummy NEXTWORD data for short-pause insertion handling */ NEXTWORD **nextword, *nwroot; /* buffer to store predicted words */ int maxnwnum; /* current allocated number of words in nextword */ int nwnum; /* current number of words in nextword */ NODE *now, *new; /* popped current hypo., expanded new hypo. */ NODE *now_noise; /* for inserting/deleting noise word */ boolean now_noise_calced; boolean acc; int t; int w,i,j; LOGPROB last_score = LOG_ZERO; /* for graph generation */ LOGPROB prev_score; WordGraph *wordgraph_root = NULL; boolean merged_p;#ifdef GRAPHOUT_DYNAMIC int dynamic_merged_num = 0; WordGraph *wtmp; LOGPROB lscore_prev;#endif#ifdef GRAPHOUT_SEARCH int terminate_search_num = 0;#endif /* local temporal parameter */ int stacksize, ncan, maxhypo, peseqlen; JCONF_SEARCH *jconf; WORD_INFO *winfo; NGRAM_INFO *ngram; DFA_INFO *gdfa; BACKTRELLIS *backtrellis; StackDecode *dwrk; if (r->lmtype == LM_DFA) { if (debug2_flag) jlog("DEBUG: only words in these categories will be expanded: %d-%d\n", cate_bgn, cate_bgn + cate_num-1); } /* * 介袋步
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?