/** \brief Try to get result */ struct ast_speech_result* uni_recog_get(struct ast_speech *speech) { struct ast_speech_result *result; mrcp_recog_header_t *recog_header; uni_speech_t *uni_speech = speech->data; if(uni_speech->is_inprogress) { uni_recog_stop(speech); } if(!uni_speech->mrcp_event) { ast_log(LOG_WARNING, "(%s) No RECOGNITION-COMPLETE message received\n",uni_speech->name); return NULL; } /* Get recognizer header */ recog_header = mrcp_resource_header_get(uni_speech->mrcp_event); if(!recog_header || mrcp_resource_header_property_check(uni_speech->mrcp_event,RECOGNIZER_HEADER_COMPLETION_CAUSE) != TRUE) { ast_log(LOG_WARNING, "(%s) Missing completion cause in RECOGNITION-COMPLETE message\n",uni_speech->name); return NULL; } ast_log(LOG_NOTICE, "(%s) Get result completion cause: %03d reason: %s\n", uni_speech->name, recog_header->completion_cause, recog_header->completion_reason.buf ? recog_header->completion_reason.buf : "none"); if(recog_header->completion_cause != RECOGNIZER_COMPLETION_CAUSE_SUCCESS) { ast_log(LOG_WARNING, "(%s) Recognition completed abnormally cause: %03d reason: %s\n", uni_speech->name, recog_header->completion_cause, recog_header->completion_reason.buf ? recog_header->completion_reason.buf : "none"); return NULL; } result = uni_recog_speech_result_build( uni_speech, &uni_speech->mrcp_event->body, uni_speech->mrcp_event->start_line.version); if(result) ast_set_flag(speech,AST_SPEECH_HAVE_RESULTS); return result; }
/** \brief Try to get result */ struct ast_speech_result* uni_recog_get(struct ast_speech *speech) { mrcp_recog_header_t *recog_header; uni_speech_t *uni_speech = speech->data; if(uni_speech->is_inprogress) { uni_recog_stop(speech); } ast_log(LOG_NOTICE, "Get result '%s'\n",uni_speech_id_get(uni_speech)); if(!uni_speech->mrcp_event) { ast_log(LOG_WARNING, "No RECOGNITION-COMPLETE message received\n"); return NULL; } /* Get recognizer header */ recog_header = mrcp_resource_header_get(uni_speech->mrcp_event); if(!recog_header || mrcp_resource_header_property_check(uni_speech->mrcp_event,RECOGNIZER_HEADER_COMPLETION_CAUSE) != TRUE) { ast_log(LOG_WARNING, "Missing Completion-Cause in RECOGNITION-COMPLETE message\n"); return NULL; } if(recog_header->completion_cause != RECOGNIZER_COMPLETION_CAUSE_SUCCESS) { ast_log(LOG_WARNING, "Unsuccessful completion cause:%d reason:%s\n", recog_header->completion_cause, recog_header->completion_reason.buf ? recog_header->completion_reason.buf : "none"); return NULL; } if(speech->results) { ast_speech_results_free(speech->results); } speech->results = uni_recog_speech_result_build( &uni_speech->mrcp_event->body, uni_speech->mrcp_event->start_line.version, mrcp_application_session_pool_get(uni_speech->session)); if(speech->results) { ast_set_flag(speech,AST_SPEECH_HAVE_RESULTS); } return speech->results; }