PocketSphinx
0.6
|
00001 /* -*- c-basic-offset: 4; indent-tabs-mode: nil -*- */ 00002 /* ==================================================================== 00003 * Copyright (c) 2008 Carnegie Mellon University. All rights 00004 * reserved. 00005 * 00006 * Redistribution and use in source and binary forms, with or without 00007 * modification, are permitted provided that the following conditions 00008 * are met: 00009 * 00010 * 1. Redistributions of source code must retain the above copyright 00011 * notice, this list of conditions and the following disclaimer. 00012 * 00013 * 2. Redistributions in binary form must reproduce the above copyright 00014 * notice, this list of conditions and the following disclaimer in 00015 * the documentation and/or other materials provided with the 00016 * distribution. 00017 * 00018 * This work was supported in part by funding from the Defense Advanced 00019 * Research Projects Agency and the National Science Foundation of the 00020 * United States of America, and the CMU Sphinx Speech Consortium. 00021 * 00022 * THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND 00023 * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 00024 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 00025 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY 00026 * NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00027 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00028 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00029 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 00030 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00031 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00032 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00033 * 00034 * ==================================================================== 00035 * 00036 */ 00037 00044 #ifndef __POCKETSPHINX_INTERNAL_H__ 00045 #define __POCKETSPHINX_INTERNAL_H__ 00046 00047 /* SphinxBase headers. */ 00048 #include <sphinxbase/cmd_ln.h> 00049 #include <sphinxbase/logmath.h> 00050 #include <sphinxbase/fe.h> 00051 #include <sphinxbase/feat.h> 00052 #include <sphinxbase/profile.h> 00053 00054 /* Local headers. */ 00055 #include "pocketsphinx.h" 00056 #include "acmod.h" 00057 #include "dict.h" 00058 #include "dict2pid.h" 00059 00063 typedef struct ps_search_s ps_search_t; 00064 00068 typedef struct ps_searchfuncs_s { 00069 char const *name; 00070 00071 int (*start)(ps_search_t *search); 00072 int (*step)(ps_search_t *search, int frame_idx); 00073 int (*finish)(ps_search_t *search); 00074 int (*reinit)(ps_search_t *search, dict_t *dict, dict2pid_t *d2p); 00075 void (*free)(ps_search_t *search); 00076 00077 ps_lattice_t *(*lattice)(ps_search_t *search); 00078 char const *(*hyp)(ps_search_t *search, int32 *out_score); 00079 int32 (*prob)(ps_search_t *search); 00080 ps_seg_t *(*seg_iter)(ps_search_t *search, int32 *out_score); 00081 } ps_searchfuncs_t; 00082 00086 struct ps_search_s { 00087 ps_searchfuncs_t *vt; 00088 ps_search_t *pls; 00089 cmd_ln_t *config; 00090 acmod_t *acmod; 00091 dict_t *dict; 00092 dict2pid_t *d2p; 00093 char *hyp_str; 00094 ps_lattice_t *dag; 00095 ps_latlink_t *last_link; 00096 int32 post; 00097 int32 n_words; 00100 /* Magical word IDs that must exist in the dictionary: */ 00101 int32 start_wid; 00102 int32 silence_wid; 00103 int32 finish_wid; 00104 }; 00105 00106 #define ps_search_base(s) ((ps_search_t *)s) 00107 #define ps_search_config(s) ps_search_base(s)->config 00108 #define ps_search_acmod(s) ps_search_base(s)->acmod 00109 #define ps_search_dict(s) ps_search_base(s)->dict 00110 #define ps_search_dict2pid(s) ps_search_base(s)->d2p 00111 #define ps_search_dag(s) ps_search_base(s)->dag 00112 #define ps_search_last_link(s) ps_search_base(s)->last_link 00113 #define ps_search_post(s) ps_search_base(s)->post 00114 #define ps_search_lookahead(s) ps_search_base(s)->pls 00115 #define ps_search_n_words(s) ps_search_base(s)->n_words 00116 00117 #define ps_search_name(s) ps_search_base(s)->vt->name 00118 #define ps_search_start(s) (*(ps_search_base(s)->vt->start))(s) 00119 #define ps_search_step(s,i) (*(ps_search_base(s)->vt->step))(s,i) 00120 #define ps_search_finish(s) (*(ps_search_base(s)->vt->finish))(s) 00121 #define ps_search_reinit(s,d,d2p) (*(ps_search_base(s)->vt->reinit))(s,d,d2p) 00122 #define ps_search_free(s) (*(ps_search_base(s)->vt->free))(s) 00123 #define ps_search_lattice(s) (*(ps_search_base(s)->vt->lattice))(s) 00124 #define ps_search_hyp(s,sc) (*(ps_search_base(s)->vt->hyp))(s,sc) 00125 #define ps_search_prob(s) (*(ps_search_base(s)->vt->prob))(s) 00126 #define ps_search_seg_iter(s,sc) (*(ps_search_base(s)->vt->seg_iter))(s,sc) 00127 00128 /* For convenience... */ 00129 #define ps_search_silence_wid(s) ps_search_base(s)->silence_wid 00130 #define ps_search_start_wid(s) ps_search_base(s)->start_wid 00131 #define ps_search_finish_wid(s) ps_search_base(s)->finish_wid 00132 00136 void ps_search_init(ps_search_t *search, ps_searchfuncs_t *vt, 00137 cmd_ln_t *config, acmod_t *acmod, dict_t *dict, 00138 dict2pid_t *d2p); 00139 00143 void ps_search_base_reinit(ps_search_t *search, dict_t *dict, 00144 dict2pid_t *d2p); 00145 00149 void ps_search_deinit(ps_search_t *search); 00150 00151 typedef struct ps_segfuncs_s { 00152 ps_seg_t *(*seg_next)(ps_seg_t *seg); 00153 void (*seg_free)(ps_seg_t *seg); 00154 } ps_segfuncs_t; 00155 00159 struct ps_seg_s { 00160 ps_segfuncs_t *vt; 00161 ps_search_t *search; 00162 char const *word; 00163 int16 sf; 00164 int16 ef; 00165 int32 ascr; 00166 int32 lscr; 00167 int32 prob; 00168 /* This doesn't need to be 32 bits, so once the scores above are 00169 * reduced to 16 bits (or less!), this will be too. */ 00170 int32 lback; 00171 /* Not sure if this should be here at all. */ 00172 float32 lwf; 00173 }; 00174 00175 #define ps_search_seg_next(seg) (*(seg->vt->seg_next))(seg) 00176 #define ps_search_seg_free(s) (*(seg->vt->seg_free))(seg) 00177 00178 00182 struct ps_decoder_s { 00183 /* Model parameters and such. */ 00184 cmd_ln_t *config; 00185 int refcount; 00187 /* Basic units of computation. */ 00188 acmod_t *acmod; 00189 dict_t *dict; 00190 dict2pid_t *d2p; 00191 logmath_t *lmath; 00193 /* Search modules. */ 00194 glist_t searches; 00195 /* TODO: Convert this to a stack of searches each with their own 00196 * lookahead value. */ 00197 ps_search_t *search; 00198 ps_search_t *phone_loop; 00199 int pl_window; 00201 /* Utterance-processing related stuff. */ 00202 uint32 uttno; 00203 char *uttid; 00204 ptmr_t perf; 00205 uint32 n_frame; 00206 char const *mfclogdir; 00207 char const *rawlogdir; 00208 char const *senlogdir; 00209 }; 00210 00211 #endif /* __POCKETSPHINX_INTERNAL_H__ */