pocketsphinx.h File Reference

Main header file for the PocketSphinx decoder. More...

`#include <stdio.h>`
`#include <sphinxbase/cmd_ln.h>`
`#include <sphinxbase/logmath.h>`
`#include <sphinxbase/fe.h>`
`#include <sphinxbase/feat.h>`
`#include <pocketsphinx_export.h>`
`#include <cmdln_macro.h>`
`#include <ps_lattice.h>`
`#include <ps_mllr.h>`
`#include <ps_search.h>`

Go to the source code of this file.

## Typedefs

typedef struct ps_decoder_s | ps_decoder_t
| PocketSphinx speech recognizer object.
typedef struct ps_astar_s | ps_nbest_t
| PocketSphinx N-best hypothesis iterator object.
typedef struct ps_seg_s | ps_seg_t
| PocketSphinx segmentation iterator object.

## Functions

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 search path.
POCKETSPHINX_EXPORT ps_decoder_t * | ps_init (cmd_ln_t *config)
| Initialize the decoder from a configuration object. More...
POCKETSPHINX_EXPORT int | ps_reinit (ps_decoder_t *ps, cmd_ln_t *config)
| Reinitialize the decoder with updated configuration. More...
POCKETSPHINX_EXPORT arg_t const * | ps_args (void)
| Returns the argument definitions used in ps_init(). More...
POCKETSPHINX_EXPORT ps_decoder_t * | ps_retain (ps_decoder_t *ps)
| Retain a pointer to the decoder. More...
POCKETSPHINX_EXPORT int | ps_free (ps_decoder_t *ps)
| Finalize the decoder. More...
POCKETSPHINX_EXPORT cmd_ln_t * | ps_get_config (ps_decoder_t *ps)
| Get the configuration object for this decoder. More...
POCKETSPHINX_EXPORT logmath_t * | ps_get_logmath (ps_decoder_t *ps)
| Get the log-math computation object for this decoder. More...
POCKETSPHINX_EXPORT fe_t * | ps_get_fe (ps_decoder_t *ps)
| Get the feature extraction object for this decoder. More...
POCKETSPHINX_EXPORT feat_t * | ps_get_feat (ps_decoder_t *ps)
| Get the dynamic feature computation object for this decoder. More...
POCKETSPHINX_EXPORT ps_mllr_t * | ps_update_mllr (ps_decoder_t *ps, ps_mllr_t *mllr)
| Adapt current acoustic model using a linear transform. More...
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. More...
POCKETSPHINX_EXPORT int | ps_save_dict (ps_decoder_t *ps, char const *dictfile, char const *format)
| Dump the current pronunciation dictionary to a file. More...
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. More...
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. More...
POCKETSPHINX_EXPORT long | ps_decode_raw (ps_decoder_t *ps, FILE *rawfh, long maxsamps)
| Decode a raw audio stream. More...
POCKETSPHINX_EXPORT int | ps_decode_senscr (ps_decoder_t *ps, FILE *senfh)
| Decode a senone score dump file. More...
POCKETSPHINX_EXPORT int | ps_start_stream (ps_decoder_t *ps)
| Start processing of the stream of speech. More...
POCKETSPHINX_EXPORT int | ps_start_utt (ps_decoder_t *ps)
| Start utterance processing. More...
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. More...
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. More...
POCKETSPHINX_EXPORT int | ps_get_n_frames (ps_decoder_t *ps)
| Get the number of frames of data searched. More...
POCKETSPHINX_EXPORT int | ps_end_utt (ps_decoder_t *ps)
| End utterance processing. More...
POCKETSPHINX_EXPORT char const * | ps_get_hyp (ps_decoder_t *ps, int32 *out_best_score)
| Get hypothesis string and path score. More...
POCKETSPHINX_EXPORT char const * | ps_get_hyp_final (ps_decoder_t *ps, int32 *out_is_final)
| Get hypothesis string and final flag. More...
POCKETSPHINX_EXPORT int32 | ps_get_prob (ps_decoder_t *ps)
| Get posterior probability. More...
POCKETSPHINX_EXPORT ps_lattice_t * | ps_get_lattice (ps_decoder_t *ps)
| Get word lattice. More...
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. More...
POCKETSPHINX_EXPORT ps_seg_t * | ps_seg_next (ps_seg_t *seg)
| Get the next segment in a word segmentation. More...
POCKETSPHINX_EXPORT char const * | ps_seg_word (ps_seg_t *seg)
| Get word string from a segmentation iterator. More...
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. More...
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. More...
POCKETSPHINX_EXPORT void | ps_seg_free (ps_seg_t *seg)
| Finish iterating over a word segmentation early, freeing resources.
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. More...
POCKETSPHINX_EXPORT ps_nbest_t * | ps_nbest_next (ps_nbest_t *nbest)
| Move an N-best list iterator forward. More...
POCKETSPHINX_EXPORT char const * | ps_nbest_hyp (ps_nbest_t *nbest, int32 *out_score)
| Get the hypothesis string from an N-best list iterator. More...
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. More...
POCKETSPHINX_EXPORT void | ps_nbest_free (ps_nbest_t *nbest)
| Finish N-best search early, releasing resources. More...
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. More...
POCKETSPHINX_EXPORT void | ps_get_all_time (ps_decoder_t *ps, double *out_nspeech, double *out_ncpu, double *out_nwall)
| Get overall performance information. More...
POCKETSPHINX_EXPORT uint8 | ps_get_in_speech (ps_decoder_t *ps)
| Checks if the last feed audio buffer contained speech. More...
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. More...
POCKETSPHINX_EXPORT void | ps_get_rawdata (ps_decoder_t *ps, int16 **buffer, int32 *size)
| Retrieves the raw data collected during utterance decoding. More...

