To add a new conversation module, create a new instance of the conversation module interface (asr_conversation_if), which provides the communication mechanism between your new module and ASR. You must implement the following callback functions, which ASR invokes via the conversation module interface:
ASR calls on_result() for a module only if no other module has a result with a higher confidence level. ASR selects the module that provides the highest rating and sends it the current result for processing. The module can optionally set itself as exclusive by calling the asrm_set_exclusive() function so that it will receive all future results in the current speech session (i.e., io-asr won't evaluate the ratings of other conversation modules). The module releases its exclusive status when ASR transitions to the ASR_STEP_SESSION_CLOSED state.
typedef struct CarDialer_data_s { asr_module_hdl_t* handle ; ... }CarDialer_data _dialer_data ; static const asr_conversation_if_t CarDialer_interface = { .name = "dialer", .asr_version = ASR_VERSION, .init = CarDialer_init, .destroy = CarDialer_destroy, .on_asr_step = CarDialer_step, .select_result = CarDialer_selectResult, .on_result = CarDialer_onResult, } ; __attribute__((constructor)) static void CarDialer_register( void ) { CarDialer_data* self = &_dialer_data ; asr_module_hdl_t* module_handle ; memset( self, 0, sizeof( *self ) ) ; module_handle = asrm_connect( &CarDialer_interface, sizeof( CarDialer_interface ), self ) ; if ( self && module_handle ) { self->handle = module_handle ; } }
When ASR unloads the conversation module, it calls the module's destroy() callback function. This function should clean up any resources that were allocated in the init() function.