sphinxwrapper Python package

This section documents the available classes, methods, properties and functions.

CMU Pocket Sphinx Decoder Classes

class sphinxwrapper.pocketsphinx_wrap.PocketSphinx(config=None)[source]

Pocket Sphinx decoder subclass with processing methods providing callback functionality and other things.

This class will try to set required config options, such as ‘-hmm’, ‘-dict’ and/or ‘-lm’, in the config object automatically if they are not set.

Construct arguments:

  • config – decoder configuration object. Will be initialised using default_config() if unspecified.

Note

The decoder class will not be initialised if the configuration object specifies more than search argument.

The name of the currently active Pocket Sphinx search.

If the setter is passed a name with no matching Pocket Sphinx search, an error will be raised.

Returns:str
batch_process(buffers, no_search=False, full_utterance=False, use_callbacks=True)[source]

Process a list of audio buffers and return the speech hypothesis or use the decoder callbacks if use_callbacks is True.

end_utt()[source]

Ends the current utterance if one was in progress.

This method is useful for resetting processing of audio via the process_audio() method.

It will not raise an error if no utterance was in progress.

get_in_speech()[source]

Check if the last audio buffer contained speech.

This method will also move utterance state from idle to started.

Returns:whether the last audio buffer contained speech.
Return type:bool
hypothesis_callback

Callback called with Pocket Sphinx’s hypothesis for what was said.

process_audio(buf, no_search=False, full_utterance=False, use_callbacks=True)[source]

Process audio from an audio buffer using the process_raw() decoder method.

The speech start and hypothesis callbacks will be called if and when necessary.

Parameters:
  • buf (str) – audio buffer
  • no_search (bool) – whether to perform feature extraction, but no recognition yet (default: False).
  • full_utterance (bool) – whether this block of data contains a full utterance worth of data (default: False). This may produce more accurate results.
  • use_callbacks (bool) – whether speech start and hypothesis callbacks should be called (default: True).
set_kws_list(name, kws_list)[source]

Set a keywords Pocket Sphinx search with the specified name taking a keywords list as a Python dictionary.

This method generates a temporary keywords list file and calls the set_kws() decoder method with its path.

Parameters:
  • name (str) – search name
  • kws_list – dictionary of words to threshold value. Can also be a list of 2-tuples.
speech_start_callback

Callback for when speech starts.

start_utt()[source]

Starts a new utterance if one is not already in progress.

This method will not raise an error if an utterance is in progress (started or idle) already.

utt_ended

Whether there is no utterance in progress.

Return type:bool
utt_idle

Whether an utterance is in progress, but no speech has been detected yet.

get_in_speech() would return False if this returns True.

Return type:bool
utt_started

Whether an utterance is in progress and speech has been detected.

get_in_speech() would return True if this returns True.

Return type:bool

Decoder Configuration

exception sphinxwrapper.config.ConfigError[source]

Error raised if something is wrong with the decoder configuration.

sphinxwrapper.config.search_arguments_set(config)[source]

This function returns the search arguments set for a given Config object.

Search arguments include:

  • -lm (default)
  • -fsg
  • -jsgf
  • -keyphrase
  • -kws
Parameters:config (Config) – decoder configuration object
Returns:list
sphinxwrapper.config.set_hmm_and_dict_paths(config, model_path=None)[source]

This function will try to find the HMM directory and dictionary file paths in model_path and set the ‘-hmm’ and ‘-dict’ arguments in the given Config object.

An error will be raised if any of the paths were not found.

Parameters:
  • config (Config) – decoder configuration object
  • model_path (str) – path to search for HMM and dictionary. The Pocket Sphinx get_model_path() function is used if the parameter is unspecified.
Raises:

ConfigError

sphinxwrapper.config.set_lm_path(config, model_path=None)[source]

This function will try to find the LM file in model_path and set the ‘-lm’ argument for the given Config object.

Only files ending with .lm or .lm.bin will be considered. An error will be raised if an LM file cannot be found.

Parameters:
  • config (Config) – decoder configuration object
  • model_path (str) – path to search for the LM file. The Pocket Sphinx get_model_path() function is used if the parameter is unspecified.
Raises:

ConfigError