Audio module interface.
struct asra_module_interface asra_module_interface_t { const char * name ; const char * version ; int(* init )(cfg_item_t *asr_config); void(* destroy )(); int(* rate )(const char *url); void(* unrate )(); int(* set_params )(); int(* open )(); int(* start )(); int(* acquire_buffer )(asr_audio_info_t *info, int wait); void(* relinquish_buffer )(asr_audio_info_t *info); int(* get_utterance )(asr_audio_info_t *info); int(* set_utterance )(asr_audio_info_t *info, int offset_ms); int(* save_wavefile )(const char *fname); int(* stop )(); int(* close )(); };
The version number is used to prevent newer, incompatible modules from being used with an older build of ASR.
The io-asr service calls init() for each registered module on startup. The init() function sets the audio properties.
The io-asr service calls destroy() when shutting down a module that has successfuly initialized via the init() function.
The rate() function rates this module's ability to handle the specified audio source URL. The module should rate itself 100 if it can reliably play resources of the specified type, but should supply a lower rating if can't play the resources or if it must perform additional processing first.
The unrate() function removes the rating for this audio module.
The set_params() function sets the global audio parameters for this module.
The open() function opens this audio module.
The start() function causes the module to begin to perform its particular service, for example capturing audio or playing back from a file.
The acquire_buffer() function requests a buffer.
The relinquish_buffer() function resets the buffer in the info structure so that it can be used again.
The get_utterance() function stores an audio sample in the buffer referenced by the info parameter. It also sets the associated properties of the utterance: buffer size, sample size, sample rate, and number of channels. The get_utterance() function waits until the audio capture has completed before copying the sample and returning.
The set_utterance() function copies the last captured audio sample to the buffer referenced by the info parameter, at the offset specified by the offset_ms parameter. The sample size, sample rate, and number of channels must match the properties of the captured sample. If the requested offset results in a buffer overrun, an error is returned. If the audio capture has not completed, an error is returned.
The save_wavefile() copies the captured audio sample as a WAV file with the specified filename.
The stop() function forces the audio capturing to stop.
The close() function closes the audio module.
This structure defines the interface from io-asr to the audio module. Each audio module's constructor function passes this structure to asra_connect().