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

📄 uttproc.c

📁 WinCE平台上的语音识别程序
💻 C
📖 第 1 页 / 共 4 页
字号:
/* -*- 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 work was supported in part by funding from the Defense Advanced  * Research Projects Agency and the National Science Foundation of the  * United States of America, and the CMU Sphinx Speech Consortium. * * 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. * * ==================================================================== * *//* * uttproc.c -- Process utterance. *  * HISTORY *  * 22-Nov-2004  M K Ravishankar (rkm@cs.cmu.edu) at Carnegie Mellon Univ. *              Modified to use senscr module for senone score computation. *  * 18-Nov-2004  M K Ravishankar (rkm@cs.cmu.edu) at Carnegie Mellon Univ. *              uttproc_feat2rawfr() is buggy; set it to ignore comp2rawfr[]. *  * Revision 1.18  2004/11/13 00:38:44  egouvea * Replaced most printf with E_INFO (or E_WARN or...). Changed the output * of the time_align code so it's consistent with the other decoder modes * (allphone, normal decoding etc). Added the file utt id to the * time_align output. * * Revision 1.17  2004/07/23 23:36:34  egouvea * Ravi's merge, with the latest fixes in the FSG code, and making the log files generated by FSG, LM, and allphone have the same 'look and feel', with the backtrace information presented consistently * * Revision 1.8  2004/07/20 20:48:40  rkm * Added uttproc_load_fsg(). * * Revision 1.7  2004/07/20 13:40:55  rkm * Added FSG get/set start/final state functions. * * Revision 1.6  2004/07/16 19:55:28  rkm * Added state information to hypothesis. * * Revision 1.16  2004/07/16 00:57:12  egouvea * Added Ravi's implementation of FSG support. * * Revision 1.5  2004/07/07 13:56:33  rkm * Added reporting of (acoustic score - best senone score)/frame * * Revision 1.4  2004/06/22 15:35:46  rkm * Added partial result reporting options in batch mode * * Revision 1.3  2004/06/16 17:48:03  rkm * Imported pscr-based stuff from fbs_main.c * * Revision 1.2  2004/05/27 14:22:57  rkm * FSG cross-word triphones completed (but for single-phone words) * * Revision 1.2  2004/03/02 15:33:39  rkm * FSG bug fixes * * Revision 1.14  2004/03/02 04:10:14  rkm * FSG bugfix: need to get senscores every utt * * Revision 1.13  2004/03/01 20:30:56  rkm * *** empty log message *** * * Revision 1.12  2004/03/01 20:21:33  rkm * *** empty log message *** * * Revision 1.11  2004/02/27 21:01:25  rkm * Many bug fixes in multiple FSGs * * Revision 1.10  2004/02/27 19:33:01  rkm * *** empty log message *** * * Revision 1.9  2004/02/27 16:15:13  rkm * Added FSG switching * * Revision 1.8  2004/02/27 15:05:21  rkm * *** empty log message *** * * Revision 1.7  2004/02/26 01:14:48  rkm * *** empty log message *** * * Revision 1.6  2004/02/25 15:08:19  rkm * *** empty log message *** * * Revision 1.5  2004/02/24 18:13:05  rkm * Added NULL transition handling * * Revision 1.4  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.1.1  2003/12/03 20:05:04  rkm * Initial CVS repository * * Revision 1.15  2001/12/11 00:24:48  lenzo * Acknowledgement in License. * * Revision 1.14  2001/12/07 20:32:59  lenzo * No unistd.h on Windows. * * Revision 1.13  2001/12/07 17:46:00  lenzo * Un-ifdef the include for <unistd.h> * * Revision 1.12  2001/12/07 17:30:02  lenzo * Clean up and remove extra lines. * * Revision 1.11  2001/12/07 05:09:30  lenzo * License.xsxc * * Revision 1.10  2001/12/07 04:27:35  lenzo * License cleanup.  Remove conditions on the names.  Rationale: These * conditions don't belong in the license itself, but in other fora that * offer protection for recognizeable names such as "Carnegie Mellon * University" and "Sphinx."  These changes also reduce interoperability * issues with other licenses such as the Mozilla Public License and the * GPL.  This update changes the top-level license files and removes the * old license conditions from each of the files that contained it. * All files in this collection fall under the copyright of the top-level * LICENSE file. * * Revision 1.9  2001/10/23 22:20:30  lenzo * Change error logging and reporting to the E_* macros that call common * functions.  This will obsolete logmsg.[ch] and they will be removed * or changed in future versions. * * Revision 1.8  2001/03/31 00:56:12  lenzo * Added <string.h> * * Revision 1.6  2001/01/25 19:36:28  lenzo * Fixing some memory leaks * * Revision 1.5  2000/12/21 18:04:51  lenzo * Fixed a nasty (but small) FRAME_RATE error.  This will need cleanup later. * * Revision 1.4  2000/12/12 23:01:42  lenzo * Rationalizing libs and names some more.  Split a/d and fe libs out. * * Revision 1.3  2000/12/05 01:45:12  lenzo * Restructuring, hear rationalization, warning removal, ANSIfy * * Revision 1.2  2000/02/08 20:44:32  lenzo * Changed uttproc_allphone_cepfile() to uttproc_allphone_file. * * Revision 1.1.1.1  2000/01/28 22:08:58  lenzo * Initial import of sphinx2 * * 09-Jan-00    Kevin Lenzo <lenzo@cs.cmu.edu> at Carnegie Mellon *              Altered to accomodate new fe lib. *  * 30-Oct-98    M K Ravishankar (rkm@cs) at Carnegie Mellon University *              Changed rawlogfile mode to READONLY (WIN32). *  * 10-Sep-98    M K Ravishankar (rkm@cs) at Carnegie Mellon University *              Reset uttno to 0 whenever uttproc_set_auto_uttid_prefix() is called. *  * 10-Sep-98    M K Ravishankar (rkm@cs) at Carnegie Mellon University *              Added uttproc_allphone_cepfile(), and minor modifications to support it. *  * 20-Aug-98    M K Ravishankar (rkm@cs) at Carnegie Mellon University *              Bugfix:  *              Added call to agc_emax_update() inside uttproc_end_utt().  Added call *              to initialize AGC with a reasonable value. *  * 20-Apr-98    M K Ravishankar (rkm@cs) at Carnegie Mellon University *              Added uttproc_set_auto_uttid_prefix(). *  * 11-Apr-98    M K Ravishankar (rkm@cs) at Carnegie Mellon University *              Added AGC_NONE test to determining livemode in uttproc_begin_utt(). *              Added memcpy to mfc2feat_live if AGC_NONE (bugfix). *  * 22-Jul-97    M K Ravishankar (rkm@cs) at Carnegie Mellon University *              Added sampling rate spec in call to fe_init. *  * 27-May-97    M K Ravishankar (rkm@cs) at Carnegie Mellon University *              Added uttprocSetcomp2rawfr() and uttprocGetcomp2rawfr() functions *              implemented by Bob Brennan for maintaining multiple lattices. *  * 04-Apr-97    M K Ravishankar (rkm@cs) at Carnegie Mellon University *              Added dictwd_in_lm() check in uttproc_set_context. *  * 30-Oct-96    M K Ravishankar (rkm@cs) at Carnegie Mellon University *              Commented out call to search_dump_lattice_ascii. *              Added feature vector padding in mfc2feat_batch (). *  * 17-Jun-96    M K Ravishankar (rkm@cs) at Carnegie Mellon University *              Added uttproc_set_context(). *  * 04-Jun-96    M K Ravishankar (rkm@cs) at Carnegie Mellon University *              Added BLOCKING option to uttproc_rawdata, uttproc_cepdata, uttproc_result. *  * 24-May-96    M K Ravishankar (rkm@cs) at Carnegie Mellon University *              Substantially modified to be driven with externally provided data, rather *                      than explicitly reading an A/D source. *              Added uttproc_abort_utt() and uttproc_partial_result(). *              Added raw and mfc logging function. *  * 17-Nov-95    M K Ravishankar (rkm@cs) at Carnegie Mellon University *              Added function uttproc_lmupdate(). *  * 17-Nov-95    M K Ravishankar (rkm@cs) at Carnegie Mellon University *              Fixed bug in uttproc_feat2rawfr that could return feat2rawfr[-1]. *  * 29-Sep-95    M K Ravishankar (rkm@cs) at Carnegie Mellon University *              Added -matchsegfn argument and processing. *  * 17-Sep-95    M K Ravishankar (rkm@cs) at Carnegie Mellon University *              Added autonumbering of utterances (typically used in live mode). *  * 02-Jul-95    M K Ravishankar (rkm@cs) at Carnegie Mellon University *              Added allphone handling. *  * 13-Jun-95    M K Ravishankar (rkm@cs) at Carnegie Mellon University *              Simplified the uttproc interface by combining functions and redefining *              others. *  * 01-Jun-95    M K Ravishankar (rkm@cs) at Carnegie Mellon University *              Added uttproc_set_lm() and uttproc_set_startword(). *//* * BUGS: *   - Instead of using query_fwdtree_flag() to determine which first pass to run *     (tree or flag), there should be an explicit uttproc_set_firstpass() call. *//* System Headers */#include <stdio.h>#include <stdlib.h>#include <time.h>#include <stdlib.h>#include <assert.h>#include <string.h>#if !defined(_WIN32)#include <sys/resource.h>#include <sys/time.h>#include <sys/types.h>#include <sys/param.h>#include <unistd.h> /* dup2() */#endif/* SphinxBase headers */#include <sphinx_config.h>#include <cmd_ln.h>/* Local headers */#include "s2types.h"#include "ckd_alloc.h"#include "basic_types.h"#include "err.h"#include "s2_semi_mgau.h"#include "senscr.h"#include "search_const.h"#include "msd.h"#include "strfuncs.h"#include "linklist.h"#include "list.h"#include "dict.h"#include "lmclass.h"#include "lm_3g.h"#include "kb.h"#include "feat.h"#include "fe.h"#include "fixpoint.h"#include "fbs.h"#include "search.h"#include "fsg_search.h"#include "ckd_alloc.h"#include "uttproc.h"#include "posixwin32.h"#define MAX_UTT_LEN     6000    /* #frames */typedef enum {    UTTSTATE_UNDEF = -1,    UTTSTATE_IDLE = 0,    UTTSTATE_BEGUN = 1,    UTTSTATE_ENDED = 2,    UTTSTATE_STOPPED = 3} uttstate_t;static uttstate_t uttstate = UTTSTATE_UNDEF;/* Used to flag beginning of utterance in livemode. */static int32 uttstart;static int32 inputtype;#define INPUT_UNKNOWN   0#define INPUT_RAW       1#define INPUT_MFC       2static int32 livemode;          /* Iff TRUE, search while input being supplied.  In this                                   case, CMN, AGC and silence compression cannot be                                   utterance based */static int32 utt_ofl;           /* TRUE iff buffer limits overflowed in current utt */static int32 nosearch = 0;static int32 fsg_search_mode = FALSE;   /* Using FSM search structure *//* Feature computation object */feat_t *fcb;/* MFC vectors for entire utt */static mfcc_t **mfcbuf;static int32 n_cepfr;          /* #input frames *//* Feature vectors for entire utt */static mfcc_t ***feat_buf;static int32 n_featfr;          /* #features frames */static int32 n_searchfr;static FILE *matchfp = NULL;static FILE *matchsegfp = NULL;static char *rawlogdir = NULL;static char *mfclogdir = NULL;static FILE *rawfp = NULL;static FILE *mfcfp = NULL;static char rawfilename[4096];static int32 samp_hist[5];      /* #Samples in 0-4K, 4K-8K, 8K-16K, 16K-24K, 24K-32K */static int32 max_samp;static char *uttid;static char *uttid_prefix = NULL;#define UTTIDSIZE       4096static int32 uttno;             /* A running sequence number assigned to every utterance.  Used as                                   an id for an utterance if uttid is undefined. */static search_hyp_t *utt_seghyp = NULL;static float TotalCPUTime, TotalElapsedTime, TotalSpeechTime;#if defined(_WIN32) && !defined(GNUWINCE) && !defined(CYGWIN)#include <windows.h>static float e_start, e_stop;static HANDLE pid;static FILETIME t_create, t_exit, kst, ket, ust, uet;static double lowscale, highscale;extern double win32_cputime();#else /* Not Windows */static struct rusage start, stop;static struct timeval e_start, e_stop;#endif/* searchlat.c */void searchlat_set_rescore_lm(char const *lmname);static fsg_search_t *fsg_search;#if defined(_WIN32) && !defined(GNUWINCE) && !defined(CYGWIN)/* The FILETIME manual page says: "It is not recommended that you add * and subtract values from the FILETIME structure to obtain relative * times." */doublewin32_cputime(FILETIME * st, FILETIME * et){    double dt;    ULARGE_INTEGER l_st = *(ULARGE_INTEGER *) st;    ULARGE_INTEGER l_et = *(ULARGE_INTEGER *) et;    LONGLONG ltime;    ltime = l_et.QuadPart - l_st.QuadPart;    dt = (ltime * lowscale);    return (dt);}#elsedoubleMakeSeconds(struct timeval const *s, struct timeval const *e)/*------------------------------------------------------------------------* * Compute an elapsed time from two timeval structs */{    return ((e->tv_sec - s->tv_sec) +            ((e->tv_usec - s->tv_usec) / 1000000.0));}#endif/* * One time initialization */static voidtiming_init(void){#if defined(_WIN32) && !defined(GNUWINCE) && !defined(CYGWIN)    lowscale = 1e-7;    highscale = 65536.0 * 65536.0 * lowscale;    pid = GetCurrentProcess();#endif    TotalCPUTime = TotalElapsedTime = TotalSpeechTime = 0.0;}/* * Start of each utterance */static voidtiming_start(void){#if !(defined(_WIN32) && !defined(GNUWINCE) && !defined(CYGWIN))# if !(defined(_HPUX_SOURCE) || defined(GNUWINCE))    getrusage(RUSAGE_SELF, &start);# endif    gettimeofday(&e_start, 0);#else                           /* _WIN32 */# ifdef _WIN32_WCE    e_start = (float) GetTickCount() / 1000;# else    e_start = (float) clock() / CLOCKS_PER_SEC;    GetProcessTimes(pid, &t_create, &t_exit, &kst, &ust);# endif /* !_WIN32_WCE */#endif                          /* _WIN32 */}/* * End of each utterance */static voidtiming_stop(int32 nfr){    if (nfr <= 0)        return;    E_INFO(" %5.2f SoS", searchFrame() * 0.01);

⌨️ 快捷键说明

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