PocketSphinx  5prealpha
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 
42 /* System headers we need. */
43 #include <stdio.h>
44 
45 /* SphinxBase headers we need. */
46 #include <sphinxbase/cmd_ln.h>
47 #include <sphinxbase/logmath.h>
48 #include <sphinxbase/fe.h>
49 #include <sphinxbase/feat.h>
50 
51 /* PocketSphinx headers (not many of them!) */
52 #include <pocketsphinx_export.h>
53 #include <cmdln_macro.h>
54 #include <ps_lattice.h>
55 #include <ps_mllr.h>
56 
57 #ifdef __cplusplus
58 extern "C" {
59 #endif
60 #if 0
61 }
62 #endif
63 
67 typedef struct ps_decoder_s ps_decoder_t;
68 
69 #include <ps_search.h>
70 
74 typedef struct ps_astar_s ps_nbest_t;
75 
79 typedef struct ps_seg_s ps_seg_t;
80 
85 POCKETSPHINX_EXPORT void
86 ps_default_search_args(cmd_ln_t *);
87 
98 POCKETSPHINX_EXPORT
99 ps_decoder_t *ps_init(cmd_ln_t *config);
100 
118 POCKETSPHINX_EXPORT
119 int ps_reinit(ps_decoder_t *ps, cmd_ln_t *config);
120 
127 POCKETSPHINX_EXPORT
128 arg_t const *ps_args(void);
129 
140 POCKETSPHINX_EXPORT
142 
153 POCKETSPHINX_EXPORT
154 int ps_free(ps_decoder_t *ps);
155 
164 POCKETSPHINX_EXPORT
165 cmd_ln_t *ps_get_config(ps_decoder_t *ps);
166 
175 POCKETSPHINX_EXPORT
176 logmath_t *ps_get_logmath(ps_decoder_t *ps);
177 
186 POCKETSPHINX_EXPORT
187 fe_t *ps_get_fe(ps_decoder_t *ps);
188 
197 POCKETSPHINX_EXPORT
198 feat_t *ps_get_feat(ps_decoder_t *ps);
199 
211 POCKETSPHINX_EXPORT
213 
228 POCKETSPHINX_EXPORT
229 int ps_load_dict(ps_decoder_t *ps, char const *dictfile,
230  char const *fdictfile, char const *format);
231 
241 POCKETSPHINX_EXPORT
242 int ps_save_dict(ps_decoder_t *ps, char const *dictfile, char const *format);
243 
263 POCKETSPHINX_EXPORT
264 int ps_add_word(ps_decoder_t *ps,
265  char const *word,
266  char const *phones,
267  int update);
268 
280 POCKETSPHINX_EXPORT
281 char *ps_lookup_word(ps_decoder_t *ps,
282  const char *word);
283 
298 POCKETSPHINX_EXPORT
299 long ps_decode_raw(ps_decoder_t *ps, FILE *rawfh,
300  long maxsamps);
301 
309 POCKETSPHINX_EXPORT
310 int ps_decode_senscr(ps_decoder_t *ps, FILE *senfh);
311 
319 POCKETSPHINX_EXPORT
321 
332 POCKETSPHINX_EXPORT
333 int ps_start_utt(ps_decoder_t *ps);
334 
348 POCKETSPHINX_EXPORT
350  int16 const *data,
351  size_t n_samples,
352  int no_search,
353  int full_utt);
354 
368 POCKETSPHINX_EXPORT
370  mfcc_t **data,
371  int n_frames,
372  int no_search,
373  int full_utt);
374 
388 POCKETSPHINX_EXPORT
390 
397 POCKETSPHINX_EXPORT
398 int ps_end_utt(ps_decoder_t *ps);
399 
408 POCKETSPHINX_EXPORT
409 char const *ps_get_hyp(ps_decoder_t *ps, int32 *out_best_score);
410 
424 POCKETSPHINX_EXPORT
425 int32 ps_get_prob(ps_decoder_t *ps);
426 
440 POCKETSPHINX_EXPORT
442 
450 POCKETSPHINX_EXPORT
452 
460 POCKETSPHINX_EXPORT
462 
470 POCKETSPHINX_EXPORT
471 char const *ps_seg_word(ps_seg_t *seg);
472 
484 POCKETSPHINX_EXPORT
485 void ps_seg_frames(ps_seg_t *seg, int *out_sf, int *out_ef);
486 
509 POCKETSPHINX_EXPORT
510 int32 ps_seg_prob(ps_seg_t *seg, int32 *out_ascr, int32 *out_lscr, int32 *out_lback);
511 
515 POCKETSPHINX_EXPORT
516 void ps_seg_free(ps_seg_t *seg);
517 
526 POCKETSPHINX_EXPORT
528 
536 POCKETSPHINX_EXPORT
538 
546 POCKETSPHINX_EXPORT
547 char const *ps_nbest_hyp(ps_nbest_t *nbest, int32 *out_score);
548 
556 POCKETSPHINX_EXPORT
558 
564 POCKETSPHINX_EXPORT
565 void ps_nbest_free(ps_nbest_t *nbest);
566 
575 POCKETSPHINX_EXPORT
576 void ps_get_utt_time(ps_decoder_t *ps, double *out_nspeech,
577  double *out_ncpu, double *out_nwall);
578 
587 POCKETSPHINX_EXPORT
588 void ps_get_all_time(ps_decoder_t *ps, double *out_nspeech,
589  double *out_ncpu, double *out_nwall);
590 
597 POCKETSPHINX_EXPORT
598 uint8 ps_get_in_speech(ps_decoder_t *ps);
599 
600 
608 POCKETSPHINX_EXPORT
609 void ps_set_rawdata_size(ps_decoder_t *ps, int32 size);
610 
611 
620 POCKETSPHINX_EXPORT
621 void ps_get_rawdata(ps_decoder_t *ps, int16 **buffer, int32 *size);
622 
637 #ifdef __cplusplus
638 } /* extern "C" */
639 #endif
640 
641 #endif /* __POCKETSPHINX_H__ */
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:455
POCKETSPHINX_EXPORT void ps_set_rawdata_size(ps_decoder_t *ps, int32 size)
Sets the limit of the raw audio data to store in decoder to retrieve it later on ps_get_rawdata.
User can configure several &quot;search&quot; objects with different grammars and langauge models and switch th...
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:407
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:732
POCKETSPHINX_EXPORT void ps_nbest_free(ps_nbest_t *nbest)
Finish N-best search early, releasing resources.
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.
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:461
Word graph search.
POCKETSPHINX_EXPORT uint8 ps_get_in_speech(ps_decoder_t *ps)
Checks if the last feed audio buffer contained speech.
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:785
POCKETSPHINX_EXPORT void ps_default_search_args(cmd_ln_t *)
Sets default grammar and language model if they are not set explicitly and are present in the default...
Definition: pocketsphinx.c:188
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 char * ps_lookup_word(ps_decoder_t *ps, const char *word)
Lookup for the word in the dictionary and return phone transcription for it.
Definition: pocketsphinx.c:860
A* search structure.
POCKETSPHINX_EXPORT ps_lattice_t * ps_get_lattice(ps_decoder_t *ps)
Get word lattice.
POCKETSPHINX_EXPORT ps_nbest_t * ps_nbest_next(ps_nbest_t *nbest)
Move an N-best list iterator forward.
POCKETSPHINX_EXPORT long ps_decode_raw(ps_decoder_t *ps, FILE *rawfh, long maxsamps)
Decode a raw audio stream.
Definition: pocketsphinx.c:883
char const * word
Word string (pointer into dictionary hash)
POCKETSPHINX_EXPORT int32 ps_get_prob(ps_decoder_t *ps)
Get posterior probability.
POCKETSPHINX_EXPORT ps_seg_t * ps_seg_next(ps_seg_t *seg)
Get the next segment in a word segmentation.
POCKETSPHINX_EXPORT char const * ps_get_hyp(ps_decoder_t *ps, int32 *out_best_score)
Get hypothesis string and path score.
Decoder object.
POCKETSPHINX_EXPORT int ps_free(ps_decoder_t *ps)
Finalize the decoder.
Definition: pocketsphinx.c:420
POCKETSPHINX_EXPORT void ps_seg_free(ps_seg_t *seg)
Finish iterating over a word segmentation early, freeing resources.
POCKETSPHINX_EXPORT ps_decoder_t * ps_retain(ps_decoder_t *ps)
Retain a pointer to the decoder.
Definition: pocketsphinx.c:413
Model-space linear transforms for speaker adaptation.
POCKETSPHINX_EXPORT ps_seg_t * ps_nbest_seg(ps_nbest_t *nbest)
Get the word segmentation from an N-best list iterator.
POCKETSPHINX_EXPORT ps_seg_t * ps_seg_iter(ps_decoder_t *ps)
Get an iterator over the word segmentation for the best hypothesis.
POCKETSPHINX_EXPORT cmd_ln_t * ps_get_config(ps_decoder_t *ps)
Get the configuration object for this decoder.
Definition: pocketsphinx.c:437
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.
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:218
POCKETSPHINX_EXPORT int ps_end_utt(ps_decoder_t *ps)
End utterance processing.
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:792
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:443
POCKETSPHINX_EXPORT ps_nbest_t * ps_nbest(ps_decoder_t *ps)
Get an iterator over the best hypotheses.
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. ...
POCKETSPHINX_EXPORT int ps_start_stream(ps_decoder_t *ps)
Start processing of the stream of speech.
Definition: pocketsphinx.c:926
POCKETSPHINX_EXPORT fe_t * ps_get_fe(ps_decoder_t *ps)
Get the feature extraction object for this decoder.
Definition: pocketsphinx.c:449
POCKETSPHINX_EXPORT int ps_start_utt(ps_decoder_t *ps)
Start utterance processing.
Definition: pocketsphinx.c:933
POCKETSPHINX_EXPORT ps_decoder_t * ps_init(cmd_ln_t *config)
Initialize the decoder from a configuration object.
Definition: pocketsphinx.c:388
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 int ps_decode_senscr(ps_decoder_t *ps, FILE *senfh)
Decode a senone score dump file.
POCKETSPHINX_EXPORT char const * ps_seg_word(ps_seg_t *seg)
Get word string from a segmentation iterator.
POCKETSPHINX_EXPORT void ps_get_rawdata(ps_decoder_t *ps, int16 **buffer, int32 *size)
Retrieves the raw data collected during utterance decoding.