## Detailed Description

Main header file for the PocketSphinx decoder.

Definition in file pocketsphinx.h.

## Function Documentation

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.

This function adds a word to the pronunciation dictionary and the current language model (but, obviously, not to the current FSG if FSG mode is enabled). If the word is already present in one or the other, it does whatever is necessary to ensure that the word can be recognized.

Parameters

  word | Word string to add.
  phones | Whitespace-separated list of phoneme strings describing pronunciation of `word`.
  update | If TRUE, update the search module (whichever one is currently active) to recognize the newly added word. If adding multiple words, it is more efficient to pass FALSE here in all but the last word.

Returns
  The internal ID (>= 0) of the newly added word, or <0 on failure.

Definition at line 804 of file pocketsphinx.c.

References ps_decoder_s::acmod, bin_mdef_ciphone_id(), ps_decoder_s::d2p, ps_decoder_s::dict, dict2pid_add_word(), dict_add_word(), acmod_s::mdef, and ps_decoder_s::searches.

POCKETSPHINX_EXPORT arg_t const* ps_args | ( | void |  | ) |

Returns the argument definitions used in ps_init().

This is here to avoid exporting global data, which is problematic on Win32 and Symbian (and possibly other platforms).

Definition at line 423 of file pocketsphinx.c.

Referenced by ps_load_dict().

POCKETSPHINX_EXPORT long ps_decode_raw | ( | ps_decoder_t * | ps,
|  | FILE * | rawfh,
|  | long | maxsamps
| ) |  |

Decode a raw audio stream.

No headers are recognized in this files. The configuration parameters `-samprate` and `-input_endian` are used to determine the sampling rate and endianness of the stream, respectively. Audio is always assumed to be 16-bit signed PCM.

Parameters

  ps | Decoder.
  rawfh | Previously opened file stream.
  maxsamps | Maximum number of samples to read from rawfh, or -1 to read until end-of-file.

Returns
  Number of samples of audio.

Definition at line 895 of file pocketsphinx.c.

References ps_end_utt(), ps_process_raw(), ps_start_stream(), and ps_start_utt().

POCKETSPHINX_EXPORT int ps_decode_senscr | ( | ps_decoder_t * | ps,
|  | FILE * | senfh
| ) |  |

Decode a senone score dump file.

Parameters

  ps | Decoder
  fh | Previously opened file handle positioned at start of file.

Returns
  Number of frames read.

Definition at line 1048 of file pocketsphinx.c.

