pocketsphinx_internal.h
Go to the documentation of this file.
/* -*- c-basic-offset: 4; indent-tabs-mode: nil -*- */
/* ====================================================================
* Copyright (c) 2008 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.
*
* ====================================================================
*
*/
#ifndef __POCKETSPHINX_INTERNAL_H__
#define __POCKETSPHINX_INTERNAL_H__
/* SphinxBase headers. */
#include <sphinxbase/cmd_ln.h>
#include <sphinxbase/fe.h>
#include <sphinxbase/feat.h>
#include <sphinxbase/hash_table.h>
#include <sphinxbase/logmath.h>
#include <sphinxbase/profile.h>
/* Local headers. */
#include "pocketsphinx.h"
#include "acmod.h"
#include "dict.h"
#include "dict2pid.h"
typedef struct ps_search_s ps_search_t;
/* Search names*/
#define PS_DEFAULT_SEARCH "_default"
#define PS_DEFAULT_PL_SEARCH "_default_pl"
/* Search types */
#define PS_SEARCH_TYPE_KWS "kws"
#define PS_SEARCH_TYPE_FSG "fsg"
#define PS_SEARCH_TYPE_NGRAM "ngram"
#define PS_SEARCH_TYPE_ALLPHONE "allphone"
#define PS_SEARCH_TYPE_STATE_ALIGN "state_align"
#define PS_SEARCH_TYPE_PHONE_LOOP "phone_loop"
typedef struct ps_searchfuncs_s {
int (*start)(ps_search_t *search);
int (*step)(ps_search_t *search, int frame_idx);
int (*finish)(ps_search_t *search);
int (*reinit)(ps_search_t *search, dict_t *dict, dict2pid_t *d2p);
void (*free)(ps_search_t *search);
ps_lattice_t *(*lattice)(ps_search_t *search);
char const *(*hyp)(ps_search_t *search, int32 *out_score);
int32 (*prob)(ps_search_t *search);
ps_seg_t *(*seg_iter)(ps_search_t *search);
} ps_searchfuncs_t;
struct ps_search_s {
ps_searchfuncs_t *vt;
char *type;
char *name;
ps_search_t *pls;
cmd_ln_t *config;
acmod_t *acmod;
dict_t *dict;
dict2pid_t *d2p;
char *hyp_str;
ps_lattice_t *dag;
ps_latlink_t *last_link;
int32 post;
int32 n_words;
/* Magical word IDs that must exist in the dictionary: */
int32 start_wid;
int32 silence_wid;
int32 finish_wid;
};
#define ps_search_base(s) ((ps_search_t *)s)
#define ps_search_config(s) ps_search_base(s)->config
#define ps_search_acmod(s) ps_search_base(s)->acmod
#define ps_search_dict(s) ps_search_base(s)->dict
#define ps_search_dict2pid(s) ps_search_base(s)->d2p
#define ps_search_dag(s) ps_search_base(s)->dag
#define ps_search_last_link(s) ps_search_base(s)->last_link
#define ps_search_post(s) ps_search_base(s)->post
#define ps_search_lookahead(s) ps_search_base(s)->pls
#define ps_search_n_words(s) ps_search_base(s)->n_words
#define ps_search_type(s) ps_search_base(s)->type
#define ps_search_name(s) ps_search_base(s)->name
#define ps_search_start(s) (*(ps_search_base(s)->vt->start))(s)
#define ps_search_step(s,i) (*(ps_search_base(s)->vt->step))(s,i)
#define ps_search_finish(s) (*(ps_search_base(s)->vt->finish))(s)
#define ps_search_reinit(s,d,d2p) (*(ps_search_base(s)->vt->reinit))(s,d,d2p)
#define ps_search_free(s) (*(ps_search_base(s)->vt->free))(s)
#define ps_search_lattice(s) (*(ps_search_base(s)->vt->lattice))(s)
#define ps_search_hyp(s,sc) (*(ps_search_base(s)->vt->hyp))(s,sc)
#define ps_search_prob(s) (*(ps_search_base(s)->vt->prob))(s)
#define ps_search_seg_iter(s) (*(ps_search_base(s)->vt->seg_iter))(s)
/* For convenience... */
#define ps_search_silence_wid(s) ps_search_base(s)->silence_wid
#define ps_search_start_wid(s) ps_search_base(s)->start_wid
#define ps_search_finish_wid(s) ps_search_base(s)->finish_wid
void ps_search_init(ps_search_t *search, ps_searchfuncs_t *vt,
const char *type, const char *name,
cmd_ln_t *config, acmod_t *acmod, dict_t *dict,
dict2pid_t *d2p);
void ps_search_base_free(ps_search_t *search);
void ps_search_base_reinit(ps_search_t *search, dict_t *dict,
dict2pid_t *d2p);
typedef struct ps_segfuncs_s {
ps_seg_t *(*seg_next)(ps_seg_t *seg);
void (*seg_free)(ps_seg_t *seg);
} ps_segfuncs_t;
struct ps_seg_s {
ps_segfuncs_t *vt;
ps_search_t *search;
char const *word;
frame_idx_t sf;
frame_idx_t ef;
int32 ascr;
int32 lscr;
int32 prob;
/* This doesn't need to be 32 bits, so once the scores above are
* reduced to 16 bits (or less!), this will be too. */
int32 lback;
/* Not sure if this should be here at all. */
float32 lwf;
};
#define ps_search_seg_next(seg) (*(seg->vt->seg_next))(seg)
#define ps_search_seg_free(s) (*(seg->vt->seg_free))(seg)
struct ps_decoder_s {
/* Model parameters and such. */
cmd_ln_t *config;
int refcount;
/* Basic units of computation. */
acmod_t *acmod;
dict_t *dict;
dict2pid_t *d2p;
logmath_t *lmath;
/* Search modules. */
hash_table_t *searches;
/* TODO: Convert this to a stack of searches each with their own
* lookahead value. */
ps_search_t *search;
ps_search_t *phone_loop;
int pl_window;
/* Utterance-processing related stuff. */
uint32 uttno;
ptmr_t perf;
uint32 n_frame;
char const *mfclogdir;
char const *rawlogdir;
char const *senlogdir;
};
struct ps_search_iter_s {
hash_iter_t itor;
};
#endif /* __POCKETSPHINX_INTERNAL_H__ */
acmod.h
Acoustic model structures for PocketSphinx.
dict2pid.h
Building triphones for a dictionary.
dict.h
Operations on dictionary.
frame_idx_t
int32 frame_idx_t
Type for frame index values.
Definition: hmm.h:64
pocketsphinx.h
Main header file for the PocketSphinx decoder.
ps_searchfuncs_t
struct ps_searchfuncs_s ps_searchfuncs_t
V-table for search algorithm.
ps_search_base_reinit
void ps_search_base_reinit(ps_search_t *search, dict_t *dict, dict2pid_t *d2p)
Re-initialize base structure with new dictionary.
Definition: pocketsphinx.c:1415
ps_search_base_free
void ps_search_base_free(ps_search_t *search)
Free search.
Definition: pocketsphinx.c:1402
ps_search_init
void ps_search_init(ps_search_t *search, ps_searchfuncs_t *vt, const char *type, const char *name, cmd_ln_t *config, acmod_t *acmod, dict_t *dict, dict2pid_t *d2p)
Initialize base structure.
Definition: pocketsphinx.c:1371
acmod_s
Acoustic model structure.
Definition: acmod.h:148
dict2pid_t
Building composite triphone (as well as word internal triphones) with the dictionary.
Definition: dict2pid.h:84
dict_t
a structure for a dictionary.
Definition: dict.h:76
ps_decoder_s
Decoder object.
Definition: pocketsphinx_internal.h:201
ps_decoder_s::config
cmd_ln_t * config
Configuration.
Definition: pocketsphinx_internal.h:203
ps_decoder_s::phone_loop
ps_search_t * phone_loop
Phone loop search for lookahead.
Definition: pocketsphinx_internal.h:217
ps_decoder_s::senlogdir
char const * senlogdir
Log directory for senone score files.
Definition: pocketsphinx_internal.h:226
ps_decoder_s::pl_window
int pl_window
Window size for phoneme lookahead.
Definition: pocketsphinx_internal.h:218
ps_decoder_s::uttno
uint32 uttno
Utterance counter.
Definition: pocketsphinx_internal.h:221
ps_decoder_s::n_frame
uint32 n_frame
Total number of frames processed.
Definition: pocketsphinx_internal.h:223
ps_decoder_s::searches
hash_table_t * searches
Set of search modules.
Definition: pocketsphinx_internal.h:213
ps_decoder_s::mfclogdir
char const * mfclogdir
Log directory for MFCC files.
Definition: pocketsphinx_internal.h:224
ps_decoder_s::rawlogdir
char const * rawlogdir
Log directory for audio files.
Definition: pocketsphinx_internal.h:225
ps_decoder_s::refcount
int refcount
Reference count.
Definition: pocketsphinx_internal.h:204
ps_decoder_s::perf
ptmr_t perf
Performance counter for all of decoding.
Definition: pocketsphinx_internal.h:222
ps_decoder_s::lmath
logmath_t * lmath
Log math computation.
Definition: pocketsphinx_internal.h:210
ps_decoder_s::search
ps_search_t * search
Currently active search module.
Definition: pocketsphinx_internal.h:216
ps_decoder_s::d2p
dict2pid_t * d2p
Dictionary to senone mapping.
Definition: pocketsphinx_internal.h:209
ps_decoder_s::dict
dict_t * dict
Pronunciation dictionary.
Definition: pocketsphinx_internal.h:208
ps_decoder_s::acmod
acmod_t * acmod
Acoustic model.
Definition: pocketsphinx_internal.h:207
ps_latlink_s
Links between DAG nodes.
Definition: ps_lattice_internal.h:96
ps_lattice_s
Word graph structure used in bestpath/nbest search.
Definition: ps_lattice_internal.h:61
ps_search_iter_s
Definition: pocketsphinx_internal.h:230
ps_search_s
Base structure for search module.
Definition: pocketsphinx_internal.h:98
ps_search_s::finish_wid
int32 finish_wid
Finish word ID.
Definition: pocketsphinx_internal.h:119
ps_search_s::acmod
acmod_t * acmod
Acoustic model.
Definition: pocketsphinx_internal.h:106
ps_search_s::pls
ps_search_t * pls
Phoneme loop for lookahead.
Definition: pocketsphinx_internal.h:104
ps_search_s::post
int32 post
Utterance posterior probability.
Definition: pocketsphinx_internal.h:112
ps_search_s::d2p
dict2pid_t * d2p
Dictionary to senone mappings.
Definition: pocketsphinx_internal.h:108
ps_search_s::dag
ps_lattice_t * dag
Current hypothesis word graph.
Definition: pocketsphinx_internal.h:110
ps_search_s::dict
dict_t * dict
Pronunciation dictionary.
Definition: pocketsphinx_internal.h:107
ps_search_s::last_link
ps_latlink_t * last_link
Final link in best path.
Definition: pocketsphinx_internal.h:111
ps_search_s::hyp_str
char * hyp_str
Current hypothesis string.
Definition: pocketsphinx_internal.h:109
ps_search_s::vt
ps_searchfuncs_t * vt
V-table of search methods.
Definition: pocketsphinx_internal.h:99
ps_search_s::config
cmd_ln_t * config
Configuration.
Definition: pocketsphinx_internal.h:105
ps_search_s::silence_wid
int32 silence_wid
Silence word ID.
Definition: pocketsphinx_internal.h:118
ps_search_s::n_words
int32 n_words
Number of words known to search (may be less than in the dictionary)
Definition: pocketsphinx_internal.h:113
ps_search_s::start_wid
int32 start_wid
Start word ID.
Definition: pocketsphinx_internal.h:117
ps_searchfuncs_s
V-table for search algorithm.
Definition: pocketsphinx_internal.h:82
ps_seg_s
Base structure for hypothesis segmentation iterator.
Definition: pocketsphinx_internal.h:178
ps_seg_s::search
ps_search_t * search
Search object from whence this came.
Definition: pocketsphinx_internal.h:180
ps_seg_s::lwf
float32 lwf
Language weight factor (for second-pass searches)
Definition: pocketsphinx_internal.h:191
ps_seg_s::lback
int32 lback
Language model backoff.
Definition: pocketsphinx_internal.h:189
ps_seg_s::vt
ps_segfuncs_t * vt
V-table of seg methods.
Definition: pocketsphinx_internal.h:179
ps_seg_s::lscr
int32 lscr
Language model score.
Definition: pocketsphinx_internal.h:185
ps_seg_s::ascr
int32 ascr
Acoustic score.
Definition: pocketsphinx_internal.h:184
ps_seg_s::sf
frame_idx_t sf
Start frame.
Definition: pocketsphinx_internal.h:182
ps_seg_s::word
char const * word
Word string (pointer into dictionary hash)
Definition: pocketsphinx_internal.h:181
ps_seg_s::ef
frame_idx_t ef
End frame.
Definition: pocketsphinx_internal.h:183
ps_seg_s::prob
int32 prob
Log posterior probability.
Definition: pocketsphinx_internal.h:186
ps_segfuncs_s
Definition: pocketsphinx_internal.h:170