示例#1
0
/** Process VERIFY request */
static apt_bool_t demo_verifier_channel_verify(mrcp_engine_channel_t *channel, mrcp_message_t *request, mrcp_message_t *response)
{
	/* process verify request */
	mrcp_verifier_header_t *verifier_header;
	demo_verifier_channel_t *verifier_channel = channel->method_obj;
	const mpf_codec_descriptor_t *descriptor = mrcp_engine_sink_stream_codec_get(channel);

	if(!descriptor) {
		apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Failed to Get Codec Descriptor "APT_SIDRES_FMT, MRCP_MESSAGE_SIDRES(request));
		response->start_line.status_code = MRCP_STATUS_CODE_METHOD_FAILED;
		return FALSE;
	}

	verifier_channel->timers_started = TRUE;

	/* get verifier header */
	verifier_header = mrcp_resource_header_get(request);
	if(verifier_header) {
		if(mrcp_resource_header_property_check(request,VERIFIER_HEADER_START_INPUT_TIMERS) == TRUE) {
			verifier_channel->timers_started = verifier_header->start_input_timers;
		}
		if(mrcp_resource_header_property_check(request,VERIFIER_HEADER_NO_INPUT_TIMEOUT) == TRUE) {
			mpf_activity_detector_noinput_timeout_set(verifier_channel->detector,verifier_header->no_input_timeout);
		}
		if(mrcp_resource_header_property_check(request,VERIFIER_HEADER_SPEECH_COMPLETE_TIMEOUT) == TRUE) {
			mpf_activity_detector_silence_timeout_set(verifier_channel->detector,verifier_header->speech_complete_timeout);
		}
	}

	if(!verifier_channel->audio_out) {
		const apt_dir_layout_t *dir_layout = channel->engine->dir_layout;
		char *file_name = apr_psprintf(channel->pool,"voiceprint-%dkHz-%s.pcm",
							descriptor->sampling_rate/1000,
							request->channel_id.session_id.buf);
		char *file_path = apt_vardir_filepath_get(dir_layout,file_name,channel->pool);
		if(file_path) {
			apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Open Utterance Output File [%s] for Writing",file_path);
			verifier_channel->audio_out = fopen(file_path,"wb");
			if(!verifier_channel->audio_out) {
				apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Failed to Open Utterance Output File [%s] for Writing",file_path);
			}
		}
	}

	response->start_line.request_state = MRCP_REQUEST_STATE_INPROGRESS;
	/* send asynchronous response */
	mrcp_engine_channel_message_send(channel,response);
	verifier_channel->verifier_request = request;
	return TRUE;
}
/** Process RECORD request */
static apt_bool_t recorder_channel_record(recorder_channel_t *recorder_channel, mrcp_message_t *request, mrcp_message_t *response)
{
	/* process RECORD request */
	mrcp_recorder_header_t *recorder_header;
	recorder_channel->timers_started = TRUE;

	/* get recorder header */
	recorder_header = mrcp_resource_header_get(request);
	if(recorder_header) {
		if(mrcp_resource_header_property_check(request,RECORDER_HEADER_START_INPUT_TIMERS) == TRUE) {
			recorder_channel->timers_started = recorder_header->start_input_timers;
		}
		if(mrcp_resource_header_property_check(request,RECORDER_HEADER_NO_INPUT_TIMEOUT) == TRUE) {
			mpf_activity_detector_noinput_timeout_set(recorder_channel->detector,recorder_header->no_input_timeout);
		}
		if(mrcp_resource_header_property_check(request,RECORDER_HEADER_FINAL_SILENCE) == TRUE) {
			mpf_activity_detector_silence_timeout_set(recorder_channel->detector,recorder_header->final_silence);
		}
		if(mrcp_resource_header_property_check(request,RECORDER_HEADER_MAX_TIME) == TRUE) {
			recorder_channel->max_time = recorder_header->max_time;
		}
	}

	/* open file to record */
	if(recorder_file_open(recorder_channel,request) == FALSE) {
		response->start_line.request_state = MRCP_REQUEST_STATE_COMPLETE;
		response->start_line.status_code = MRCP_STATUS_CODE_METHOD_FAILED;
		/* send asynchronous response */
		mrcp_engine_channel_message_send(recorder_channel->channel,response);
		return TRUE;
	}

	recorder_channel->cur_time = 0;
	recorder_channel->cur_size = 0;
	response->start_line.request_state = MRCP_REQUEST_STATE_INPROGRESS;
	/* send asynchronous response */
	mrcp_engine_channel_message_send(recorder_channel->channel,response);
	recorder_channel->record_request = request;
	return TRUE;
}
/** Process RECOGNIZE request */
static apt_bool_t demo_recog_channel_recognize(mrcp_engine_channel_t *channel, mrcp_message_t *request, mrcp_message_t *response)
{
	/* process RECOGNIZE request */
	mrcp_recog_header_t *recog_header;
	demo_recog_channel_t *recog_channel = channel->method_obj;
	recog_channel->timers_started = TRUE;

	/* get recognizer header */
	recog_header = mrcp_resource_header_get(request);
	if(recog_header) {
		if(mrcp_resource_header_property_check(request,RECOGNIZER_HEADER_START_INPUT_TIMERS) == TRUE) {
			recog_channel->timers_started = recog_header->start_input_timers;
		}
		if(mrcp_resource_header_property_check(request,RECOGNIZER_HEADER_NO_INPUT_TIMEOUT) == TRUE) {
			mpf_activity_detector_noinput_timeout_set(recog_channel->detector,recog_header->no_input_timeout);
		}
		if(mrcp_resource_header_property_check(request,RECOGNIZER_HEADER_SPEECH_COMPLETE_TIMEOUT) == TRUE) {
			mpf_activity_detector_silence_timeout_set(recog_channel->detector,recog_header->speech_complete_timeout);
		}
	}

	if(!recog_channel->audio_out) {
		const apt_dir_layout_t *dir_layout = channel->engine->dir_layout;
		const mpf_codec_descriptor_t *descriptor = mrcp_engine_sink_stream_codec_get(channel);
		char *file_name = apr_psprintf(channel->pool,"utter-%dkHz-%s.pcm",
			descriptor ? descriptor->sampling_rate/1000 : 8,
			request->channel_id.session_id.buf);
		char *file_path = apt_datadir_filepath_get(dir_layout,file_name,channel->pool);
		if(file_path) {
			recog_channel->audio_out = fopen(file_path,"wb");
		}
	}

	response->start_line.request_state = MRCP_REQUEST_STATE_INPROGRESS;
	/* send asynchronous response */
	mrcp_engine_channel_message_send(channel,response);
	recog_channel->recog_request = request;
	return TRUE;
}