References ps_decoder_s::acmod, acmod_read_scores(), acmod_set_insenfh(), ps_end_utt(), and ps_start_utt().

POCKETSPHINX_EXPORT int ps_end_utt | ( | ps_decoder_t * | ps | ) |

End utterance processing.

Parameters

  ps | Decoder.

Returns
  0 for success, <0 on error

Definition at line 1136 of file pocketsphinx.c.

References ps_decoder_s::acmod, acmod_end_utt(), ACMOD_ENDED, ACMOD_IDLE, ps_decoder_s::config, acmod_s::output_frame, ps_decoder_s::perf, ps_decoder_s::phone_loop, ps_decoder_s::pl_window, ps_get_hyp(), ps_get_logmath(), ps_seg_frames(), ps_seg_iter(), ps_seg_next(), ps_seg_prob(), ps_seg_word(), ps_decoder_s::search, and acmod_s::state.

Referenced by ps_decode_raw(), and ps_decode_senscr().

POCKETSPHINX_EXPORT int ps_free | ( | ps_decoder_t * | ps | ) |

Finalize the decoder.

This releases all resources associated with the decoder, including any language models or grammars which have been added to it, and the initial configuration object passed to ps_init().

Parameters

  ps | Decoder to be freed.

Returns
  New reference count (0 if freed).

Definition at line 436 of file pocketsphinx.c.

References ps_decoder_s::acmod, acmod_free(), ps_decoder_s::config, ps_decoder_s::d2p, ps_decoder_s::dict, dict2pid_free(), dict_free(), ps_decoder_s::lmath, and ps_decoder_s::refcount.

Referenced by ps_init().

POCKETSPHINX_EXPORT void ps_get_all_time | ( | ps_decoder_t * | ps,
|  | double * | out_nspeech,
|  | double * | out_ncpu,
|  | double * | out_nwall
| ) |  |

Get overall performance information.

Parameters

  ps | Decoder.
  out_nspeech | Output: Number of seconds of speech.
  out_ncpu | Output: Number of seconds of CPU time used.
  out_nwall | Output: Number of seconds of wall time used.

Definition at line 1379 of file pocketsphinx.c.

References ps_decoder_s::config, ps_decoder_s::n_frame, and ps_decoder_s::perf.

POCKETSPHINX_EXPORT cmd_ln_t* ps_get_config | ( | ps_decoder_t * | ps | ) |

Get the configuration object for this decoder.

Returns
  The configuration object for this decoder. The decoder retains ownership of this pointer, so you should not attempt to free it manually. Use cmd_ln_retain() if you wish to reuse it elsewhere.

Definition at line 453 of file pocketsphinx.c.

References ps_decoder_s::config.

POCKETSPHINX_EXPORT fe_t* ps_get_fe | ( | ps_decoder_t * | ps | ) |

Get the feature extraction object for this decoder.

Returns
  The feature extraction object for this decoder. The decoder retains ownership of this pointer, so you should not attempt to free it manually. Use fe_retain() if you wish to reuse it elsewhere.

Definition at line 465 of file pocketsphinx.c.

References ps_decoder_s::acmod, and acmod_s::fe.

POCKETSPHINX_EXPORT feat_t* ps_get_feat | ( | ps_decoder_t * | ps | ) |

Get the dynamic feature computation object for this decoder.

Returns
  The dynamic feature computation object for this decoder. The decoder retains ownership of this pointer, so you should not attempt to free it manually. Use feat_retain() if you wish to reuse it elsewhere.

Definition at line 471 of file pocketsphinx.c.

References ps_decoder_s::acmod, and acmod_s::fcb.

POCKETSPHINX_EXPORT char const* ps_get_hyp | ( | ps_decoder_t * | ps,
|  | int32 * | out_best_score
| ) |  |

Get hypothesis string and path score.

Parameters

  ps | Decoder.
  out_best_score | Output: path score corresponding to returned string.

Returns
  String containing best hypothesis at this point in decoding. NULL if no hypothesis is available.

Definition at line 1202 of file pocketsphinx.c.

References ps_decoder_s::perf, and ps_decoder_s::search.

Referenced by ps_end_utt().

