PocketSphinx  5.0.0
A small speech recognizer
Public Member Functions | Related Functions | List of all members
ps_config_t Struct Reference

configuration object. More...

#include <pocketsphinx.h>

Public Member Functions

POCKETSPHINX_EXPORT ps_config_tps_config_init (const ps_arg_t *defn)
 
POCKETSPHINX_EXPORT ps_config_tps_config_retain (ps_config_t *config)
 
POCKETSPHINX_EXPORT int ps_config_free (ps_config_t *config)
 
int ps_config_validate (ps_config_t *config)
 
POCKETSPHINX_EXPORT ps_config_tps_config_parse_json (ps_config_t *config, const char *json)
 
const POCKETSPHINX_EXPORT char * ps_config_serialize_json (ps_config_t *config)
 
POCKETSPHINX_EXPORT ps_type_t ps_config_typeof (ps_config_t *config, char const *name)
 
const POCKETSPHINX_EXPORT anytype_tps_config_get (ps_config_t *config, const char *name)
 
const POCKETSPHINX_EXPORT anytype_tps_config_set (ps_config_t *config, const char *name, const anytype_t *val, ps_type_t t)
 
POCKETSPHINX_EXPORT long ps_config_int (ps_config_t *config, const char *name)
 
POCKETSPHINX_EXPORT int ps_config_bool (ps_config_t *config, const char *name)
 
POCKETSPHINX_EXPORT double ps_config_float (ps_config_t *config, const char *name)
 
const POCKETSPHINX_EXPORT char * ps_config_str (ps_config_t *config, const char *name)
 
const POCKETSPHINX_EXPORT anytype_tps_config_set_int (ps_config_t *config, const char *name, long val)
 
const POCKETSPHINX_EXPORT anytype_tps_config_set_bool (ps_config_t *config, const char *name, int val)
 
const POCKETSPHINX_EXPORT anytype_tps_config_set_float (ps_config_t *config, const char *name, double val)
 
const POCKETSPHINX_EXPORT anytype_tps_config_set_str (ps_config_t *config, const char *name, const char *val)
 
POCKETSPHINX_EXPORT int ps_config_soundfile (ps_config_t *config, FILE *fh, const char *file)
 
POCKETSPHINX_EXPORT int ps_config_wavfile (ps_config_t *config, FILE *infh, const char *file)
 
POCKETSPHINX_EXPORT int ps_config_nistfile (ps_config_t *config, FILE *infh, const char *file)
 
POCKETSPHINX_EXPORT void ps_default_search_args (ps_config_t *config)
 
POCKETSPHINX_EXPORT void ps_expand_model_config (ps_config_t *config)
 
POCKETSPHINX_EXPORT ps_decoder_tps_init (ps_config_t *config)
 

Related Functions

(Note that these are not member functions.)

const POCKETSPHINX_EXPORT char * ps_default_modeldir (void)
 
POCKETSPHINX_EXPORT const ps_arg_tps_args (void)
 

Detailed Description

configuration object.

Examples
live.c, and simple.c.

Member Function Documentation

◆ ps_config_init()

POCKETSPHINX_EXPORT ps_config_t * ps_config_init ( const ps_arg_t defn)

Create a configuration with default values.

Parameters
defnArray of ps_arg_t defining and describing parameters, terminated by an ps_arg_t with name == NULL. You should usually just pass NULL here, which will result in the standard set of parameters being used.
Returns
Newly created configuration or NULL on failure (should not happen, but check it anyway).
Examples
live.c, and simple.c.

◆ ps_config_retain()

POCKETSPHINX_EXPORT ps_config_t * ps_config_retain ( ps_config_t config)

Retain a pointer to a configuration object.

◆ ps_config_free()

POCKETSPHINX_EXPORT int ps_config_free ( ps_config_t config)

Release a configuration object.

Examples
live.c, and simple.c.

◆ ps_config_validate()

int ps_config_validate ( ps_config_t config)

Validate configuration.

Currently this just checks that you haven't specified multiple types of grammars or language models at the same time.

Returns
0 for success, <0 for failure.

◆ ps_config_parse_json()

POCKETSPHINX_EXPORT ps_config_t * ps_config_parse_json ( ps_config_t config,
const char *  json 
)

Create or update a configuration by parsing slightly extended JSON.

