PocketSphinx  0.6
pocketsphinx.h
Go to the documentation of this file.
1 /* -*- c-basic-offset:4; indent-tabs-mode: nil -*- */
2 /* ====================================================================
3  * Copyright (c) 1999-2008 Carnegie Mellon University. All rights
4  * reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  *
13  * 2. Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in
15  * the documentation and/or other materials provided with the
16  * distribution.
17  *
18  *
19  * THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND
20  * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY
23  * NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  *
31  * ====================================================================
32  *
33  */
38 #ifndef __POCKETSPHINX_H__
39 #define __POCKETSPHINX_H__
40 
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44 #if 0
45 }
46 #endif
47 
48 /* System headers we need. */
49 #include <stdio.h>
50 
51 /* SphinxBase headers we need. */
52 #include <sphinxbase/cmd_ln.h>
53 #include <sphinxbase/logmath.h>
54 #include <sphinxbase/fe.h>
55 #include <sphinxbase/feat.h>
56 #include <sphinxbase/ngram_model.h>
57 
58 /* PocketSphinx headers (not many of them!) */
59 #include <pocketsphinx_export.h>
60 #include <cmdln_macro.h>
61 #include <ps_lattice.h>
62 #include <ps_mllr.h>
63 #include <fsg_set.h>
64 
68 typedef struct ps_decoder_s ps_decoder_t;
69 
73 typedef struct ps_astar_s ps_nbest_t;
74 
78 typedef struct ps_seg_s ps_seg_t;
79 
90 POCKETSPHINX_EXPORT
91 ps_decoder_t *ps_init(cmd_ln_t *config);
92 
110 POCKETSPHINX_EXPORT
111 int ps_reinit(ps_decoder_t *ps, cmd_ln_t *config);
112 
119 POCKETSPHINX_EXPORT
120 arg_t const *ps_args(void);
121 
132 POCKETSPHINX_EXPORT
134 
145 POCKETSPHINX_EXPORT
146 int ps_free(ps_decoder_t *ps);
147 
156 POCKETSPHINX_EXPORT
157 cmd_ln_t *ps_get_config(ps_decoder_t *ps);
158 
167 POCKETSPHINX_EXPORT
168 logmath_t *ps_get_logmath(ps_decoder_t *ps);
169 
178 POCKETSPHINX_EXPORT
179 fe_t *ps_get_fe(ps_decoder_t *ps);
180 
189 POCKETSPHINX_EXPORT
190 feat_t *ps_get_feat(ps_decoder_t *ps);
191 
203 POCKETSPHINX_EXPORT
205 
217 POCKETSPHINX_EXPORT
218 ngram_model_t *ps_get_lmset(ps_decoder_t *ps);
219 
236 POCKETSPHINX_EXPORT
237 ngram_model_t *ps_update_lmset(ps_decoder_t *ps, ngram_model_t *lmset);
238 
248 POCKETSPHINX_EXPORT
250 
261 POCKETSPHINX_EXPORT
263 
278 POCKETSPHINX_EXPORT
279 int ps_load_dict(ps_decoder_t *ps, char const *dictfile,
280  char const *fdictfile, char const *format);
281 
291 POCKETSPHINX_EXPORT
292 int ps_save_dict(ps_decoder_t *ps, char const *dictfile, char const *format);
293 
313 POCKETSPHINX_EXPORT
314 int ps_add_word(ps_decoder_t *ps,
315  char const *word,
316  char const *phones,
317  int update);
318 
334 POCKETSPHINX_EXPORT
335 int ps_decode_raw(ps_decoder_t *ps, FILE *rawfh,
336  char const *uttid, long maxsamps);
337 
346 POCKETSPHINX_EXPORT
347 int ps_decode_senscr(ps_decoder_t *ps, FILE *senfh,
348  char const *uttid);
349 
362 POCKETSPHINX_EXPORT
363 int ps_start_utt(ps_decoder_t *ps, char const *uttid);
364 
372 POCKETSPHINX_EXPORT
373 char const *ps_get_uttid(ps_decoder_t *ps);
387 POCKETSPHINX_EXPORT
389  int16 const *data,
390  size_t n_samples,
391  int no_search,
392  int full_utt);
393 
407 POCKETSPHINX_EXPORT
409  mfcc_t **data,
410  int n_frames,
411  int no_search,
412  int full_utt);
413 
427 POCKETSPHINX_EXPORT
429 
436 POCKETSPHINX_EXPORT
437 int ps_end_utt(ps_decoder_t *ps);
438 
448 POCKETSPHINX_EXPORT
449 char const *ps_get_hyp(ps_decoder_t *ps, int32 *out_best_score,
450  char const **out_uttid);
451 
460 POCKETSPHINX_EXPORT
461 char const *ps_get_hyp_final(ps_decoder_t *ps, int32 *out_is_final);
462 
477 POCKETSPHINX_EXPORT
478 int32 ps_get_prob(ps_decoder_t *ps, char const **out_uttid);
479 
493 POCKETSPHINX_EXPORT
495 
504 POCKETSPHINX_EXPORT
505 ps_seg_t *ps_seg_iter(ps_decoder_t *ps, int32 *out_best_score);
506 
514 POCKETSPHINX_EXPORT
516 
524 POCKETSPHINX_EXPORT
525 char const *ps_seg_word(ps_seg_t *seg);
526 
538 POCKETSPHINX_EXPORT
539 void ps_seg_frames(ps_seg_t *seg, int *out_sf, int *out_ef);
540 
563 POCKETSPHINX_EXPORT
564 int32 ps_seg_prob(ps_seg_t *seg, int32 *out_ascr, int32 *out_lscr, int32 *out_lback);
565 
569 POCKETSPHINX_EXPORT
570 void ps_seg_free(ps_seg_t *seg);
571 
586 POCKETSPHINX_EXPORT
587 ps_nbest_t *ps_nbest(ps_decoder_t *ps, int sf, int ef,
588  char const *ctx1, char const *ctx2);
589 
597 POCKETSPHINX_EXPORT
599 
607 POCKETSPHINX_EXPORT
608 char const *ps_nbest_hyp(ps_nbest_t *nbest, int32 *out_score);
609 
617 POCKETSPHINX_EXPORT
618 ps_seg_t *ps_nbest_seg(ps_nbest_t *nbest, int32 *out_score);
619 
625 POCKETSPHINX_EXPORT
626 void ps_nbest_free(ps_nbest_t *nbest);
627 
636 POCKETSPHINX_EXPORT
637 void ps_get_utt_time(ps_decoder_t *ps, double *out_nspeech,
638  double *out_ncpu, double *out_nwall);
639 
648 POCKETSPHINX_EXPORT
649 void ps_get_all_time(ps_decoder_t *ps, double *out_nspeech,
650  double *out_ncpu, double *out_nwall);
651 
665 #ifdef __cplusplus
666 } /* extern "C" */
667 #endif
668 
669 #endif /* __POCKETSPHINX_H__ */
Implementation of FSG search (and "FSG set") structure.
POCKETSPHINX_EXPORT void ps_get_utt_time(ps_decoder_t *ps, double *out_nspeech, double *out_ncpu, double *out_nwall)
Get performance information for the current utterance.
POCKETSPHINX_EXPORT feat_t * ps_get_feat(ps_decoder_t *ps)
Get the dynamic feature computation object for this decoder.
Definition: pocketsphinx.c:368
POCKETSPHINX_EXPORT ps_seg_t * ps_seg_iter(ps_decoder_t *ps, int32 *out_best_score)
Get an iterator over the word segmentation for the best hypothesis.
Definition: pocketsphinx.c:910
POCKETSPHINX_EXPORT int ps_process_cep(ps_decoder_t *ps, mfcc_t **data, int n_frames, int no_search, int full_utt)
Decode acoustic feature data.
POCKETSPHINX_EXPORT arg_t const * ps_args(void)
Returns the argument definitions used in ps_init().
Definition: pocketsphinx.c:313
POCKETSPHINX_EXPORT int ps_load_dict(ps_decoder_t *ps, char const *dictfile, char const *fdictfile, char const *format)
Reload the pronunciation dictionary from a file.
Definition: pocketsphinx.c:457
POCKETSPHINX_EXPORT void ps_nbest_free(ps_nbest_t *nbest)
Finish N-best search early, releasing resources.
Definition: pocketsphinx.c:995
POCKETSPHINX_EXPORT ps_nbest_t * ps_nbest(ps_decoder_t *ps, int sf, int ef, char const *ctx1, char const *ctx2)
Get an iterator over the best hypotheses, optionally within a selected region of the utterance...
Definition: pocketsphinx.c:961
POCKETSPHINX_EXPORT ps_seg_t * ps_nbest_seg(ps_nbest_t *nbest, int32 *out_score)
Get the word segmentation from an N-best list iterator.
POCKETSPHINX_EXPORT void ps_seg_frames(ps_seg_t *seg, int *out_sf, int *out_ef)
Get inclusive start and end frames from a segmentation iterator.
Definition: pocketsphinx.c:933
POCKETSPHINX_EXPORT ps_mllr_t * ps_update_mllr(ps_decoder_t *ps, ps_mllr_t *mllr)
Adapt current acoustic model using a linear transform.
Definition: pocketsphinx.c:374
Word graph search.
POCKETSPHINX_EXPORT int ps_save_dict(ps_decoder_t *ps, char const *dictfile, char const *format)
Dump the current pronunciation dictionary to a file.
Definition: pocketsphinx.c:512
POCKETSPHINX_EXPORT int ps_decode_raw(ps_decoder_t *ps, FILE *rawfh, char const *uttid, long maxsamps)
Decode a raw audio stream.
Definition: pocketsphinx.c:580
POCKETSPHINX_EXPORT char const * ps_nbest_hyp(ps_nbest_t *nbest, int32 *out_score)
Get the hypothesis string from an N-best list iterator.
POCKETSPHINX_EXPORT ngram_model_t * ps_get_lmset(ps_decoder_t *ps)
Get the language model set object for this decoder.
Definition: pocketsphinx.c:380
A* search structure.
POCKETSPHINX_EXPORT ps_lattice_t * ps_get_lattice(ps_decoder_t *ps)
Get word lattice.
Definition: pocketsphinx.c:955
POCKETSPHINX_EXPORT ps_nbest_t * ps_nbest_next(ps_nbest_t *nbest)
Move an N-best list iterator forward.
POCKETSPHINX_EXPORT int32 ps_get_prob(ps_decoder_t *ps, char const **out_uttid)
Get posterior probability.
Definition: pocketsphinx.c:897
char const * word
Word string (pointer into dictionary hash)
POCKETSPHINX_EXPORT ngram_model_t * ps_update_lmset(ps_decoder_t *ps, ngram_model_t *lmset)
Update the language model set object for this decoder.
Definition: pocketsphinx.c:389
POCKETSPHINX_EXPORT int ps_start_utt(ps_decoder_t *ps, char const *uttid)
Start utterance processing.
Definition: pocketsphinx.c:621
POCKETSPHINX_EXPORT ps_seg_t * ps_seg_next(ps_seg_t *seg)
Get the next segment in a word segmentation.
Definition: pocketsphinx.c:921
Decoder object.
POCKETSPHINX_EXPORT int ps_decode_senscr(ps_decoder_t *ps, FILE *senfh, char const *uttid)
Decode a senone score dump file.
Definition: pocketsphinx.c:727
POCKETSPHINX_EXPORT int ps_free(ps_decoder_t *ps)
Finalize the decoder.
Definition: pocketsphinx.c:326
POCKETSPHINX_EXPORT void ps_seg_free(ps_seg_t *seg)
Finish iterating over a word segmentation early, freeing resources.
Definition: pocketsphinx.c:949
POCKETSPHINX_EXPORT fsg_set_t * ps_update_fsgset(ps_decoder_t *ps)
Update the finite-state grammar set object for this decoder.
Definition: pocketsphinx.c:432
frame_idx_t ef
End frame.
POCKETSPHINX_EXPORT ps_decoder_t * ps_retain(ps_decoder_t *ps)
Retain a pointer to the decoder.
Definition: pocketsphinx.c:319
Model-space linear transforms for speaker adaptation.
POCKETSPHINX_EXPORT cmd_ln_t * ps_get_config(ps_decoder_t *ps)
Get the configuration object for this decoder.
Definition: pocketsphinx.c:350
Feature space linear transform structure.
Definition: acmod.h:82
POCKETSPHINX_EXPORT int ps_process_raw(ps_decoder_t *ps, int16 const *data, size_t n_samples, int no_search, int full_utt)
Decode raw audio data.
Definition: pocketsphinx.c:749
Word graph structure used in bestpath/nbest search.
POCKETSPHINX_EXPORT int ps_reinit(ps_decoder_t *ps, cmd_ln_t *config)
Reinitialize the decoder with updated configuration.
Definition: pocketsphinx.c:193
POCKETSPHINX_EXPORT int ps_end_utt(ps_decoder_t *ps)
End utterance processing.
Definition: pocketsphinx.c:816
POCKETSPHINX_EXPORT int ps_add_word(ps_decoder_t *ps, char const *word, char const *phones, int update)
Add a word to the pronunciation dictionary.
Definition: pocketsphinx.c:519
POCKETSPHINX_EXPORT void ps_get_all_time(ps_decoder_t *ps, double *out_nspeech, double *out_ncpu, double *out_nwall)
Get overall performance information.
POCKETSPHINX_EXPORT logmath_t * ps_get_logmath(ps_decoder_t *ps)
Get the log-math computation object for this decoder.
Definition: pocketsphinx.c:356
POCKETSPHINX_EXPORT char const * ps_get_uttid(ps_decoder_t *ps)
Get current utterance ID.
Definition: pocketsphinx.c:344
POCKETSPHINX_EXPORT int32 ps_seg_prob(ps_seg_t *seg, int32 *out_ascr, int32 *out_lscr, int32 *out_lback)
Get language, acoustic, and posterior probabilities from a segmentation iterator. ...
Definition: pocketsphinx.c:940
POCKETSPHINX_EXPORT char const * ps_get_hyp_final(ps_decoder_t *ps, int32 *out_is_final)
Get hypothesis string and final flag.
Definition: pocketsphinx.c:885
POCKETSPHINX_EXPORT fsg_set_t * ps_get_fsgset(ps_decoder_t *ps)
Get the finite-state grammar set object for this decoder.
Definition: pocketsphinx.c:423
POCKETSPHINX_EXPORT fe_t * ps_get_fe(ps_decoder_t *ps)
Get the feature extraction object for this decoder.
Definition: pocketsphinx.c:362
POCKETSPHINX_EXPORT ps_decoder_t * ps_init(cmd_ln_t *config)
Initialize the decoder from a configuration object.
Definition: pocketsphinx.c:299
Base structure for hypothesis segmentation iterator.
POCKETSPHINX_EXPORT int ps_get_n_frames(ps_decoder_t *ps)
Get the number of frames of data searched.
POCKETSPHINX_EXPORT char const * ps_seg_word(ps_seg_t *seg)
Get word string from a segmentation iterator.
Definition: pocketsphinx.c:927
frame_idx_t sf
Start frame.
Public functions for FSG decoding.
POCKETSPHINX_EXPORT char const * ps_get_hyp(ps_decoder_t *ps, int32 *out_best_score, char const **out_uttid)
Get hypothesis string and path score.
Definition: pocketsphinx.c:872