POCKETSPHINX_EXPORT char const* ps_get_hyp_final | ( | ps_decoder_t * | ps,
|  | int32 * | out_is_final
| ) |  |

Get hypothesis string and final flag.

Parameters

  ps | Decoder.
  out_is_best_score | Output: if hypothesis is reached final state in the grammar.

Returns
  String containing best hypothesis at this point in decoding. NULL if no hypothesis is available.

Definition at line 1213 of file pocketsphinx.c.

References ps_decoder_s::perf, and ps_decoder_s::search.

POCKETSPHINX_EXPORT uint8 ps_get_in_speech | ( | ps_decoder_t * | ps | ) |

Checks if the last feed audio buffer contained speech.

Parameters

  ps | Decoder.

Returns
  1 if last buffer contained speech, 0 - otherwise

Definition at line 1391 of file pocketsphinx.c.

References ps_decoder_s::acmod, and acmod_s::fe.

POCKETSPHINX_EXPORT ps_lattice_t* ps_get_lattice | ( | ps_decoder_t * | ps | ) |

Get word lattice.

There isn't much you can do with this so far, a public API will appear in the future.

Parameters

  ps | Decoder.

Returns
  Word lattice object containing all hypotheses so far. NULL if no hypotheses are available. This pointer is owned by the decoder and you should not attempt to free it manually. It is only valid until the next utterance, unless you use ps_lattice_retain() to retain it.

Definition at line 1283 of file pocketsphinx.c.

References ps_decoder_s::search.

Referenced by ps_nbest().

POCKETSPHINX_EXPORT logmath_t* ps_get_logmath | ( | ps_decoder_t * | ps | ) |

Get the log-math computation object for this decoder.

Returns
  The log-math object for this decoder. The decoder retains ownership of this pointer, so you should not attempt to free it manually. Use logmath_retain() if you wish to reuse it elsewhere.

Definition at line 459 of file pocketsphinx.c.

References ps_decoder_s::lmath.

Referenced by ps_end_utt().

POCKETSPHINX_EXPORT int ps_get_n_frames | ( | ps_decoder_t * | ps | ) |

Get the number of frames of data searched.

Note that there is a delay between this and the number of frames of audio which have been input to the system. This is due to the fact that acoustic features are computed using a sliding window of audio, and dynamic features are computed over a sliding window of acoustic features.

Parameters

  ps | Decoder.

Returns
  Number of frames of speech data which have been recognized so far.

Definition at line 1361 of file pocketsphinx.c.

References ps_decoder_s::acmod, and acmod_s::output_frame.

POCKETSPHINX_EXPORT int32 ps_get_prob | ( | ps_decoder_t * | ps | ) |

Get posterior probability.

Note
  Unless the -bestpath option is enabled, this function will always return zero (corresponding to a posterior probability of 1.0). Even if -bestpath is enabled, it will also return zero when called on a partial result. Ongoing research into effective confidence annotation for partial hypotheses may result in these restrictions being lifted in future versions.

Parameters

  ps | Decoder.

Returns
  Posterior probability of the best hypothesis.

Definition at line 1225 of file pocketsphinx.c.

References ps_decoder_s::perf, and ps_decoder_s::search.

POCKETSPHINX_EXPORT void ps_get_rawdata | ( | ps_decoder_t * | ps,
|  | int16 ** | buffer,
|  | int32 * | size
| ) |  |

Retrieves the raw data collected during utterance decoding.

Parameters

  ps | Decoder
  buffer | preallocated buffer to store the data, must be within the limit set before
  size | size of the data collected in samples (not bytes).

Definition at line 1472 of file pocketsphinx.c.

References ps_decoder_s::acmod, and acmod_get_rawdata().

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.

Parameters

  ps | Decoder.
  out_nspeech | Output: Number of seconds of speech.
  out_ncpu | Output: Number of seconds of CPU time used.
  out_nwall | Output: Number of seconds of wall time used.

Definition at line 1367 of file pocketsphinx.c.

References ps_decoder_s::acmod, ps_decoder_s::config, acmod_s::output_frame, and ps_decoder_s::perf.

POCKETSPHINX_EXPORT ps_decoder_t* ps_init | ( | cmd_ln_t * | config | ) |

