static apt_bool_t recog_event_interpretation_complete(mrcp_recog_state_machine_t *state_machine, mrcp_message_t *message) { if(mrcp_resource_header_property_check(message,RECOGNIZER_HEADER_COMPLETION_CAUSE) != TRUE) { mrcp_recog_header_t *recog_header = mrcp_resource_header_prepare(message); recog_header->completion_cause = RECOGNIZER_COMPLETION_CAUSE_SUCCESS; mrcp_resource_header_property_add(message,RECOGNIZER_HEADER_COMPLETION_CAUSE); } return recog_event_dispatch(state_machine,message); }
mrcp_message_t* VerifierSession::CreateVerificationRequest(mrcp_channel_t* pMrcpChannel) { mrcp_message_t* pMrcpMessage = CreateMrcpMessage(pMrcpChannel,VERIFIER_VERIFY); if(!pMrcpMessage) return NULL; mrcp_verifier_header_t* pVerifierHeader; /* get/allocate verifier header */ pVerifierHeader = (mrcp_verifier_header_t*) mrcp_resource_header_prepare(pMrcpMessage); if(pVerifierHeader) { pVerifierHeader->no_input_timeout = 5000; mrcp_resource_header_property_add(pMrcpMessage,VERIFIER_HEADER_NO_INPUT_TIMEOUT); pVerifierHeader->start_input_timers = TRUE; mrcp_resource_header_property_add(pMrcpMessage,VERIFIER_HEADER_START_INPUT_TIMERS); } return pMrcpMessage; }
static apt_bool_t recog_response_define_grammar(mrcp_recog_state_machine_t *state_machine, mrcp_message_t *message) { apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Process DEFINE-GRAMMAR Response [%d]",message->start_line.request_id); if(mrcp_resource_header_property_check(message,RECOGNIZER_HEADER_COMPLETION_CAUSE) != TRUE) { mrcp_recog_header_t *recog_header = mrcp_resource_header_prepare(message); recog_header->completion_cause = RECOGNIZER_COMPLETION_CAUSE_SUCCESS; mrcp_resource_header_property_add(message,RECOGNIZER_HEADER_COMPLETION_CAUSE); } return recog_response_dispatch(state_machine,message); }
/** Create demo MRCP message (RECOGNIZE request) */ mrcp_message_t* demo_recognize_message_create(mrcp_session_t *session, mrcp_channel_t *channel, const apt_dir_layout_t *dir_layout) { const char text[] = "session:[email protected]"; /* create MRCP message */ mrcp_message_t *mrcp_message = mrcp_application_message_create(session,channel,RECOGNIZER_RECOGNIZE); if(mrcp_message) { mrcp_recog_header_t *recog_header; mrcp_generic_header_t *generic_header; /* get/allocate generic header */ generic_header = mrcp_generic_header_prepare(mrcp_message); if(generic_header) { /* set generic header fields */ apt_string_assign(&generic_header->content_type,"text/uri-list",mrcp_message->pool); mrcp_generic_header_property_add(mrcp_message,GENERIC_HEADER_CONTENT_TYPE); } /* get/allocate recognizer header */ recog_header = mrcp_resource_header_prepare(mrcp_message); if(recog_header) { if(mrcp_message->start_line.version == MRCP_VERSION_2) { /* set recognizer header fields */ recog_header->cancel_if_queue = FALSE; mrcp_resource_header_property_add(mrcp_message,RECOGNIZER_HEADER_CANCEL_IF_QUEUE); } recog_header->no_input_timeout = 5000; mrcp_resource_header_property_add(mrcp_message,RECOGNIZER_HEADER_NO_INPUT_TIMEOUT); recog_header->recognition_timeout = 10000; mrcp_resource_header_property_add(mrcp_message,RECOGNIZER_HEADER_RECOGNITION_TIMEOUT); recog_header->start_input_timers = TRUE; mrcp_resource_header_property_add(mrcp_message,RECOGNIZER_HEADER_START_INPUT_TIMERS); recog_header->confidence_threshold = 0.87f; mrcp_resource_header_property_add(mrcp_message,RECOGNIZER_HEADER_CONFIDENCE_THRESHOLD); } /* set message body */ apt_string_assign(&mrcp_message->body,text,mrcp_message->pool); } return mrcp_message; }
mrcp_message_t* RecogSession::CreateRecognizeRequest(mrcp_channel_t* pMrcpChannel) { mrcp_message_t* pMrcpMessage = CreateMrcpMessage(pMrcpChannel,RECOGNIZER_RECOGNIZE); if(!pMrcpMessage) return NULL; const RecogScenario* pScenario = GetScenario(); mrcp_generic_header_t* pGenericHeader; mrcp_recog_header_t* pRecogHeader; /* get/allocate generic header */ pGenericHeader = (mrcp_generic_header_t*) mrcp_generic_header_prepare(pMrcpMessage); if(pGenericHeader) { /* set generic header fields */ if(pScenario->IsDefineGrammarEnabled()) { apt_string_assign(&pGenericHeader->content_type,"text/uri-list",pMrcpMessage->pool); /* set message body */ const char* pContent = apr_pstrcat(pMrcpMessage->pool,"session:",m_ContentId,NULL); apt_string_set(&pMrcpMessage->body,pContent); } else { apt_string_assign(&pGenericHeader->content_type,pScenario->GetContentType(),pMrcpMessage->pool); /* set content-id */ apt_string_assign(&pGenericHeader->content_id,m_ContentId,pMrcpMessage->pool); mrcp_generic_header_property_add(pMrcpMessage,GENERIC_HEADER_CONTENT_ID); /* set message body */ if(pScenario->GetContent()) apt_string_assign_n(&pMrcpMessage->body,pScenario->GetContent(),pScenario->GetContentLength(),pMrcpMessage->pool); } mrcp_generic_header_property_add(pMrcpMessage,GENERIC_HEADER_CONTENT_TYPE); } /* get/allocate recognizer header */ pRecogHeader = (mrcp_recog_header_t*) mrcp_resource_header_prepare(pMrcpMessage); if(pRecogHeader) { /* set recognizer header fields */ if(pMrcpMessage->start_line.version == MRCP_VERSION_2) { pRecogHeader->cancel_if_queue = FALSE; mrcp_resource_header_property_add(pMrcpMessage,RECOGNIZER_HEADER_CANCEL_IF_QUEUE); } pRecogHeader->no_input_timeout = 5000; mrcp_resource_header_property_add(pMrcpMessage,RECOGNIZER_HEADER_NO_INPUT_TIMEOUT); pRecogHeader->recognition_timeout = 10000; mrcp_resource_header_property_add(pMrcpMessage,RECOGNIZER_HEADER_RECOGNITION_TIMEOUT); pRecogHeader->start_input_timers = TRUE; mrcp_resource_header_property_add(pMrcpMessage,RECOGNIZER_HEADER_START_INPUT_TIMERS); pRecogHeader->confidence_threshold = 0.87f; mrcp_resource_header_property_add(pMrcpMessage,RECOGNIZER_HEADER_CONFIDENCE_THRESHOLD); pRecogHeader->save_waveform = TRUE; mrcp_resource_header_property_add(pMrcpMessage,RECOGNIZER_HEADER_SAVE_WAVEFORM); } return pMrcpMessage; }
/** Process GET-PARAMS request */ static apt_bool_t demo_synth_channel_get_params(mrcp_engine_channel_t *channel, mrcp_message_t *request, mrcp_message_t *response) { mrcp_synth_header_t *req_synth_header; /* get synthesizer header */ req_synth_header = mrcp_resource_header_get(request); if(req_synth_header) { mrcp_synth_header_t *res_synth_header = mrcp_resource_header_prepare(response); /* check voice age header */ if(mrcp_resource_header_property_check(request,SYNTHESIZER_HEADER_VOICE_AGE) == TRUE) { res_synth_header->voice_param.age = 25; mrcp_resource_header_property_add(response,SYNTHESIZER_HEADER_VOICE_AGE); } /* check voice name header */ if(mrcp_resource_header_property_check(request,SYNTHESIZER_HEADER_VOICE_NAME) == TRUE) { apt_string_set(&res_synth_header->voice_param.name,"David"); mrcp_resource_header_property_add(response,SYNTHESIZER_HEADER_VOICE_NAME); } } /* send asynchronous response */ mrcp_engine_channel_message_send(channel,response); return TRUE; }
mrcp_message_t* RecorderSession::CreateRecordRequest(mrcp_channel_t* pMrcpChannel) { mrcp_message_t* pMrcpMessage = CreateMrcpMessage(pMrcpChannel,RECORDER_RECORD); if(!pMrcpMessage) return NULL; mrcp_recorder_header_t* pRecorderHeader; /* get/allocate recorder header */ pRecorderHeader = (mrcp_recorder_header_t*) mrcp_resource_header_prepare(pMrcpMessage); if(pRecorderHeader) { /* set recorder header fields */ pRecorderHeader->no_input_timeout = 5000; mrcp_resource_header_property_add(pMrcpMessage,RECORDER_HEADER_NO_INPUT_TIMEOUT); pRecorderHeader->final_silence = 300; mrcp_resource_header_property_add(pMrcpMessage,RECORDER_HEADER_FINAL_SILENCE); pRecorderHeader->max_time = 10000; mrcp_resource_header_property_add(pMrcpMessage,RECORDER_HEADER_MAX_TIME); } return pMrcpMessage; }
mrcp_message_t* SetParamSession::CreateSetParams2(mrcp_channel_t* pMrcpChannel) { mrcp_message_t* pMrcpMessage = CreateMrcpMessage(pMrcpChannel,RECOGNIZER_SET_PARAMS); if(!pMrcpMessage) return NULL; mrcp_recog_header_t* pRecogHeader; /* get/allocate recog header */ pRecogHeader = (mrcp_recog_header_t*) mrcp_resource_header_prepare(pMrcpMessage); if(pRecogHeader) { /* set recog header fields */ pRecogHeader->recognition_timeout = 5000; mrcp_resource_header_property_add(pMrcpMessage,RECOGNIZER_HEADER_RECOGNITION_TIMEOUT); pRecogHeader->speech_complete_timeout = 1000; mrcp_resource_header_property_add(pMrcpMessage,RECOGNIZER_HEADER_SPEECH_COMPLETE_TIMEOUT); pRecogHeader->speech_incomplete_timeout = 2000; mrcp_resource_header_property_add(pMrcpMessage,RECOGNIZER_HEADER_SPEECH_INCOMPLETE_TIMEOUT); pRecogHeader->dtmf_interdigit_timeout = 3000; mrcp_resource_header_property_add(pMrcpMessage,RECOGNIZER_HEADER_DTMF_INTERDIGIT_TIMEOUT); } return pMrcpMessage; }
/** Create RECOGNIZE request */ static mrcp_message_t* recognize_message_create(asr_session_t *asr_session) { /* create MRCP message */ mrcp_message_t *mrcp_message = mrcp_application_message_create( asr_session->mrcp_session, asr_session->mrcp_channel, RECOGNIZER_RECOGNIZE); if(mrcp_message) { mrcp_recog_header_t *recog_header; mrcp_generic_header_t *generic_header; /* get/allocate generic header */ generic_header = mrcp_generic_header_prepare(mrcp_message); if(generic_header) { /* set generic header fields */ apt_string_assign(&generic_header->content_type,"text/uri-list",mrcp_message->pool); mrcp_generic_header_property_add(mrcp_message,GENERIC_HEADER_CONTENT_TYPE); /* set message body */ apt_string_assign(&mrcp_message->body,"session:demo-grammar",mrcp_message->pool); } /* get/allocate recognizer header */ recog_header = mrcp_resource_header_prepare(mrcp_message); if(recog_header) { if(mrcp_message->start_line.version == MRCP_VERSION_2) { /* set recognizer header fields */ recog_header->cancel_if_queue = FALSE; mrcp_resource_header_property_add(mrcp_message,RECOGNIZER_HEADER_CANCEL_IF_QUEUE); } recog_header->no_input_timeout = 5000; mrcp_resource_header_property_add(mrcp_message,RECOGNIZER_HEADER_NO_INPUT_TIMEOUT); recog_header->recognition_timeout = 20000; mrcp_resource_header_property_add(mrcp_message,RECOGNIZER_HEADER_RECOGNITION_TIMEOUT); recog_header->speech_complete_timeout = 400; mrcp_resource_header_property_add(mrcp_message,RECOGNIZER_HEADER_SPEECH_COMPLETE_TIMEOUT); recog_header->dtmf_term_timeout = 3000; mrcp_resource_header_property_add(mrcp_message,RECOGNIZER_HEADER_DTMF_TERM_TIMEOUT); recog_header->dtmf_interdigit_timeout = 3000; mrcp_resource_header_property_add(mrcp_message,RECOGNIZER_HEADER_DTMF_INTERDIGIT_TIMEOUT); recog_header->confidence_threshold = 0.5f; mrcp_resource_header_property_add(mrcp_message,RECOGNIZER_HEADER_CONFIDENCE_THRESHOLD); recog_header->start_input_timers = TRUE; mrcp_resource_header_property_add(mrcp_message,RECOGNIZER_HEADER_START_INPUT_TIMERS); } } return mrcp_message; }
/* Create SPEAK-COMPLETE event */ static mrcp_message_t* speak_event_create(mrcp_resource_factory_t *factory, const mrcp_message_t *request) { mrcp_message_t *event_message; apt_log(APT_LOG_MARK,APT_PRIO_NOTICE,"Create SPEAK-COMPLETE Event"); event_message = mrcp_event_create(request,SYNTHESIZER_SPEAK_COMPLETE,request->pool); if(event_message) { /* get/allocate synthesizer header */ mrcp_synth_header_t *synth_header = mrcp_resource_header_prepare(event_message); if(synth_header) { /* set completion cause */ synth_header->completion_cause = SYNTHESIZER_COMPLETION_CAUSE_NORMAL; mrcp_resource_header_property_add(event_message,SYNTHESIZER_HEADER_COMPLETION_CAUSE); } /* set request state */ event_message->start_line.request_state = MRCP_REQUEST_STATE_COMPLETE; } return event_message; }
static apt_bool_t recog_event_recognition_complete(mrcp_recog_state_machine_t *state_machine, mrcp_message_t *message) { mrcp_message_t *pending_request; if(!state_machine->recog) { apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Unexpected RECOGNITION-COMPLETE Event "APT_SIDRES_FMT" [%"MRCP_REQUEST_ID_FMT"]", MRCP_MESSAGE_SIDRES(message), message->start_line.request_id); return FALSE; } if(state_machine->recog->start_line.request_id != message->start_line.request_id) { apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Unexpected RECOGNITION-COMPLETE Event "APT_SIDRES_FMT" [%"MRCP_REQUEST_ID_FMT"]", MRCP_MESSAGE_SIDRES(message), message->start_line.request_id); return FALSE; } if(state_machine->active_request && state_machine->active_request->start_line.method_id == RECOGNIZER_STOP) { apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Ignore RECOGNITION-COMPLETE Event "APT_SIDRES_FMT" [%"MRCP_REQUEST_ID_FMT"]: waiting for STOP response", MRCP_MESSAGE_SIDRES(message), message->start_line.request_id); return FALSE; } if(mrcp_resource_header_property_check(message,RECOGNIZER_HEADER_COMPLETION_CAUSE) != TRUE) { mrcp_recog_header_t *recog_header = mrcp_resource_header_prepare(message); recog_header->completion_cause = RECOGNIZER_COMPLETION_CAUSE_SUCCESS; mrcp_resource_header_property_add(message,RECOGNIZER_HEADER_COMPLETION_CAUSE); } recog_state_change(state_machine,RECOGNIZER_STATE_RECOGNIZED,message); recog_event_dispatch(state_machine,message); /* process pending RECOGNIZE requests */ pending_request = apt_list_pop_front(state_machine->queue); if(pending_request) { apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Process Pending RECOGNIZE Request "APT_SIDRES_FMT" [%"MRCP_REQUEST_ID_FMT"]", MRCP_MESSAGE_SIDRES(pending_request), pending_request->start_line.request_id); state_machine->is_pending = TRUE; recog_request_dispatch(state_machine,pending_request); } return TRUE; }
/** Set Record-URI header field */ static apt_bool_t recorder_channel_uri_set(recorder_channel_t *recorder_channel, mrcp_message_t *message) { char *record_uri; /* get/allocate recorder header */ mrcp_recorder_header_t *recorder_header = mrcp_resource_header_prepare(message); if(!recorder_header) { return FALSE; } record_uri = apr_psprintf( message->pool, "<file://mediaserver/data/%s>;size=%"APR_SIZE_T_FMT";duration=%"APR_SIZE_T_FMT, recorder_channel->file_name, recorder_channel->cur_size, recorder_channel->cur_time); apt_string_set(&recorder_header->record_uri,record_uri); mrcp_resource_header_property_add(message,RECORDER_HEADER_RECORD_URI); return TRUE; }
static apt_bool_t synth_event_speak_complete(mrcp_synth_state_machine_t *state_machine, mrcp_message_t *message) { mrcp_message_t *pending_request; if(!state_machine->speaker) { apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Unexpected SPEAK-COMPLETE Event [%"MRCP_REQUEST_ID_FMT"]", message->start_line.request_id); return FALSE; } if(state_machine->speaker->start_line.request_id != message->start_line.request_id) { apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Unexpected SPEAK-COMPLETE Event [%"MRCP_REQUEST_ID_FMT"]", message->start_line.request_id); return FALSE; } if(state_machine->active_request && state_machine->active_request->start_line.method_id == SYNTHESIZER_STOP) { apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Ignore SPEAK-COMPLETE Event [%d]: waiting for STOP response",message->start_line.request_id); return FALSE; } apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Process SPEAK-COMPLETE Event [%"MRCP_REQUEST_ID_FMT"]", message->start_line.request_id); if(mrcp_resource_header_property_check(message,SYNTHESIZER_HEADER_COMPLETION_CAUSE) != TRUE) { mrcp_synth_header_t *synth_header = mrcp_resource_header_prepare(message); synth_header->completion_cause = SYNTHESIZER_COMPLETION_CAUSE_NORMAL; mrcp_resource_header_property_add(message,SYNTHESIZER_HEADER_COMPLETION_CAUSE); } synth_state_change(state_machine,SYNTHESIZER_STATE_IDLE); synth_event_dispatch(state_machine,message); /* process pending SPEAK requests */ pending_request = apt_list_pop_front(state_machine->queue); if(pending_request) { apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Process Pending SPEAK Request [%d]",pending_request->start_line.request_id); state_machine->is_pending = TRUE; synth_request_dispatch(state_machine,pending_request); } return TRUE; }
/* Create GET-PARAMS response */ static mrcp_message_t* get_params_response_create(mrcp_resource_factory_t *factory, mrcp_message_t *request) { apt_bool_t res; mrcp_message_t *response; apt_log(APT_LOG_MARK,APT_PRIO_NOTICE,"Create GET-PARAMS Response"); response = mrcp_response_create(request,request->pool); if(response) { mrcp_generic_header_t *generic_header; mrcp_synth_header_t *synth_header; res = FALSE; /* get generic header */ generic_header = mrcp_generic_header_get(request); if(generic_header) { mrcp_generic_header_t *res_generic_header = mrcp_generic_header_prepare(response); /* test content id header */ if(mrcp_generic_header_property_check(request,GENERIC_HEADER_CONTENT_ID) == TRUE) { apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Set Content-ID: %s",SAMPLE_CONTENT_ID); apt_string_assign(&res_generic_header->content_id,SAMPLE_CONTENT_ID,response->pool); mrcp_generic_header_property_add(response,GENERIC_HEADER_CONTENT_ID); res = TRUE; } /* test vendor specific header */ if(mrcp_generic_header_property_check(request,GENERIC_HEADER_VENDOR_SPECIFIC_PARAMS) == TRUE) { apt_str_t name; const apt_pair_t *pair; res_generic_header->vendor_specific_params = apt_pair_array_create(1,response->pool); apt_string_set(&name,SAMPLE_PARAM_NAME); pair = apt_pair_array_find(generic_header->vendor_specific_params,&name); if(pair) { apt_str_t value; apt_string_set(&value,SAMPLE_PARAM_VALUE); apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Set Vendor-Specific-Params: %s=%s",name.buf,value.buf); apt_pair_array_append(res_generic_header->vendor_specific_params,&name,&value,response->pool); } mrcp_generic_header_property_add(response,GENERIC_HEADER_VENDOR_SPECIFIC_PARAMS); res = TRUE; } } if(res == FALSE) { apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Failed to Test Generic Header"); return NULL; } res = FALSE; /* get synthesizer header */ synth_header = mrcp_resource_header_get(request); if(synth_header) { mrcp_synth_header_t *res_synth_header = mrcp_resource_header_prepare(response); /* test voice age header */ if(mrcp_resource_header_property_check(request,SYNTHESIZER_HEADER_VOICE_AGE) == TRUE) { res_synth_header->voice_param.age = SAMPLE_VOICE_AGE; apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Set Voice-Age: %"APR_SIZE_T_FMT,res_synth_header->voice_param.age); mrcp_resource_header_property_add(response,SYNTHESIZER_HEADER_VOICE_AGE); res = TRUE; } } if(res == FALSE) { apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Failed to Test Synthesizer Header"); return NULL; } } return response; }
/** brief Prepare engine to accept audio */ static int uni_recog_start(struct ast_speech *speech) { uni_speech_t *uni_speech = speech->data; mrcp_message_t *mrcp_message; mrcp_generic_header_t *generic_header; mrcp_recog_header_t *recog_header; if(uni_speech->is_inprogress) { uni_recog_stop(speech); } ast_log(LOG_NOTICE, "Start audio '%s'\n",uni_speech_id_get(uni_speech)); mrcp_message = mrcp_application_message_create( uni_speech->session, uni_speech->channel, RECOGNIZER_RECOGNIZE); if(!mrcp_message) { ast_log(LOG_WARNING, "Failed to create MRCP message\n"); return -1; } /* Get/allocate generic header */ generic_header = mrcp_generic_header_prepare(mrcp_message); if(generic_header) { apr_hash_index_t *it; void *val; const char *grammar_name; const char *content = NULL; /* Set generic header fields */ apt_string_assign(&generic_header->content_type,"text/uri-list",mrcp_message->pool); mrcp_generic_header_property_add(mrcp_message,GENERIC_HEADER_CONTENT_TYPE); /* Construct and set message body */ it = apr_hash_first(mrcp_message->pool,uni_speech->active_grammars); if(it) { apr_hash_this(it,NULL,NULL,&val); grammar_name = val; content = apr_pstrcat(mrcp_message->pool,"session:",grammar_name,NULL); it = apr_hash_next(it); } for(; it; it = apr_hash_next(it)) { apr_hash_this(it,NULL,NULL,&val); grammar_name = val; content = apr_pstrcat(mrcp_message->pool,content,"\nsession:",grammar_name,NULL); } if(content) { apt_string_set(&mrcp_message->body,content); } } /* Get/allocate recognizer header */ recog_header = (mrcp_recog_header_t*) mrcp_resource_header_prepare(mrcp_message); if(recog_header) { /* Set recognizer header fields */ if(mrcp_message->start_line.version == MRCP_VERSION_2) { recog_header->cancel_if_queue = FALSE; mrcp_resource_header_property_add(mrcp_message,RECOGNIZER_HEADER_CANCEL_IF_QUEUE); } recog_header->start_input_timers = TRUE; mrcp_resource_header_property_add(mrcp_message,RECOGNIZER_HEADER_START_INPUT_TIMERS); } /* Reset last event (if any) */ uni_speech->mrcp_event = NULL; /* Send MRCP request and wait for response */ if(uni_recog_mrcp_request_send(uni_speech,mrcp_message) != TRUE) { ast_log(LOG_WARNING, "Failed to send MRCP message\n"); return -1; } /* Check received response */ if(!uni_speech->mrcp_response || uni_speech->mrcp_response->start_line.status_code != MRCP_STATUS_CODE_SUCCESS) { ast_log(LOG_WARNING, "Received failure response\n"); return -1; } /* Reset media buffer */ mpf_frame_buffer_restart(uni_speech->media_buffer); ast_speech_change_state(speech, AST_SPEECH_STATE_READY); uni_speech->is_inprogress = TRUE; return 0; }
/** Callback is called from MPF engine context to read/get new frame */ static apt_bool_t demo_synth_stream_read(mpf_audio_stream_t *stream, mpf_frame_t *frame) { demo_synth_channel_t *synth_channel = stream->obj; /* check if STOP was requested */ if(synth_channel->stop_response) { /* send asynchronous response to STOP request */ mrcp_engine_channel_message_send(synth_channel->channel,synth_channel->stop_response); synth_channel->stop_response = NULL; synth_channel->speak_request = NULL; synth_channel->paused = FALSE; if(synth_channel->audio_file) { fclose(synth_channel->audio_file); synth_channel->audio_file = NULL; } return TRUE; } /* check if there is active SPEAK request and it isn't in paused state */ if(synth_channel->speak_request && synth_channel->paused == FALSE) { /* normal processing */ apt_bool_t completed = FALSE; if(synth_channel->audio_file) { /* read speech from file */ apr_size_t size = frame->codec_frame.size; if(fread(frame->codec_frame.buffer,1,size,synth_channel->audio_file) == size) { frame->type |= MEDIA_FRAME_TYPE_AUDIO; } else { completed = TRUE; } } else { /* fill with silence in case no file available */ if(synth_channel->time_to_complete >= CODEC_FRAME_TIME_BASE) { memset(frame->codec_frame.buffer,0,frame->codec_frame.size); frame->type |= MEDIA_FRAME_TYPE_AUDIO; synth_channel->time_to_complete -= CODEC_FRAME_TIME_BASE; } else { completed = TRUE; } } if(completed) { /* raise SPEAK-COMPLETE event */ mrcp_message_t *message = mrcp_event_create( synth_channel->speak_request, SYNTHESIZER_SPEAK_COMPLETE, synth_channel->speak_request->pool); if(message) { /* get/allocate synthesizer header */ mrcp_synth_header_t *synth_header = mrcp_resource_header_prepare(message); if(synth_header) { /* set completion cause */ synth_header->completion_cause = SYNTHESIZER_COMPLETION_CAUSE_NORMAL; mrcp_resource_header_property_add(message,SYNTHESIZER_HEADER_COMPLETION_CAUSE); } /* set request state */ message->start_line.request_state = MRCP_REQUEST_STATE_COMPLETE; synth_channel->speak_request = NULL; if(synth_channel->audio_file) { fclose(synth_channel->audio_file); synth_channel->audio_file = NULL; } /* send asynch event */ mrcp_engine_channel_message_send(synth_channel->channel,message); } } } return TRUE; }