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

📄 search.c

📁 WinCE平台上的语音识别程序
💻 C
📖 第 1 页 / 共 5 页
字号:
                mpx_sseq2sen(chan, 0, 3),                mpx_sseq2sen(chan, 0, 4));        fprintf(fp, "\tSENSCR %11d %11d %11d %11d %11d\n",                mpx_sseq2score(chan, 0, 0),                mpx_sseq2score(chan, 0, 1),                mpx_sseq2score(chan, 0, 2),                mpx_sseq2score(chan, 0, 3),                mpx_sseq2score(chan, 0, 4));        fprintf(fp, "\tSCORES %11d %11d %11d %11d %11d %11d\n",                chan->score[0],                chan->score[1],                chan->score[2],                chan->score[3],                chan->score[4],                chan->score[5]);        fprintf(fp, "\tPATHS  %11d %11d %11d %11d %11d %11d\n",                chan->path[0],                chan->path[1],                chan->path[2],                chan->path[3],                chan->path[4],                chan->path[5]);    }}voidchan_dump(const char *msg, CHAN_T * chan, int32 frame, FILE * fp){    fprintf(fp, "[%4d] %s CIPHONE %5d SSID %5d (%5d %5d %5d %5d %5d)\n",            frame, msg, chan->ciphone, chan->sseqid,            bin_mdef_sseq2sen(mdef,chan->sseqid,0),            bin_mdef_sseq2sen(mdef,chan->sseqid,1),            bin_mdef_sseq2sen(mdef,chan->sseqid,2),            bin_mdef_sseq2sen(mdef,chan->sseqid,3),            bin_mdef_sseq2sen(mdef,chan->sseqid,4));    fprintf(fp, "\tSENSCR %11d %11d %11d %11d %11d\n",            senone_scores[bin_mdef_sseq2sen(mdef,chan->sseqid,0)],            senone_scores[bin_mdef_sseq2sen(mdef,chan->sseqid,1)],            senone_scores[bin_mdef_sseq2sen(mdef,chan->sseqid,2)],            senone_scores[bin_mdef_sseq2sen(mdef,chan->sseqid,3)],            senone_scores[bin_mdef_sseq2sen(mdef,chan->sseqid,4)]);    fprintf(fp, "\tSCORES %11d %11d %11d %11d %11d %11d\n",            chan->score[0],            chan->score[1],            chan->score[2],            chan->score[3],            chan->score[4],            chan->score[5]);    fprintf(fp, "\tPATHS  %11d %11d %11d %11d %11d %11d\n",            chan->path[0],            chan->path[1],            chan->path[2],            chan->path[3],            chan->path[4],            chan->path[5]);}#else#define root_chan_dump(m,c,f,p)#define chan_dump(m,c,f,p)#endif /* __CHAN_DUMP__ */voidroot_chan_v_eval(ROOT_CHAN_T * chan){    int32 **tp = tmat->tp[chan->ciphone];    CHAN_V_EVAL(chan, chan->sseqid[0], tp);}voidchan_v_eval(CHAN_T * chan){    int32 **tp = tmat->tp[chan->ciphone];    CHAN_V_EVAL(chan, chan->sseqid, tp);}int32eval_root_chan(void){    ROOT_CHAN_T *rhmm;    int32 i, cf, bestscore, k;    cf = CurrentFrame;    bestscore = WORST_SCORE;    k = 0;    for (i = n_root_chan, rhmm = root_chan; i > 0; --i, rhmm++) {        if (rhmm->active == cf) {            root_chan_dump("BEFORE(root)", rhmm, cf, stdout);            if (rhmm->mpx) {                root_chan_v_mpx_eval(rhmm);            }            else {                root_chan_v_eval(rhmm);            }            root_chan_dump("AFTER(root)", rhmm, cf, stdout);            if (bestscore < rhmm->bestscore)                bestscore = rhmm->bestscore;#if (SEARCH_PROFILE || SEARCH_TRACE_CHAN)            k++;#endif        }    }#if SEARCH_PROFILE    n_root_chan_eval += k;#endif#if SEARCH_TRACE_CHAN    E_INFO(" %3d #root(%10d)", cf, k, bestscore);#endif    return (bestscore);}int32eval_nonroot_chan(void){    CHAN_T *hmm, **acl;    int32 i, cf, bestscore, k;    cf = CurrentFrame;    i = n_active_chan[cf & 0x1];    acl = active_chan_list[cf & 0x1];    bestscore = WORST_SCORE;    k = i;    for (hmm = *(acl++); i > 0; --i, hmm = *(acl++)) {        assert(hmm->active == cf);        chan_dump("BEFORE(nonroot)", hmm, cf, stdout);        chan_v_eval(hmm);        chan_dump("AFTER(nonroot)", hmm, cf, stdout);        if (bestscore < hmm->bestscore)            bestscore = hmm->bestscore;    }#if SEARCH_PROFILE    n_nonroot_chan_eval += k;#endif#if SEARCH_TRACE_CHAN    E_INFO(" %5d #non-root(%10d)", k, bestscore);#endif    return (bestscore);}int32eval_word_chan(void){    ROOT_CHAN_T *rhmm;    CHAN_T *hmm;    int32 i, w, cf, bestscore, *awl, j, k;    k = 0;    cf = CurrentFrame;    bestscore = WORST_SCORE;    awl = active_word_list[cf & 0x1];    i = n_active_word[cf & 0x1];    for (w = *(awl++); i > 0; --i, w = *(awl++)) {        assert(word_active[w] != 0);        word_active[w] = 0;        assert(word_chan[w] != NULL);        for (hmm = word_chan[w]; hmm; hmm = hmm->next) {            assert(hmm->active == cf);            chan_dump("BEFORE(word)", hmm, cf, stdout);            chan_v_eval(hmm);            chan_dump("AFTER(word)", hmm, cf, stdout);            if (bestscore < hmm->bestscore)                bestscore = hmm->bestscore;#if (SEARCH_PROFILE || SEARCH_TRACE_CHAN)            k++;#endif        }    }    /* Similarly for statically allocated single-phone words */    j = 0;    for (i = 0; i < n_1ph_words; i++) {        w = single_phone_wid[i];        rhmm = (ROOT_CHAN_T *) word_chan[w];        if (rhmm->active < cf)            continue;        root_chan_dump("BEFORE(1ph)", rhmm, cf, stdout);        if (rhmm->mpx) {            root_chan_v_mpx_eval(rhmm);        }        else {            root_chan_v_eval(rhmm);        }        root_chan_dump("AFTER(1ph)", rhmm, cf, stdout);        if ((bestscore < rhmm->bestscore) && (w != FinishWordId))            bestscore = rhmm->bestscore;#if (SEARCH_PROFILE || SEARCH_TRACE_CHAN)        j++;#endif    }#if (SEARCH_PROFILE || SEARCH_TRACE_CHAN)    k += j;#endif#if SEARCH_PROFILE    n_last_chan_eval += k;    n_nonroot_chan_eval += k;    n_word_lastchan_eval += n_active_word[cf & 0x1] + j;#endif#if SEARCH_TRACE_CHAN    printf(" %5d #leaf(%10d)\n", k, bestscore);#endif    return (bestscore);}static voidcache_bptable_paths(int32 bp){    int32 w, prev_bp;    BPTBL_T *bpe;    bpe = &(BPTable[bp]);    prev_bp = bp;    w = bpe->wid;    while (ISA_FILLER_WORD(w)) {        prev_bp = BPTable[prev_bp].bp;        w = BPTable[prev_bp].wid;    }    bpe->real_fwid = word_dict->dict_list[w]->fwid;    if (cmd_ln_boolean("-fwd3g")) {        prev_bp = BPTable[prev_bp].bp;        bpe->prev_real_fwid =            (prev_bp != NO_BP) ? BPTable[prev_bp].real_fwid : -1;    }    else        bpe->prev_real_fwid = -1;}voidsave_bwd_ptr(WORD_ID w, int32 score, int32 path, int32 rc){    int32 _bp_;    _bp_ = WordLatIdx[w];    if (_bp_ != NO_BP) {        if (BPTable[_bp_].score < score) {            if (BPTable[_bp_].bp != path) {                BPTable[_bp_].bp = path;                cache_bptable_paths(_bp_);            }            BPTable[_bp_].score = score;        }        BScoreStack[BPTable[_bp_].s_idx + rc] = score;    }    else {        int32 i, rcsize, *bss;        dict_entry_t *de;        BPTBL_T *bpe;        if ((BPIdx >= BPTableSize)            || (BSSHead >= BScoreStackSize - NumCiPhones)) {            if (!BPTblOflMsg) {                E_ERROR                    ("BPTable OVERFLOWED; IGNORING REST OF UTTERANCE!!\n");                BPTblOflMsg = 1;            }            return;        }        de = word_dict->dict_list[w];        WordLatIdx[w] = BPIdx;        bpe = &(BPTable[BPIdx]);        bpe->wid = w;        bpe->frame = CurrentFrame;        bpe->bp = path;        bpe->score = score;        bpe->s_idx = BSSHead;        bpe->valid = 1;        if ((de->len != 1) && (de->mpx)) {            bpe->r_diph = de->phone_ids[de->len - 1];            rcsize = RightContextFwdSize[bpe->r_diph];        }        else {            bpe->r_diph = -1;            rcsize = 1;        }        for (i = rcsize, bss = BScoreStack + BSSHead; i > 0; --i, bss++)            *bss = WORST_SCORE;        BScoreStack[BSSHead + rc] = score;        cache_bptable_paths(BPIdx);        BPIdx++;        BSSHead += rcsize;    }}/* * Limit the number of word exits in each frame to maxwpf.  And also limit the number of filler * words to 1. */static voidbptable_maxwpf(int32 maxwpf){    int32 cf, bp, n;    int32 bestscr, worstscr;    BPTBL_T *bpe, *bestbpe, *worstbpe;    cf = CurrentFrame;    /* Allow only one filler word exit (the best) per frame */    bestscr = (int32) 0x80000000;    bestbpe = NULL;    n = 0;    for (bp = BPTableIdx[cf]; bp < BPIdx; bp++) {        bpe = &(BPTable[bp]);        if (ISA_FILLER_WORD(bpe->wid)) {            if (bpe->score > bestscr) {                bestscr = bpe->score;                bestbpe = bpe;            }            bpe->valid = 0;     /* Flag to indicate invalidation */            n++;                /* No. of filler words */        }    }    /* Restore bestbpe to valid state */    if (bestbpe != NULL) {        bestbpe->valid = 1;        --n;    }    /* Allow up to maxwpf best entries to survive; mark the remaining with valid = 0 */    n = (BPIdx - BPTableIdx[cf]) - n;   /* No. of entries after limiting fillers */    for (; n > maxwpf; --n) {        /* Find worst BPTable entry */        worstscr = (int32) 0x7fffffff;        worstbpe = NULL;        for (bp = BPTableIdx[cf]; (bp < BPIdx); bp++) {            bpe = &(BPTable[bp]);            if (bpe->valid && (bpe->score < worstscr)) {                worstscr = bpe->score;                worstbpe = bpe;            }        }        if (worstbpe == NULL)            E_FATAL("PANIC: No worst BPtable entry remaining\n");        worstbpe->valid = 0;    }}/* * Prune currently active root channels for next frame.  Also, perform exit * transitions out of them and activate successors. * score[] of pruned root chan set to WORST_SCORE elsewhere. */voidprune_root_chan(void){    ROOT_CHAN_T *rhmm;    CHAN_T *hmm;    int32 i, cf, nf, w, pip;    int32 thresh, newphone_thresh, lastphn_thresh, newphone_score;    CHAN_T **nacl;              /* next active list */    lastphn_cand_t *candp;    dict_entry_t *de;    cf = CurrentFrame;    nf = cf + 1;    thresh = BestScore + DynamicLogBeamWidth;    newphone_thresh =        BestScore + (DynamicLogBeamWidth >                     NewPhoneLogBeamWidth ? DynamicLogBeamWidth :                     NewPhoneLogBeamWidth);    lastphn_thresh =        BestScore + (DynamicLogBeamWidth >                     LastPhoneLogBeamWidth ? DynamicLogBeamWidth :                     LastPhoneLogBeamWidth);    pip = logPhoneInsertionPenalty;#if 0    printf("%10d =Th, %10d =NPTh, %10d =LPTh, %10d =bestscore\n",

⌨️ 快捷键说明

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