Initialize the decoder from a configuration object.

Note
  The decoder retains ownership of the pointer `config`, so if you are not going to use it elsewere, you can free it.

Parameters

  config | a command-line structure, as created by cmd_ln_parse_r() or cmd_ln_parse_file_r().

Definition at line 404 of file pocketsphinx.c.

References ps_free(), ps_reinit(), and ps_decoder_s::refcount.

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.

This function replaces the current pronunciation dictionary with the one stored in dictfile. This also causes the active search module(s) to be reinitialized, in the same manner as calling ps_add_word() with update=TRUE.

Parameters

  dictfile | Path to dictionary file to load.
  fdictfile | Path to filler dictionary to load, or NULL to keep the existing filler dictionary.
  format | Format of the dictionary file, or NULL to determine automatically (currently unused,should be NULL)

Definition at line 741 of file pocketsphinx.c.

References ps_decoder_s::acmod, ps_decoder_s::config, ps_decoder_s::d2p, ps_decoder_s::dict, dict2pid_build(), dict2pid_free(), dict_free(), dict_init(), acmod_s::mdef, ps_args(), and ps_decoder_s::searches.

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.

Parameters

  ps | Pocketsphinx decoder
  word | Word to look for

Returns
  Whitespace-spearated phone string describing the pronunciation of the `word` or NULL if word is not present in the dictionary. The string is allocated and must be freed by the user.

Definition at line 872 of file pocketsphinx.c.

References BAD_S3WID, ps_decoder_s::dict, dict_ciphone_str(), and dict_wordid().

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.

Iterator is empty now, it must be advanced with ps_nbest_next first. The function may also return a NULL which means that there is no hypothesis available for this utterance.

Parameters

  ps | Decoder.
  sf | Start frame for N-best search (0 for whole utterance)
  ef | End frame for N-best search (-1 for whole utterance)
  ctx1 | First word of trigram context (NULL for whole utterance)
  ctx2 | First word of trigram context (NULL for whole utterance)

Returns
  Iterator over N-best hypotheses or NULL if no hypothesis is available

Definition at line 1289 of file pocketsphinx.c.

References dict_wordid(), ps_astar_start(), ps_get_lattice(), and ps_decoder_s::search.

POCKETSPHINX_EXPORT void ps_nbest_free | ( | ps_nbest_t * | nbest | ) |

Finish N-best search early, releasing resources.

Parameters

  nbest | N-best iterator.

Definition at line 1322 of file pocketsphinx.c.

References ps_astar_finish().

Referenced by ps_nbest_next().

POCKETSPHINX_EXPORT char const* ps_nbest_hyp | ( | ps_nbest_t * | nbest,
|  | int32 * | out_score
| ) |  |

Get the hypothesis string from an N-best list iterator.

Parameters

  nbest | N-best iterator.
  out_score | Output: Path score for this hypothesis.

Returns
  String containing next best hypothesis.

Definition at line 1341 of file pocketsphinx.c.

References ps_astar_hyp(), and ps_latpath_s::score.

POCKETSPHINX_EXPORT ps_nbest_t* ps_nbest_next | ( | ps_nbest_t * | nbest | ) |

Move an N-best list iterator forward.

Parameters

  nbest | N-best iterator.

Returns
  Updated N-best iterator, or NULL if no more hypotheses are available (iterator is freed ni this case).

Definition at line 1328 of file pocketsphinx.c.

References ps_astar_next(), and ps_nbest_free().

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.

Parameters

  nbest | N-best iterator.
  out_score | Output: Path score for this hypothesis.

Returns
  Iterator over the next best hypothesis.

Definition at line 1352 of file pocketsphinx.c.

References ps_astar_seg_iter(), and ps_latpath_s::score.

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.

Parameters

  ps | Decoder.
  no_search | If non-zero, perform feature extraction but don't do any recognition yet. This may be necessary if your processor has trouble doing recognition in real-time.
  full_utt | If non-zero, this block of data is a full utterance worth of data. This may allow the recognizer to produce more accurate results.

Returns
  Number of frames of data searched, or <0 for error.

Referenced by 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
| ) |  |