This function parses a JSON object in non-strict mode to produce a ps_config_t. Configuration parameters are given without a leading dash, and do not need to be quoted, nor does the object need to be enclosed in curly braces, nor are commas necessary between key/value pairs. Basically, it's degenerate YAML. So, for example, this is accepted:

hmm: fr-fr
samprate: 8000
keyphrase: "hello world"

Of course, valid JSON is also accepted, but who wants to use that.

Well, mostly. Unicode escape sequences (e.g. "\u0020") are not supported at the moment, so please don't use them.

  • config Previously existing ps_config_t to update, or NULL to create a new one.
  • json JSON serialized object as null-terminated UTF-8, containing configuration parameters.
    Returns
    Newly created configuration or NULL on failure (such as invalid or missing parameters).

◆ ps_config_serialize_json()

const POCKETSPHINX_EXPORT char * ps_config_serialize_json ( ps_config_t config)

Construct JSON from a configuration object.

Unlike ps_config_parse_json(), this actually produces valid JSON ;-)

  • config Configuration object
    Returns
    Newly created null-terminated JSON string. The ps_config_t retains ownership of this pointer, which is only valid until the next call to ps_config_serialize_json(). You must copy it if you wish to retain it.

◆ ps_config_typeof()

POCKETSPHINX_EXPORT ps_type_t ps_config_typeof ( ps_config_t config,
char const *  name 
)

Access the type of a configuration parameter.

Parameters
configConfiguration object.
nameName of the parameter to retrieve.
Returns
the type of the parameter (as a combination of the ARG_* bits), or 0 if no such parameter exists.

◆ ps_config_get()

const POCKETSPHINX_EXPORT anytype_t * ps_config_get ( ps_config_t config,
const char *  name 
)

Access the value of a configuration parameter.

To actually do something with the value, you will need to know its type, which can be obtained with ps_config_typeof(). This function is thus mainly useful for dynamic language bindings, and you should use ps_config_int(), ps_config_float(), or ps_config_str() instead.

Parameters
configConfiguration object.
nameName of the parameter to retrieve.
Returns
Pointer to the parameter's value, or NULL if the parameter does not exist. Note that a string parameter can also have NULL as a value, in which case the ptr field in the return value is NULL. This pointer (and any pointers inside it) is owned by the 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 
)

Set or unset the value of a configuration parameter.

This will coerce the value to the proper type, so you can, for example, pass it a string with ARG_STRING as the type when adding options from the command-line. Note that the return pointer will not be the same as the one passed in the value.

Parameters
configConfiguration object.
nameName of the parameter to set. Must exist.
valPointer to the value (strings will be copied) inside an anytype_t union. On 64-bit little-endian platforms, you can cast a pointer to int, long, double, or char* here, but that doesn't necessarily mean that you should. As a convenience, you can pass NULL here to reset a parameter to its default value.
tType of the value in val, will be coerced to the type of the actual parameter if necessary.
Returns
Pointer to the parameter's value, or NULL on failure (unknown parameter, usually). This pointer (and any pointers inside it) is owned by the ps_config_t.

◆ ps_config_int()

POCKETSPHINX_EXPORT long ps_config_int ( ps_config_t config,
const char *  name 
)

Get an integer-valued parameter.

If the parameter does not have an integer or boolean type, this will print an error and return 0. So don't do that.

◆ ps_config_bool()

POCKETSPHINX_EXPORT int ps_config_bool ( ps_config_t config,
const char *  name 
)

Get a boolean-valued parameter.

If the parameter does not have an integer or boolean type, this will print an error and return 0. The return value is either 0 or 1 (if the parameter has an integer type, any non-zero value will return 1).

◆ ps_config_float()

POCKETSPHINX_EXPORT double ps_config_float ( ps_config_t config,
const char *  name 
)

Get a floating-point parameter.

If the parameter does not have a floating-point type, this will print an error and return 0.

◆ ps_config_str()

const POCKETSPHINX_EXPORT char * ps_config_str ( ps_config_t config,
const char *  name 
)

Get a string parameter.

If the parameter does not have a string type, this will print an error and return NULL. Notably, it will NOT format an integer or float for you, because that would involve allocating memory. So don't do that.

◆ ps_config_set_int()

const POCKETSPHINX_EXPORT anytype_t * ps_config_set_int ( ps_config_t config,
const char *  name,
long  val 
)

Set an integer-valued parameter.

If the parameter does not have an integer or boolean type, this will convert val appropriately.

◆ ps_config_set_bool()

