PocketSphinx  5.0.0
A small speech recognizer
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  */
62 #ifndef __POCKETSPHINX_H__
63 #define __POCKETSPHINX_H__
64 
65 /* System headers */
66 #include <stdio.h>
67 
68 /* PocketSphinx utility headers */
69 #include <pocketsphinx/sphinx_config.h>
70 #include <pocketsphinx/prim_type.h>
71 #include <pocketsphinx/logmath.h>
72 #include <pocketsphinx/err.h>
73 
74 /* PocketSphinx API headers */
75 #include <pocketsphinx/vad.h>
77 #include <pocketsphinx/model.h>
78 #include <pocketsphinx/search.h>
79 #include <pocketsphinx/export.h>
80 #include <pocketsphinx/lattice.h>
81 #include <pocketsphinx/alignment.h>
82 #include <pocketsphinx/mllr.h>
83 
84 /* Namum manglium ii domum */
85 #ifdef __cplusplus
86 extern "C" {
87 #endif
88 #if 0
89 }
90 #endif
91 
92 /* Transparent structures */
97 typedef enum ps_type_e {
98  ARG_REQUIRED = (1<<0), /*<< Bit indicating required argument. */
99  ARG_INTEGER = (1<<1), /*<< Integer up to 64 bits. */
100  ARG_FLOATING = (1<<2), /*<< Double-precision floating point. */
101  ARG_STRING = (1<<3), /*<< String. */
102  ARG_BOOLEAN = (1<<4), /*<< Boolean (true/false). */
103  REQARG_INTEGER = (ARG_INTEGER | ARG_REQUIRED),
104  REQARG_FLOATING = (ARG_FLOATING | ARG_REQUIRED),
105  REQARG_STRING = (ARG_STRING | ARG_REQUIRED),
106  REQARG_BOOLEAN = (ARG_BOOLEAN | ARG_REQUIRED)
107 } ps_type_t;
117 typedef struct ps_arg_s {
118  char const *name;
119  int type;
120  char const *deflt;
121  char const *doc;
122 } ps_arg_t;
123 
124 /* Opaque structures */
125 
130 typedef struct cmd_ln_s ps_config_t;
131 
136 typedef struct ps_decoder_s ps_decoder_t;
137 
142 typedef struct ps_astar_s ps_nbest_t;
143 
148 typedef struct ps_seg_s ps_seg_t;
149 
161 POCKETSPHINX_EXPORT
162 ps_config_t *ps_config_init(const ps_arg_t *defn);
163 
168 POCKETSPHINX_EXPORT
170 
175 POCKETSPHINX_EXPORT
176 int ps_config_free(ps_config_t *config);
177 
187 int ps_config_validate(ps_config_t *config);
188 
216 POCKETSPHINX_EXPORT
217 ps_config_t *ps_config_parse_json(ps_config_t *config, const char *json);
218 
231 POCKETSPHINX_EXPORT
232 const char *ps_config_serialize_json(ps_config_t *config);
233 
243 POCKETSPHINX_EXPORT
244 ps_type_t ps_config_typeof(ps_config_t *config, char const *name);
245 
262 POCKETSPHINX_EXPORT
263 const anytype_t *ps_config_get(ps_config_t *config, const char *name);
264 
287 POCKETSPHINX_EXPORT
288 const anytype_t *ps_config_set(ps_config_t *config, const char *name,
289  const anytype_t *val, ps_type_t t);
290 
299 POCKETSPHINX_EXPORT
300 long ps_config_int(ps_config_t *config, const char *name);
301 
312 POCKETSPHINX_EXPORT
313 int ps_config_bool(ps_config_t *config, const char *name);
314 
323 POCKETSPHINX_EXPORT
324 double ps_config_float(ps_config_t *config, const char *name);
325 
336 POCKETSPHINX_EXPORT
337 const char *ps_config_str(ps_config_t *config, const char *name);
338 
347 POCKETSPHINX_EXPORT
348 const anytype_t *ps_config_set_int(ps_config_t *config, const char *name, long val);
349 
358 POCKETSPHINX_EXPORT
359 const anytype_t *ps_config_set_bool(ps_config_t *config, const char *name, int val);
360 
369 POCKETSPHINX_EXPORT
370 const anytype_t *ps_config_set_float(ps_config_t *config, const char *name, double val);
371 
385 POCKETSPHINX_EXPORT
386 const anytype_t *ps_config_set_str(ps_config_t *config, const char *name, const char *val);
387 
410 POCKETSPHINX_EXPORT
411 int ps_config_soundfile(ps_config_t *config, FILE *fh, const char *file);
412 
426 POCKETSPHINX_EXPORT
427 int ps_config_wavfile(ps_config_t *config, FILE *infh, const char *file);
428 
442 POCKETSPHINX_EXPORT
443 int ps_config_nistfile(ps_config_t *config, FILE *infh, const char *file);
444 
464 POCKETSPHINX_EXPORT
465 void ps_default_search_args(ps_config_t *config);
466 
472 POCKETSPHINX_EXPORT
473 void ps_expand_model_config(ps_config_t *config);
474 
483 POCKETSPHINX_EXPORT
484 const char *ps_default_modeldir(void);
485 
497 POCKETSPHINX_EXPORT
499 
523 POCKETSPHINX_EXPORT
524 int ps_reinit(ps_decoder_t *ps, ps_config_t *config);
525 
547 POCKETSPHINX_EXPORT
548 int ps_reinit_feat(ps_decoder_t *ps, ps_config_t *config);
549 
569 POCKETSPHINX_EXPORT
570 const char *ps_get_cmn(ps_decoder_t *ps, int update);
571 
587 POCKETSPHINX_EXPORT
588 int ps_set_cmn(ps_decoder_t *ps, const char *cmn);
589 
598 POCKETSPHINX_EXPORT
599 ps_arg_t const *ps_args(void);
600 
612 POCKETSPHINX_EXPORT
614 
624 POCKETSPHINX_EXPORT
625 int ps_free(ps_decoder_t *ps);
626 
636 POCKETSPHINX_EXPORT
638 
648 POCKETSPHINX_EXPORT
650 
662 POCKETSPHINX_EXPORT
664 
680 POCKETSPHINX_EXPORT
681 int ps_load_dict(ps_decoder_t *ps, char const *dictfile,
682  char const *fdictfile, char const *format);
683 
694 POCKETSPHINX_EXPORT
695 int ps_save_dict(ps_decoder_t *ps, char const *dictfile, char const *format);
696 
717 POCKETSPHINX_EXPORT
718 int ps_add_word(ps_decoder_t *ps,
719  char const *word,
720  char const *phones,
721  int update);
722 
735 POCKETSPHINX_EXPORT
736 char *ps_lookup_word(ps_decoder_t *ps,
737  const char *word);
738 
754 POCKETSPHINX_EXPORT
755 long ps_decode_raw(ps_decoder_t *ps, FILE *rawfh,
756  long maxsamps);
757 
766 POCKETSPHINX_EXPORT
767 int ps_decode_senscr(ps_decoder_t *ps, FILE *senfh);
768 
779 POCKETSPHINX_EXPORT
781 
795 POCKETSPHINX_EXPORT
797 
809 POCKETSPHINX_EXPORT
810 int ps_start_utt(ps_decoder_t *ps);
811 
828 POCKETSPHINX_EXPORT
830  int16 const *data,
831  size_t n_samples,
832  int no_search,
833  int full_utt);
834 
855 POCKETSPHINX_EXPORT
857  float32 **data,
858  int n_frames,
859  int no_search,
860  int full_utt);
861 
876 POCKETSPHINX_EXPORT
878 
886 POCKETSPHINX_EXPORT
887 int ps_end_utt(ps_decoder_t *ps);
888 
900 POCKETSPHINX_EXPORT
901 char const *ps_get_hyp(ps_decoder_t *ps, int32 *out_best_score);
902 
917 POCKETSPHINX_EXPORT
918 int32 ps_get_prob(ps_decoder_t *ps);
919 
931 POCKETSPHINX_EXPORT
933 
942 POCKETSPHINX_EXPORT
944 
953 POCKETSPHINX_EXPORT
955 
964 POCKETSPHINX_EXPORT
965 char const *ps_seg_word(ps_seg_t *seg);
966 
979 POCKETSPHINX_EXPORT
980 void ps_seg_frames(ps_seg_t *seg, int *out_sf, int *out_ef);
981 
1005 POCKETSPHINX_EXPORT
1006 int32 ps_seg_prob(ps_seg_t *seg, int32 *out_ascr, int32 *out_lscr, int32 *out_lback);
1007 
1012 POCKETSPHINX_EXPORT
1013 void ps_seg_free(ps_seg_t *seg);
1014 
1024 POCKETSPHINX_EXPORT
1026 
1035 POCKETSPHINX_EXPORT
1037 
1047 POCKETSPHINX_EXPORT
1048 char const *ps_nbest_hyp(ps_nbest_t *nbest, int32 *out_score);
1049 
1057 POCKETSPHINX_EXPORT
1059 
1066 POCKETSPHINX_EXPORT
1067 void ps_nbest_free(ps_nbest_t *nbest);
1068 
1078 POCKETSPHINX_EXPORT
1079 void ps_get_utt_time(ps_decoder_t *ps, double *out_nspeech,
1080  double *out_ncpu, double *out_nwall);
1081 
1091 POCKETSPHINX_EXPORT
1092 void ps_get_all_time(ps_decoder_t *ps, double *out_nspeech,
1093  double *out_ncpu, double *out_nwall);
1094 
1309 #ifdef __cplusplus
1310 } /* extern "C" */
1311 #endif
1312 
1313 #endif /* __POCKETSPHINX_H__ */
ps_decoder_t::ps_decode_senscr
POCKETSPHINX_EXPORT int ps_decode_senscr(ps_decoder_t *ps, FILE *senfh)
ps_decoder_t::ps_reinit_feat
POCKETSPHINX_EXPORT int ps_reinit_feat(ps_decoder_t *ps, ps_config_t *config)
ps_decoder_t::ps_get_utt_time
POCKETSPHINX_EXPORT void ps_get_utt_time(ps_decoder_t *ps, double *out_nspeech, double *out_ncpu, double *out_nwall)
ps_config_t::ps_config_set_bool
const POCKETSPHINX_EXPORT anytype_t * ps_config_set_bool(ps_config_t *config, const char *name, int val)
ps_config_t::ps_expand_model_config
POCKETSPHINX_EXPORT void ps_expand_model_config(ps_config_t *config)
ps_decoder_t::ps_process_raw
POCKETSPHINX_EXPORT int ps_process_raw(ps_decoder_t *ps, int16 const *data, size_t n_samples, int no_search, int full_utt)
ps_config_t::ps_config_set_float
const POCKETSPHINX_EXPORT anytype_t * ps_config_set_float(ps_config_t *config, const char *name, double val)
ps_config_t::ps_config_init
POCKETSPHINX_EXPORT ps_config_t * ps_config_init(const ps_arg_t *defn)
ps_config_t::ps_config_retain
POCKETSPHINX_EXPORT ps_config_t * ps_config_retain(ps_config_t *config)
ps_decoder_t::ps_get_hyp
POCKETSPHINX_EXPORT const char * ps_get_hyp(ps_decoder_t *ps, int32 *out_best_score)
ps_arg_t
Definition of a configuration parameter.
ps_config_t::ps_config_get
const POCKETSPHINX_EXPORT anytype_t * ps_config_get(ps_config_t *config, const char *name)
prim_type.h
Basic type definitions used in Sphinx.
model.h
Public API for language models.
ps_config_t::ps_config_serialize_json
const POCKETSPHINX_EXPORT char * ps_config_serialize_json(ps_config_t *config)
ps_decoder_t::ps_lookup_word
POCKETSPHINX_EXPORT char * ps_lookup_word(ps_decoder_t *ps, const char *word)
ps_decoder_t::ps_process_cep
POCKETSPHINX_EXPORT int ps_process_cep(ps_decoder_t *ps, float32 **data, int n_frames, int no_search, int full_utt)
ps_config_t::ps_config_soundfile
POCKETSPHINX_EXPORT int ps_config_soundfile(ps_config_t *config, FILE *fh, const char *file)
ps_decoder_t::ps_get_n_frames
POCKETSPHINX_EXPORT int ps_get_n_frames(ps_decoder_t *ps)
ps_type_t
enum ps_type_e ps_type_t
Types of configuration parameters.
ps_config_t::ps_config_float
POCKETSPHINX_EXPORT double ps_config_float(ps_config_t *config, const char *name)
ps_decoder_t::ps_retain
POCKETSPHINX_EXPORT ps_decoder_t * ps_retain(ps_decoder_t *ps)
anytype_t
Literally any type!
alignment.h
Multi-level alignment structure.
ps_config_t::ps_config_free
POCKETSPHINX_EXPORT int ps_config_free(ps_config_t *config)
ps_decoder_t::ps_set_cmn
POCKETSPHINX_EXPORT int ps_set_cmn(ps_decoder_t *ps, const char *cmn)
ps_seg_t::ps_seg_next
POCKETSPHINX_EXPORT ps_seg_t * ps_seg_next(ps_seg_t *seg)
ps_decoder_t::ps_get_all_time
POCKETSPHINX_EXPORT void ps_get_all_time(ps_decoder_t *ps, double *out_nspeech, double *out_ncpu, double *out_nwall)
logmath.h
Fast integer logarithmic addition operations.
ps_seg_t::ps_seg_word
POCKETSPHINX_EXPORT const char * ps_seg_word(ps_seg_t *seg)
ps_config_t::ps_config_set_str
const POCKETSPHINX_EXPORT anytype_t * ps_config_set_str(ps_config_t *config, const char *name, const char *val)
ps_type_e
ps_type_e
Types of configuration parameters.
Definition: pocketsphinx.h:97
ps_decoder_t::ps_free
POCKETSPHINX_EXPORT int ps_free(ps_decoder_t *ps)
ps_config_t::ps_config_wavfile
POCKETSPHINX_EXPORT int ps_config_wavfile(ps_config_t *config, FILE *infh, const char *file)
ps_decoder_t::ps_nbest
POCKETSPHINX_EXPORT ps_nbest_t * ps_nbest(ps_decoder_t *ps)
vad.h
Simple voice activity detection.
ps_decoder_t::ps_add_word
POCKETSPHINX_EXPORT int ps_add_word(ps_decoder_t *ps, char const *word, char const *phones, int update)
ps_seg_t::ps_seg_prob
POCKETSPHINX_EXPORT int32 ps_seg_prob(ps_seg_t *seg, int32 *out_ascr, int32 *out_lscr, int32 *out_lback)
ps_config_t::ps_config_validate
int ps_config_validate(ps_config_t *config)
endpointer.h
VAD-based endpointer for PocketSphinx.
ps_config_t::ps_config_nistfile
POCKETSPHINX_EXPORT int ps_config_nistfile(ps_config_t *config, FILE *infh, const char *file)
ps_seg_t::ps_seg_free
POCKETSPHINX_EXPORT void ps_seg_free(ps_seg_t *seg)
ps_decoder_t::ps_reinit
POCKETSPHINX_EXPORT int ps_reinit(ps_decoder_t *ps, ps_config_t *config)
ps_seg_t
Segmentation iterator object.
mllr.h
Model-space linear transforms for speaker adaptation.
ps_decoder_t::ps_get_logmath
POCKETSPHINX_EXPORT logmath_t * ps_get_logmath(ps_decoder_t *ps)
ps_seg_t::ps_seg_frames
POCKETSPHINX_EXPORT void ps_seg_frames(ps_seg_t *seg, int *out_sf, int *out_ef)
lattice.h
Word lattices.
ps_config_t::ps_config_typeof
POCKETSPHINX_EXPORT ps_type_t ps_config_typeof(ps_config_t *config, char const *name)
ps_config_t::ps_config_set
const POCKETSPHINX_EXPORT anytype_t * ps_config_set(ps_config_t *config, const char *name, const anytype_t *val, ps_type_t t)
ps_config_t
configuration object.
ps_config_t::ps_config_int
POCKETSPHINX_EXPORT long ps_config_int(ps_config_t *config, const char *name)
err.h
Implementation of logging routines.
ps_lattice_t
Word graph structure used in bestpath/nbest search.
ps_nbest_t::ps_nbest_hyp
POCKETSPHINX_EXPORT const char * ps_nbest_hyp(ps_nbest_t *nbest, int32 *out_score)
ps_decoder_t::ps_save_dict
POCKETSPHINX_EXPORT int ps_save_dict(ps_decoder_t *ps, char const *dictfile, char const *format)
ps_decoder_t::ps_start_stream
POCKETSPHINX_EXPORT int ps_start_stream(ps_decoder_t *ps)
ps_config_t::ps_config_set_int
const POCKETSPHINX_EXPORT anytype_t * ps_config_set_int(ps_config_t *config, const char *name, long val)
ps_nbest_t::ps_nbest_free
POCKETSPHINX_EXPORT void ps_nbest_free(ps_nbest_t *nbest)
ps_decoder_t::ps_get_prob
POCKETSPHINX_EXPORT int32 ps_get_prob(ps_decoder_t *ps)
logmath_t
Integer log math computation class.
ps_config_t::ps_args
POCKETSPHINX_EXPORT const ps_arg_t * ps_args(void)
ps_decoder_t::ps_update_mllr
POCKETSPHINX_EXPORT ps_mllr_t * ps_update_mllr(ps_decoder_t *ps, ps_mllr_t *mllr)
ps_decoder_t::ps_get_config
POCKETSPHINX_EXPORT ps_config_t * ps_get_config(ps_decoder_t *ps)
ps_decoder_t::ps_decode_raw
POCKETSPHINX_EXPORT long ps_decode_raw(ps_decoder_t *ps, FILE *rawfh, long maxsamps)
ps_config_t::ps_config_str
const POCKETSPHINX_EXPORT char * ps_config_str(ps_config_t *config, const char *name)
ps_decoder_t::ps_get_lattice
POCKETSPHINX_EXPORT ps_lattice_t * ps_get_lattice(ps_decoder_t *ps)
ps_nbest_t
N-best hypothesis iterator object.
ps_nbest_t::ps_nbest_seg
POCKETSPHINX_EXPORT ps_seg_t * ps_nbest_seg(ps_nbest_t *nbest)
ps_config_t::ps_config_bool
POCKETSPHINX_EXPORT int ps_config_bool(ps_config_t *config, const char *name)
ps_config_t::ps_config_parse_json
POCKETSPHINX_EXPORT ps_config_t * ps_config_parse_json(ps_config_t *config, const char *json)
ps_decoder_t::ps_start_utt
POCKETSPHINX_EXPORT int ps_start_utt(ps_decoder_t *ps)
ps_config_t::ps_init
POCKETSPHINX_EXPORT ps_decoder_t * ps_init(ps_config_t *config)
ps_mllr_t
Linear transform object.
ps_decoder_t::ps_seg_iter
POCKETSPHINX_EXPORT ps_seg_t * ps_seg_iter(ps_decoder_t *ps)
ps_config_t::ps_default_modeldir
const POCKETSPHINX_EXPORT char * ps_default_modeldir(void)
ps_decoder_t
Speech recognizer object.
ps_decoder_t::ps_end_utt
POCKETSPHINX_EXPORT int ps_end_utt(ps_decoder_t *ps)
ps_config_t::ps_default_search_args
POCKETSPHINX_EXPORT void ps_default_search_args(ps_config_t *config)
ps_decoder_t::ps_get_in_speech
POCKETSPHINX_EXPORT int ps_get_in_speech(ps_decoder_t *ps)
ps_decoder_t::ps_get_cmn
const POCKETSPHINX_EXPORT char * ps_get_cmn(ps_decoder_t *ps, int update)
ps_decoder_t::ps_load_dict
POCKETSPHINX_EXPORT int ps_load_dict(ps_decoder_t *ps, char const *dictfile, char const *fdictfile, char const *format)
search.h
Search modules.
ps_nbest_t::ps_nbest_next
POCKETSPHINX_EXPORT ps_nbest_t * ps_nbest_next(ps_nbest_t *nbest)