Decode raw audio data.

Parameters

  ps | Decoder.
  no_search | If non-zero, perform feature extraction but don't do any recognition yet. This may be necessary if your processor has trouble doing recognition in real-time.
  full_utt | If non-zero, this block of data is a full utterance worth of data. This may allow the recognizer to produce more accurate results.

Returns
  Number of frames of data searched, or <0 for error.

Definition at line 1069 of file pocketsphinx.c.

References ps_decoder_s::acmod, ACMOD_IDLE, acmod_process_cep(), acmod_process_raw(), acmod_set_grow(), ps_process_cep(), and acmod_s::state.

Referenced by ps_decode_raw().

POCKETSPHINX_EXPORT int ps_reinit | ( | ps_decoder_t * | ps,
|  | cmd_ln_t * | config
| ) |  |

Reinitialize the decoder with updated configuration.

This function allows you to switch the acoustic model, dictionary, or other configuration without creating an entirely new decoding object.

Note
  The decoder retains ownership of the pointer `config`, so you must not attempt to free it manually. If you wish to reuse it elsewhere, call cmd_ln_retain() on it.

Parameters

  ps | Decoder.
  config | An optional new configuration to use. If this is NULL, the previous configuration will be reloaded, with any changes applied.

Returns
  0 for success, <0 for failure.

Definition at line 234 of file pocketsphinx.c.

References ps_decoder_s::acmod, acmod_free(), acmod_init(), ps_decoder_s::config, ps_decoder_s::d2p, ps_decoder_s::dict, dict2pid_build(), dict2pid_free(), dict_free(), dict_init(), ps_decoder_s::lmath, acmod_s::mdef, ps_decoder_s::mfclogdir, ps_decoder_s::perf, ps_decoder_s::phone_loop, ps_set_allphone_file(), ps_set_fsg(), ps_set_jsgf_file(), ps_set_keyphrase(), ps_set_kws(), ps_set_lm(), ps_set_lm_file(), ps_set_search(), ps_decoder_s::rawlogdir, ps_decoder_s::searches, and ps_decoder_s::senlogdir.

Referenced by ps_init().

POCKETSPHINX_EXPORT ps_decoder_t* ps_retain | ( | ps_decoder_t * | ps | ) |

Retain a pointer to the decoder.

This increments the reference count on the decoder, allowing it to be shared between multiple parent objects. In general you will not need to use this function, ever. It is mainly here for the convenience of scripting language bindings.

Returns
  pointer to retained decoder.

Definition at line 429 of file pocketsphinx.c.

References ps_decoder_s::refcount.

POCKETSPHINX_EXPORT int ps_save_dict | ( | ps_decoder_t * | ps,
|  | char const * | dictfile,
|  | char const * | format
| ) |  |

Dump the current pronunciation dictionary to a file.

This function dumps the current pronunciation dictionary to a tex

Parameters

  dictfile | Path to file where dictionary will be written.
  format | Format of the dictionary file, or NULL for the default (text) format (currently unused, should be NULL)

Definition at line 797 of file pocketsphinx.c.

References ps_decoder_s::dict, and dict_write().

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.

Note
  These frame numbers are inclusive, i.e. the end frame refers to the last frame in which the given word or other segment was active. Therefore, the actual duration is *out_ef - *out_sf + 1.

Parameters

  seg | Segment iterator.
  out_sf | Output: First frame index in segment.
  out_sf | Output: Last frame index in segment.

Definition at line 1259 of file pocketsphinx.c.

References ps_search_s::acmod, acmod_stream_offset(), ps_seg_s::ef, ps_seg_s::search, and ps_seg_s::sf.

Referenced by ps_end_utt().

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.

Parameters

  ps | Decoder.
  out_best_score | Output: path score corresponding to hypothesis.

Returns
  Iterator over the best hypothesis at this point in decoding. NULL if no hypothesis is available.

Definition at line 1236 of file pocketsphinx.c.

References ps_decoder_s::perf, and ps_decoder_s::search.

Referenced by ps_end_utt().

POCKETSPHINX_EXPORT ps_seg_t* ps_seg_next | ( | ps_seg_t * | seg | ) |