const POCKETSPHINX_EXPORT anytype_t * ps_config_set_bool ( ps_config_t config,
const char *  name,
int  val 
)

Set a boolean-valued parameter.

If the parameter does not have an integer or boolean type, this will convert val appropriately.

◆ ps_config_set_float()

const POCKETSPHINX_EXPORT anytype_t * ps_config_set_float ( ps_config_t config,
const char *  name,
double  val 
)

Set a floating-point parameter.

If the parameter does not have a floating-point type, this will convert val appropriately.

◆ ps_config_set_str()

const POCKETSPHINX_EXPORT anytype_t * ps_config_set_str ( ps_config_t config,
const char *  name,
const char *  val 
)

Set a string-valued parameter.

If the parameter does not have a string type, this will convert val appropriately. For boolean parameters, any string matching /^[yt1]/ will be true, while any string matching /^[nf0]/ will be false. NULL is also false.

This function is used for configuration from JSON, you may want to use it for your own configuration files too.

◆ ps_config_soundfile()

POCKETSPHINX_EXPORT int ps_config_soundfile ( ps_config_t config,
FILE *  fh,
const char *  file 
)

Set configuration parameters (actually just sample rate) from a sound file.

If the file is unreadable, unsupported or incompatible with the existing feature extraction parameters, this will print an error message and fail (return -1).

If it is of an unknown type, it will be treated as raw data. So beware! Currently we only support WAV and NIST Sphere files. We attempt to recognize Ogg, MP3 (but not really, because it is very difficult to do reliably), and FLAC, but do not support them. For everything else, there's SoX (tm).

Currently, the file must be seekable, so you can't use this on standard input, for instance.

Parameters
configConfiguration to update from file.
fhPreviously opened file handle.
fileName of open file handle for logging (optional, can be NULL)
Examples
simple.c.

◆ ps_config_wavfile()

POCKETSPHINX_EXPORT int ps_config_wavfile ( ps_config_t config,
FILE *  infh,
const char *  file 
)

Read a WAV header and set configuration parameters.

This works like ps_config_soundfile() but assumes that you already know it's a WAV file.

Unlike ps_config_soundfile(), the file does not have to be seekable.

Parameters
configConfiguration to update from file.
infhPreviously opened file handle.
fileName of open file handle for logging (optional, can be NULL)

◆ ps_config_nistfile()

POCKETSPHINX_EXPORT int ps_config_nistfile ( ps_config_t config,
FILE *  infh,
const char *  file 
)

Read a NIST header and set configuration parameters.

This works like ps_config_soundfile() but assumes that you already know it's a NIST file.

Unlike ps_config_soundfile(), the file does not have to be seekable.

Parameters
configConfiguration to update from file.
infhPreviously opened file handle.
fileName of open file handle for logging (optional, can be NULL)

◆ ps_default_search_args()

POCKETSPHINX_EXPORT void ps_default_search_args ( ps_config_t config)

Sets default acoustic and language model if they are not set explicitly.

This function fills in the configuration with the default acoustic and language models and dictionary, if (and this is a badly implemented heuristic) they do not seem to be already filled in. It is preferable for you to call this before doing any other configuration to avoid confusion.

The default models are looked for in the directory returned by ps_default_modeldir(), or, if the POCKETSPHINX_PATH environment variable is set, this function will look there instead.

If no global model directory was defined at compilation time (this is useful for relocatable installs such as the Python module) and POCKETSPHINX_PATH is not set, this will simply do nothing.

Examples
live.c, and simple.c.

◆ ps_expand_model_config()

POCKETSPHINX_EXPORT void ps_expand_model_config ( ps_config_t config)

Sets default file paths and parameters based on configuration.

◆ ps_init()

POCKETSPHINX_EXPORT ps_decoder_t * ps_init ( ps_config_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 elsewhere, you can free it.
Parameters
configa configuration object. If NULL, the decoder will be allocated but not initialized. You can proceed to initialize it with ps_reinit().
Examples
live.c, and simple.c.

Friends And Related Function Documentation

◆ ps_default_modeldir()

const POCKETSPHINX_EXPORT char * ps_default_modeldir ( void  )
related

Gets the system default model directory, if any exists.

Returns
system model directory defined at compile time, or NULL if not defined (usually in a relocatable installation such as a Python module).

◆ ps_args()

POCKETSPHINX_EXPORT const ps_arg_t * ps_args ( void  )
related

Returns the argument definitions used in ps_config_init().

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


The documentation for this struct was generated from the following file: