PocketSphinx
5.0.0
A small speech recognizer
|
configuration object. More...
#include <pocketsphinx.h>
Public Member Functions | |
POCKETSPHINX_EXPORT ps_config_t * | ps_config_init (const ps_arg_t *defn) |
POCKETSPHINX_EXPORT ps_config_t * | ps_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_t * | ps_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_t * | ps_config_get (ps_config_t *config, const char *name) |
const POCKETSPHINX_EXPORT anytype_t * | ps_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_t * | ps_config_set_int (ps_config_t *config, const char *name, long val) |
const POCKETSPHINX_EXPORT anytype_t * | ps_config_set_bool (ps_config_t *config, const char *name, int val) |
const POCKETSPHINX_EXPORT anytype_t * | ps_config_set_float (ps_config_t *config, const char *name, double val) |
const POCKETSPHINX_EXPORT anytype_t * | ps_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_t * | ps_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_t * | ps_args (void) |
POCKETSPHINX_EXPORT ps_config_t * ps_config_init | ( | const ps_arg_t * | defn | ) |
Create a configuration with default values.
defn | Array 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. |
POCKETSPHINX_EXPORT ps_config_t * ps_config_retain | ( | ps_config_t * | config | ) |
Retain a pointer to a configuration object.
POCKETSPHINX_EXPORT int ps_config_free | ( | ps_config_t * | config | ) |
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.
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.
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 ;-)
POCKETSPHINX_EXPORT ps_type_t ps_config_typeof | ( | ps_config_t * | config, |
char const * | name | ||
) |
Access the type of a configuration parameter.
config | Configuration object. |
name | Name of the parameter to retrieve. |
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.
config | Configuration object. |
name | Name of the parameter to retrieve. |
ptr
field in the return value is NULL. This pointer (and any pointers inside it) is owned by the ps_config_t. 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.
config | Configuration object. |
name | Name of the parameter to set. Must exist. |
val | Pointer 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. |
t | Type of the value in val , will be coerced to the type of the actual parameter if necessary. |
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.
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).
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.
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.
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.
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.
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.
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.
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.
config | Configuration to update from file. |
fh | Previously opened file handle. |
file | Name of open file handle for logging (optional, can be NULL) |
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.
config | Configuration to update from file. |
infh | Previously opened file handle. |
file | Name of open file handle for logging (optional, can be NULL) |
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.
config | Configuration to update from file. |
infh | Previously opened file handle. |
file | Name of open file handle for logging (optional, can be NULL) |
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.
POCKETSPHINX_EXPORT void ps_expand_model_config | ( | ps_config_t * | config | ) |
Sets default file paths and parameters based on configuration.
POCKETSPHINX_EXPORT ps_decoder_t * ps_init | ( | ps_config_t * | config | ) |
Initialize the decoder from a configuration object.
config
, so if you are not going to use it elsewhere, you can free it. config | a configuration object. If NULL, the decoder will be allocated but not initialized. You can proceed to initialize it with ps_reinit(). |
|
related |
Gets the system default model directory, if any exists.
|
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).