Get the next segment in a word segmentation.

Parameters

  seg | Segment iterator.

Returns
  Updated iterator with the next segment. NULL at end of utterance (the iterator will be freed in this case).

Definition at line 1247 of file pocketsphinx.c.

Referenced by ps_end_utt().

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.

Note
  Unless the -bestpath option is enabled, this function will always return zero (corresponding to a posterior probability of 1.0). Even if -bestpath is enabled, it will also return zero when called on a partial result. Ongoing research into effective confidence annotation for partial hypotheses may result in these restrictions being lifted in future versions.

Parameters

  out_ascr | Output: acoustic model score for this segment.
  out_lscr | Output: language model score for this segment.
  out_lback | Output: language model backoff mode for this segment (i.e. the number of words used in calculating lscr). This field is, of course, only meaningful for N-Gram models.

Returns
  Log posterior probability of current segment. Log is expressed in the log-base used in the decoder. To convert to linear floating-point, use logmath_exp(ps_get_logmath(), pprob).

Definition at line 1268 of file pocketsphinx.c.

References ps_seg_s::ascr, ps_seg_s::lback, ps_seg_s::lscr, and ps_seg_s::prob.

Referenced by ps_end_utt().

POCKETSPHINX_EXPORT char const* ps_seg_word | ( | ps_seg_t * | seg | ) |

Get word string from a segmentation iterator.

Parameters

  seg | Segment iterator.

Returns
  Read-only string giving string name of this segment. This is only valid until the next call to ps_seg_next().

Definition at line 1253 of file pocketsphinx.c.

References ps_seg_s::word.

Referenced by ps_end_utt().

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.

Parameters

  ps | Decoder
  size | bytes of the utterance to store

Definition at line 1466 of file pocketsphinx.c.

References ps_decoder_s::acmod, and acmod_set_rawdata_size().

POCKETSPHINX_EXPORT int ps_start_stream | ( | ps_decoder_t * | ps | ) |

Start processing of the stream of speech.

Channel parameters like noise-level are maintained for the stream and reused among utterances. Times returned in segment iterators are also stream-wide.

Returns
  0 for success, <0 on error.

Definition at line 938 of file pocketsphinx.c.

References ps_decoder_s::acmod, and acmod_start_stream().

Referenced by ps_decode_raw().

POCKETSPHINX_EXPORT int ps_start_utt | ( | ps_decoder_t * | ps | ) |

Start utterance processing.

This function should be called before any utterance data is passed to the decoder. It marks the start of a new utterance and reinitializes internal data structures.

Parameters

  ps | Decoder to be started.

Returns
  0 for success, <0 on error.

Definition at line 945 of file pocketsphinx.c.

References ps_decoder_s::acmod, acmod_advance(), ACMOD_PROCESSING, acmod_set_mfcfh(), acmod_set_rawfh(), acmod_set_senfh(), acmod_start_utt(), ACMOD_STARTED, ps_search_s::dag, ps_search_s::hyp_str, ps_search_s::last_link, ps_decoder_s::mfclogdir, acmod_s::n_feat_frame, ps_decoder_s::n_frame, acmod_s::output_frame, ps_decoder_s::perf, ps_decoder_s::phone_loop, ps_decoder_s::pl_window, ps_search_s::post, ps_lattice_free(), ps_decoder_s::rawlogdir, ps_decoder_s::search, ps_decoder_s::senlogdir, acmod_s::state, and ps_decoder_s::uttno.

Referenced by ps_decode_raw(), and ps_decode_senscr().

POCKETSPHINX_EXPORT ps_mllr_t* ps_update_mllr | ( | ps_decoder_t * | ps,
|  | ps_mllr_t * | mllr
| ) |  |

Adapt current acoustic model using a linear transform.

Parameters

  mllr | The new transform to use, or NULL to update the existing transform. The decoder retains ownership of this pointer, so you should not attempt to free it manually. Use ps_mllr_retain() if you wish to reuse it elsewhere.

Returns
  The updated transform object for this decoder, or NULL on failure.

Definition at line 477 of file pocketsphinx.c.

References ps_decoder_s::acmod, and acmod_update_mllr().