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

📄 fsg_psubtree.c

📁 WinCE平台上的语音识别程序
💻 C
📖 第 1 页 / 共 2 页
字号:
/* -*- c-basic-offset: 4; indent-tabs-mode: nil -*- *//* ==================================================================== * Copyright (c) 1999-2004 Carnegie Mellon University.  All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright *    notice, this list of conditions and the following disclaimer.  * * 2. Redistributions in binary form must reproduce the above copyright *    notice, this list of conditions and the following disclaimer in *    the documentation and/or other materials provided with the *    distribution. * * * THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND  * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY * NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * *//* * fsg_psubtree.c -- Phone-level FSG subtree representing all transitions * out of a single FSG state. *  * ********************************************** * CMU ARPA Speech Project * * Copyright (c) 2004 Carnegie Mellon University. * ALL RIGHTS RESERVED. * ********************************************** *  * HISTORY *  * $Log: fsg_psubtree.c,v $ * Revision 1.1.1.1  2006/05/23 18:44:59  dhuggins * re-importation * * Revision 1.2  2005/01/26 17:54:52  rkm * Added -maxhmmpf absolute pruning parameter in FSG mode * * Revision 1.1  2004/07/16 00:57:11  egouvea * Added Ravi's implementation of FSG support. * * Revision 1.3  2004/06/25 14:49:08  rkm * Optimized size of history table and speed of word transitions by maintaining only best scoring word exits at each state * * Revision 1.2  2004/05/27 14:22:57  rkm * FSG cross-word triphones completed (but for single-phone words) * * Revision 1.1.1.1  2004/03/01 14:30:30  rkm * * * Revision 1.3  2004/02/27 21:01:25  rkm * Many bug fixes in multiple FSGs * * Revision 1.2  2004/02/27 15:05:21  rkm * *** empty log message *** * * Revision 1.1  2004/02/23 15:53:45  rkm * Renamed from fst to fsg * * Revision 1.3  2004/02/23 15:09:50  rkm * *** empty log message *** * * Revision 1.2  2004/02/19 21:16:54  rkm * Added fsg_search.{c,h} * * Revision 1.1  2004/02/17 21:11:49  rkm * *** empty log message *** * *  * 10-Feb-2004	M K Ravishankar (rkm@cs.cmu.edu) at Carnegie Mellon * 		Started. */#include <stdio.h>#include <string.h>#include <assert.h>#include <ckd_alloc.h>#include <cmd_ln.h>#include <err.h>#include "fsg_psubtree.h"#include "kb.h"#include "dict.h"#include "phone.h"#include "log.h"#include "search.h"voidfsg_pnode_add_all_ctxt(fsg_pnode_ctxt_t * ctxt){    int32 i;    for (i = 0; i < FSG_PNODE_CTXT_BVSZ; i++)        ctxt->bv[i] = 0xffffffff;}uint32fsg_pnode_ctxt_sub(fsg_pnode_ctxt_t * src, fsg_pnode_ctxt_t * sub){    int32 i;    uint32 non_zero;    non_zero = 0;    for (i = 0; i < FSG_PNODE_CTXT_BVSZ; i++) {        src->bv[i] = ~(sub->bv[i]) & src->bv[i];        non_zero |= src->bv[i];    }    return non_zero;}/* * Add the word emitted by the given transition (fsglink) to the given lextree * (rooted at root), and return the new lextree root.  (There may actually be * several root nodes, maintained in a linked list via fsg_pnode_t.sibling. * "root" is the head of this list.) * lclist, rclist: sets of left and right context phones for this link. * alloc_head: head of a linear list of all allocated pnodes for the parent * FSG state, kept elsewhere and updated by this routine. *  * NOTE: No lextree structure for now; using a flat representation. */static fsg_pnode_t *psubtree_add_trans(fsg_pnode_t * root,                   word_fsglink_t * fsglink,                   int8 * lclist, int8 * rclist, fsg_pnode_t ** alloc_head){    int32 **lcfwd;              /* Uncompressed left cross-word context map;                                   lcfwd[left-diphone][p] = SSID for p.left-diphone */    int32 **lcbwd;              /* Compressed left cross-word context map;                                   lcbwd[left-diphone] = array of unique SSIDs for all                                   possible left contexts */    int32 **lcbwdperm;          /* For CIphone p, lcbwdperm[d][p] = index in lcbwd[d]                                   containing the SSID for triphone p.d */    int32 **rcbwd;              /* Uncompressed right cross-word context map;                                   rcbwd[right-diphone][p] = SSID for right-diphone.p */    int32 **rcfwd;              /* Compressed right cross-word context map; similar to                                   lcbwd */    int32 **rcfwdperm;    int32 silcipid;             /* Silence CI phone ID */    int32 wip;                  /* Word Insertion Penalty */    int32 pip;                  /* Phone Insertion Penalty */    int32 pronlen;              /* Pronunciation length */    float32 lw;                 /* Language weight */    int32 wid;                  /* Word ID */    int32 did;                  /* Diphone ID */    int32 ssid;                 /* Senone Sequence ID */    gnode_t *gn;    fsg_pnode_t *pnode, *pred, *head;    int32 n_ci, p, lc, rc;    glist_t lc_pnodelist;       /* Temp pnodes list for different left contexts */    glist_t rc_pnodelist;       /* Temp pnodes list for different right contexts */    fsg_pnode_t **ssid_pnode_map;       /* Temp array of ssid->pnode mapping */    int32 i, j;    lw = cmd_ln_float32("-lw");    pip = (int32) (LOG(cmd_ln_float32("-pip")) * lw);    wip = (int32) (LOG(cmd_ln_float32("-wip")) * lw);    silcipid = phone_to_id("SIL",  TRUE);    n_ci = phoneCiCount();    lcfwd = dict_left_context_fwd();    lcbwd = dict_left_context_bwd();    lcbwdperm = dict_left_context_bwd_perm();    rcbwd = dict_right_context_bwd();    rcfwd = dict_right_context_fwd();    rcfwdperm = dict_right_context_fwd_perm();    wid = word_fsglink_wid(fsglink);    assert(wid >= 0);           /* Cannot be a null transition */    pronlen = dict_pronlen(word_dict, wid);    assert(pronlen >= 1);    if (pronlen > 255) {        E_FATAL            ("Pronlen too long (%d); cannot use int8 for fsg_pnode_t.ppos\n",             pronlen);    }    assert(lclist[0] >= 0);     /* At least one phonetic context provided */    assert(rclist[0] >= 0);    head = *alloc_head;    pred = NULL;    if (pronlen == 1) {         /* Single-phone word */        did = dict_phone(word_dict, wid, 0); /* Diphone ID or SSID */        if (dict_mpx(word_dict, wid)) {      /* Only non-filler words are mpx */            /*             * Left diphone ID for single-phone words already assumes SIL is right             * context; only left contexts need to be handled.             */            lc_pnodelist = NULL;            for (i = 0; lclist[i] >= 0; i++) {                lc = lclist[i];                ssid = lcfwd[did][lc];  /* Use lcfwd for single-phone word, not lcbwd,                                           as lcbwd would use only SIL as context */                /* Check if this ssid already allocated for some other context */                for (gn = lc_pnodelist; gn; gn = gnode_next(gn)) {                    pnode = (fsg_pnode_t *) gnode_ptr(gn);                    if (pnode->hmm.sseqid == ssid) {                        /* already allocated; share it for this context phone */                        fsg_pnode_add_ctxt(pnode, lc);                        break;                    }                }                if (!gn) {      /* ssid not already allocated */                    pnode =                        (fsg_pnode_t *) ckd_calloc(1, sizeof(fsg_pnode_t));                    pnode->hmm.sseqid = ssid;                    pnode->next.fsglink = fsglink;                    pnode->logs2prob =                        word_fsglink_logs2prob(fsglink) + wip + pip;                    pnode->ci_ext = (int8) dict_ciphone(word_dict, wid, 0);                    pnode->ppos = 0;                    pnode->leaf = TRUE;                    pnode->sibling = root;      /* All root nodes linked together */                    fsg_pnode_add_ctxt(pnode, lc);      /* Initially zeroed by calloc above */                    pnode->alloc_next = head;                    head = pnode;                    root = pnode;                    search_chan_deactivate(&(pnode->hmm));                    lc_pnodelist =                        glist_add_ptr(lc_pnodelist, (void *) pnode);                }            }            glist_free(lc_pnodelist);        }        else {                  /* Filler word; no context modelled */            ssid = did;         /* dict_phone() already has the right CIphone ssid */            pnode = (fsg_pnode_t *) ckd_calloc(1, sizeof(fsg_pnode_t));            pnode->hmm.sseqid = ssid;            pnode->next.fsglink = fsglink;            pnode->logs2prob = word_fsglink_logs2prob(fsglink) + wip + pip;            pnode->ci_ext = silcipid;   /* Presents SIL as context to neighbors */            pnode->ppos = 0;            pnode->leaf = TRUE;            pnode->sibling = root;            fsg_pnode_add_all_ctxt(&(pnode->ctxt));            pnode->alloc_next = head;            head = pnode;

⌨️ 快捷键说明

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