예제 #1
0
/* Raise demo VERIFICATION-COMPLETE event */
static apt_bool_t demo_verifier_verification_complete(demo_verifier_channel_t *verifier_channel, mrcp_verifier_completion_cause_e cause)
{
	mrcp_verifier_header_t *verifier_header;
	/* create VERIFICATION-COMPLETE event */
	mrcp_message_t *message = mrcp_event_create(
						verifier_channel->verifier_request,
						VERIFIER_VERIFICATION_COMPLETE,
						verifier_channel->verifier_request->pool);
	if(!message) {
		return FALSE;
	}

	/* get/allocate verifier header */
	verifier_header = mrcp_resource_header_prepare(message);
	if(verifier_header) {
		/* set completion cause */
		verifier_header->completion_cause = cause;
		mrcp_resource_header_property_add(message,VERIFIER_HEADER_COMPLETION_CAUSE);
	}
	/* set request state */
	message->start_line.request_state = MRCP_REQUEST_STATE_COMPLETE;

	if(cause == VERIFIER_COMPLETION_CAUSE_SUCCESS) {
		demo_verifier_result_load(verifier_channel,message);
	}

	verifier_channel->verifier_request = NULL;
	/* send asynch event */
	return mrcp_engine_channel_message_send(verifier_channel->channel,message);
}
예제 #2
0
/** Process SPEAK request */
static apt_bool_t demo_synth_channel_speak(mrcp_engine_channel_t *channel, mrcp_message_t *request, mrcp_message_t *response)
{
	char *file_path;
	demo_synth_channel_t *synth_channel = channel->method_obj;
	synth_channel->time_to_complete = 0;
	file_path = apt_datadir_filepath_get(channel->engine->dir_layout,DEMO_SPEECH_SOURCE_FILE,channel->pool);
	if(file_path) {
		synth_channel->audio_file = fopen(file_path,"rb");
		if(synth_channel->audio_file) {
			apt_log(APT_PRIO_INFO,"Set [%s] as Speech Source",file_path);
		}
		else {
			apt_log(APT_PRIO_INFO,"No Speech Source [%s] Found",file_path);
			/* calculate estimated time to complete */
			if(mrcp_generic_header_property_check(request,GENERIC_HEADER_CONTENT_LENGTH) == TRUE) {
				mrcp_generic_header_t *generic_header = mrcp_generic_header_get(request);
				if(generic_header) {
					synth_channel->time_to_complete = generic_header->content_length * 10; /* 10 msec per character */
				}
			}
		}
	}
	
	response->start_line.request_state = MRCP_REQUEST_STATE_INPROGRESS;
	/* send asynchronous response */
	mrcp_engine_channel_message_send(channel,response);
	synth_channel->speak_request = request;
	return TRUE;
}
예제 #3
0
/* Raise demo RECOGNITION-COMPLETE event */
static apt_bool_t demo_recog_recognition_complete(demo_recog_channel_t *recog_channel, mrcp_recog_completion_cause_e cause)
{
	mrcp_recog_header_t *recog_header;
	/* create RECOGNITION-COMPLETE event */
	mrcp_message_t *message = mrcp_event_create(
						recog_channel->recog_request,
						RECOGNIZER_RECOGNITION_COMPLETE,
						recog_channel->recog_request->pool);
	if(!message) {
		return FALSE;
	}

	/* get/allocate recognizer header */
	recog_header = mrcp_resource_header_prepare(message);
	if(recog_header) {
		/* set completion cause */
		recog_header->completion_cause = cause;
		mrcp_resource_header_property_add(message,RECOGNIZER_HEADER_COMPLETION_CAUSE);
	}
	/* set request state */
	message->start_line.request_state = MRCP_REQUEST_STATE_COMPLETE;

	if(cause == RECOGNIZER_COMPLETION_CAUSE_SUCCESS) {
		demo_recog_result_load(recog_channel,message);
	}

	recog_channel->recog_request = NULL;
	/* send asynch event */
	return mrcp_engine_channel_message_send(recog_channel->channel,message);
}
예제 #4
0
/** Process MRCP channel request (asynchronous response MUST be sent)*/
static apt_bool_t recorder_channel_request_process(mrcp_engine_channel_t *channel, mrcp_message_t *request)
{
	apt_bool_t processed = FALSE;
	recorder_channel_t *recorder_channel = channel->method_obj;
	mrcp_message_t *response = mrcp_response_create(request,request->pool);
	switch(request->start_line.method_id) {
		case RECORDER_SET_PARAMS:
			break;
		case RECORDER_GET_PARAMS:
			break;
		case RECORDER_RECORD:
			processed = recorder_channel_record(recorder_channel,request,response);
			break;
		case RECORDER_STOP:
			processed = recorder_channel_stop(recorder_channel,request,response);
			break;
		case RECORDER_START_INPUT_TIMERS:
			processed = recorder_channel_timers_start(recorder_channel,request,response);
			break;
		default:
			break;
	}
	if(processed == FALSE) {
		/* send asynchronous response for not handled request */
		mrcp_engine_channel_message_send(channel,response);
	}
	return TRUE;
}
예제 #5
0
/** Dispatch MRCP request */
static apt_bool_t demo_recog_channel_request_dispatch(mrcp_engine_channel_t *channel, mrcp_message_t *request)
{
	apt_bool_t processed = FALSE;
	mrcp_message_t *response = mrcp_response_create(request,request->pool);
	switch(request->start_line.method_id) {
		case RECOGNIZER_SET_PARAMS:
			break;
		case RECOGNIZER_GET_PARAMS:
			break;
		case RECOGNIZER_DEFINE_GRAMMAR:
			break;
		case RECOGNIZER_RECOGNIZE:
			processed = demo_recog_channel_recognize(channel,request,response);
			break;
		case RECOGNIZER_GET_RESULT:
			break;
		case RECOGNIZER_START_INPUT_TIMERS:
			processed = demo_recog_channel_timers_start(channel,request,response);
			break;
		case RECOGNIZER_STOP:
			processed = demo_recog_channel_stop(channel,request,response);
			break;
		default:
			break;
	}
	if(processed == FALSE) {
		/* send asynchronous response for not handled request */
		mrcp_engine_channel_message_send(channel,response);
	}
	return TRUE;
}
예제 #6
0
/** Raise SPEAK-COMPLETE event */
static apt_bool_t synth_speak_complete_raise(mrcp_swift_channel_t *synth_channel)
{
	mrcp_message_t *message;
	mrcp_synth_header_t *synth_header;
	if(!synth_channel->speak_request) {
		return FALSE;
	}
	message = mrcp_event_create(
						synth_channel->speak_request,
						SYNTHESIZER_SPEAK_COMPLETE,
						synth_channel->speak_request->pool);
	if(!message) {
		return FALSE;
	}
	
	/* get/allocate synthesizer header */
	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;
	/* send asynch event */
	return mrcp_engine_channel_message_send(synth_channel->channel,message);
}
예제 #7
0
/* Raise RECORD-COMPLETE event */
static apt_bool_t recorder_record_complete(recorder_channel_t *recorder_channel, mrcp_recorder_completion_cause_e cause)
{
	mrcp_recorder_header_t *recorder_header;
	/* create RECORD-COMPLETE event */
	mrcp_message_t *message = mrcp_event_create(
						recorder_channel->record_request,
						RECORDER_RECORD_COMPLETE,
						recorder_channel->record_request->pool);
	if(!message) {
		return FALSE;
	}

	if(recorder_channel->audio_out) {
		fclose(recorder_channel->audio_out);
		recorder_channel->audio_out = NULL;
	}

	/* get/allocate recorder header */
	recorder_header = mrcp_resource_header_prepare(message);
	if(recorder_header) {
		/* set completion cause */
		recorder_header->completion_cause = cause;
		mrcp_resource_header_property_add(message,RECORDER_HEADER_COMPLETION_CAUSE);
	}
	/* set record-uri */
	recorder_channel_uri_set(recorder_channel,message);
	/* set request state */
	message->start_line.request_state = MRCP_REQUEST_STATE_COMPLETE;

	recorder_channel->record_request = NULL;
	/* send asynch event */
	return mrcp_engine_channel_message_send(recorder_channel->channel,message);
}
예제 #8
0
/** Process PAUSE request */
static apt_bool_t demo_synth_channel_pause(mrcp_engine_channel_t *channel, mrcp_message_t *request, mrcp_message_t *response)
{
	demo_synth_channel_t *synth_channel = channel->method_obj;
	synth_channel->paused = TRUE;
	/* send asynchronous response */
	mrcp_engine_channel_message_send(channel,response);
	return TRUE;
}
예제 #9
0
/** Process RESUME request */
static apt_bool_t mrcp_swift_channel_resume(mrcp_engine_channel_t *channel, mrcp_message_t *request, mrcp_message_t *response)
{
	mrcp_swift_channel_t *synth_channel = channel->method_obj;
	synth_channel->paused = FALSE;
	/* send asynchronous response */
	mrcp_engine_channel_message_send(channel,response);
	return TRUE;
}
예제 #10
0
/** Callback is called from MPF engine context to write/send new frame */
static apt_bool_t demo_verifier_stream_write(mpf_audio_stream_t *stream, const mpf_frame_t *frame)
{
	demo_verifier_channel_t *verifier_channel = stream->obj;
	if(verifier_channel->stop_response) {
		/* send asynchronous response to STOP request */
		mrcp_engine_channel_message_send(verifier_channel->channel,verifier_channel->stop_response);
		verifier_channel->stop_response = NULL;
		verifier_channel->verifier_request = NULL;
		return TRUE;
	}

	if(verifier_channel->verifier_request) {
		mpf_detector_event_e det_event = mpf_activity_detector_process(verifier_channel->detector,frame);
		switch(det_event) {
			case MPF_DETECTOR_EVENT_ACTIVITY:
				apt_log(VERIF_LOG_MARK,APT_PRIO_INFO,"Detected Voice Activity " APT_SIDRES_FMT,
					MRCP_MESSAGE_SIDRES(verifier_channel->verifier_request));
				demo_verifier_start_of_input(verifier_channel);
				break;
			case MPF_DETECTOR_EVENT_INACTIVITY:
				apt_log(VERIF_LOG_MARK,APT_PRIO_INFO,"Detected Voice Inactivity " APT_SIDRES_FMT,
					MRCP_MESSAGE_SIDRES(verifier_channel->verifier_request));
				demo_verifier_verification_complete(verifier_channel,VERIFIER_COMPLETION_CAUSE_SUCCESS);
				break;
			case MPF_DETECTOR_EVENT_NOINPUT:
				apt_log(VERIF_LOG_MARK,APT_PRIO_INFO,"Detected Noinput " APT_SIDRES_FMT,
					MRCP_MESSAGE_SIDRES(verifier_channel->verifier_request));
				if(verifier_channel->timers_started == TRUE) {
					demo_verifier_verification_complete(verifier_channel,VERIFIER_COMPLETION_CAUSE_NO_INPUT_TIMEOUT);
				}
				break;
			default:
				break;
		}

		if(verifier_channel->verifier_request) {
			if((frame->type & MEDIA_FRAME_TYPE_EVENT) == MEDIA_FRAME_TYPE_EVENT) {
				if(frame->marker == MPF_MARKER_START_OF_EVENT) {
					apt_log(VERIF_LOG_MARK,APT_PRIO_INFO,"Detected Start of Event " APT_SIDRES_FMT " id:%d",
						MRCP_MESSAGE_SIDRES(verifier_channel->verifier_request),
						frame->event_frame.event_id);
				}
				else if(frame->marker == MPF_MARKER_END_OF_EVENT) {
					apt_log(VERIF_LOG_MARK,APT_PRIO_INFO,"Detected End of Event " APT_SIDRES_FMT " id:%d duration:%d ts",
						MRCP_MESSAGE_SIDRES(verifier_channel->verifier_request),
						frame->event_frame.event_id,
						frame->event_frame.duration);
				}
			}
		}

		if(verifier_channel->audio_out) {
			fwrite(frame->codec_frame.buffer,1,frame->codec_frame.size,verifier_channel->audio_out);
		}
	}
	return TRUE;
}
예제 #11
0
/** Process CONTROL request */
static apt_bool_t mrcp_swift_channel_control(mrcp_engine_channel_t *channel, mrcp_message_t *request, mrcp_message_t *response)
{
	mrcp_swift_channel_t *synth_channel = channel->method_obj;
	/* set params */
	mrcp_swift_channel_params_set(synth_channel,request);
	/* send asynchronous response */
	mrcp_engine_channel_message_send(channel,response);
	return TRUE;
}
예제 #12
0
/** Callback is called from MPF engine context to write/send new frame */
static apt_bool_t recorder_stream_write(mpf_audio_stream_t *stream, const mpf_frame_t *frame)
{
	recorder_channel_t *recorder_channel = stream->obj;
	if(recorder_channel->stop_response) {
		if(recorder_channel->audio_out) {
			fclose(recorder_channel->audio_out);
			recorder_channel->audio_out = NULL;
		}
		
		if(recorder_channel->record_request){
			/* set record-uri */
			recorder_channel_uri_set(recorder_channel,recorder_channel->stop_response);
		}
		/* send asynchronous response to STOP request */
		mrcp_engine_channel_message_send(recorder_channel->channel,recorder_channel->stop_response);
		recorder_channel->stop_response = NULL;
		recorder_channel->record_request = NULL;
		return TRUE;
	}

	if(recorder_channel->record_request) {
		mpf_detector_event_e det_event = mpf_activity_detector_process(recorder_channel->detector,frame);
		switch(det_event) {
			case MPF_DETECTOR_EVENT_ACTIVITY:
				apt_log(RECORD_LOG_MARK,APT_PRIO_INFO,"Detected Voice Activity "APT_SIDRES_FMT,
					MRCP_MESSAGE_SIDRES(recorder_channel->record_request));
				recorder_start_of_input(recorder_channel);
				break;
			case MPF_DETECTOR_EVENT_INACTIVITY:
				apt_log(RECORD_LOG_MARK,APT_PRIO_INFO,"Detected Voice Inactivity "APT_SIDRES_FMT,
					MRCP_MESSAGE_SIDRES(recorder_channel->record_request));
				recorder_record_complete(recorder_channel,RECORDER_COMPLETION_CAUSE_SUCCESS_SILENCE);
				break;
			case MPF_DETECTOR_EVENT_NOINPUT:
				apt_log(RECORD_LOG_MARK,APT_PRIO_INFO,"Detected Noinput "APT_SIDRES_FMT,
					MRCP_MESSAGE_SIDRES(recorder_channel->record_request));
				if(recorder_channel->timers_started == TRUE) {
					recorder_record_complete(recorder_channel,RECORDER_COMPLETION_CAUSE_NO_INPUT_TIMEOUT);
				}
				break;
			default:
				break;
		}

		if(recorder_channel->audio_out) {
			fwrite(frame->codec_frame.buffer,1,frame->codec_frame.size,recorder_channel->audio_out);
			
			recorder_channel->cur_size += frame->codec_frame.size;
			recorder_channel->cur_time += CODEC_FRAME_TIME_BASE;
			if(recorder_channel->max_time && recorder_channel->cur_time >= recorder_channel->max_time) {
				recorder_record_complete(recorder_channel,RECORDER_COMPLETION_CAUSE_SUCCESS_MAXTIME);
			}
		}
	}
	return TRUE;
}
예제 #13
0
/** 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;
}
예제 #14
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;
}
예제 #15
0
/* Raise START-OF-INPUT event */
static apt_bool_t recorder_start_of_input(recorder_channel_t *recorder_channel)
{
	/* create START-OF-INPUT event */
	mrcp_message_t *message = mrcp_event_create(
						recorder_channel->record_request,
						RECORDER_START_OF_INPUT,
						recorder_channel->record_request->pool);
	if(!message) {
		return FALSE;
	}

	/* set request state */
	message->start_line.request_state = MRCP_REQUEST_STATE_INPROGRESS;
	/* send asynch event */
	return mrcp_engine_channel_message_send(recorder_channel->channel,message);
}
예제 #16
0
/* Raise demo START-OF-INPUT event */
static apt_bool_t demo_verifier_start_of_input(demo_verifier_channel_t *verifier_channel)
{
	/* create START-OF-INPUT event */
	mrcp_message_t *message = mrcp_event_create(
						verifier_channel->verifier_request,
						VERIFIER_START_OF_INPUT,
						verifier_channel->verifier_request->pool);
	if(!message) {
		return FALSE;
	}

	/* set request state */
	message->start_line.request_state = MRCP_REQUEST_STATE_INPROGRESS;
	/* send asynch event */
	return mrcp_engine_channel_message_send(verifier_channel->channel,message);
}
예제 #17
0
/** Dispatch MRCP request */
static apt_bool_t demo_verifier_channel_request_dispatch(mrcp_engine_channel_t *channel, mrcp_message_t *request)
{
	apt_bool_t processed = FALSE;
	mrcp_message_t *response = mrcp_response_create(request,request->pool);
	switch(request->start_line.method_id) {
		case VERIFIER_SET_PARAMS:
			break;
		case VERIFIER_GET_PARAMS:
			break;
		case VERIFIER_START_SESSION:
			break;
		case VERIFIER_END_SESSION:
			break;
		case VERIFIER_QUERY_VOICEPRINT:
			break;
		case VERIFIER_DELETE_VOICEPRINT:
			break;
		case VERIFIER_VERIFY:
			processed = demo_verifier_channel_verify(channel,request,response);
			break;
		case VERIFIER_VERIFY_FROM_BUFFER:
			break;
		case VERIFIER_VERIFY_ROLLBACK:
			break;
		case VERIFIER_STOP:
			processed = demo_verifier_channel_stop(channel,request,response);
			break;
		case VERIFIER_CLEAR_BUFFER:
			break;
		case VERIFIER_START_INPUT_TIMERS:
			processed = demo_verifier_channel_timers_start(channel,request,response);
			break;
		case VERIFIER_GET_INTERMIDIATE_RESULT:
			processed = demo_verifier_channel_get_result(channel,request,response);
			break;
			
		default:
			break;
	}
	if(processed == FALSE) {
		/* send asynchronous response for not handled request */
		mrcp_engine_channel_message_send(channel,response);
	}
	return TRUE;
}
예제 #18
0
/** Process SPEAK request */
static apt_bool_t demo_synth_channel_speak(mrcp_engine_channel_t *channel, mrcp_message_t *request, mrcp_message_t *response)
{
	char *file_path = NULL;
	demo_synth_channel_t *synth_channel = channel->method_obj;
	const mpf_codec_descriptor_t *descriptor = mrcp_engine_source_stream_codec_get(channel);

	if(!descriptor) {
		apt_log(SYNTH_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;
	}

	synth_channel->time_to_complete = 0;
	if(channel->engine) {
		char *file_name = apr_psprintf(channel->pool,"demo-%dkHz.pcm",descriptor->sampling_rate/1000);
		file_path = apt_datadir_filepath_get(channel->engine->dir_layout,file_name,channel->pool);
	}
	if(file_path) {
		synth_channel->audio_file = fopen(file_path,"rb");
		if(synth_channel->audio_file) {
			apt_log(SYNTH_LOG_MARK,APT_PRIO_INFO,"Set [%s] as Speech Source "APT_SIDRES_FMT,
				file_path,
				MRCP_MESSAGE_SIDRES(request));
		}
		else {
			apt_log(SYNTH_LOG_MARK,APT_PRIO_INFO,"No Speech Source [%s] Found "APT_SIDRES_FMT,
				file_path,
				MRCP_MESSAGE_SIDRES(request));
			/* calculate estimated time to complete */
			if(mrcp_generic_header_property_check(request,GENERIC_HEADER_CONTENT_LENGTH) == TRUE) {
				mrcp_generic_header_t *generic_header = mrcp_generic_header_get(request);
				if(generic_header) {
					synth_channel->time_to_complete = generic_header->content_length * 10; /* 10 msec per character */
				}
			}
		}
	}

	response->start_line.request_state = MRCP_REQUEST_STATE_INPROGRESS;
	/* send asynchronous response */
	mrcp_engine_channel_message_send(channel,response);
	synth_channel->speak_request = request;
	return TRUE;
}
예제 #19
0
/** Process SPEAK request */
static apt_bool_t mrcp_swift_channel_speak(mrcp_engine_channel_t *channel, mrcp_message_t *request, mrcp_message_t *response)
{
	mrcp_swift_channel_t *synth_channel = channel->method_obj;

	/* set voice */
	mrcp_swift_channel_voice_set(synth_channel,request);
	/* set params */
	mrcp_swift_channel_params_set(synth_channel,request);
	/* (re)start audio buffer */
	mpf_buffer_restart(synth_channel->audio_buffer);
	response->start_line.request_state = MRCP_REQUEST_STATE_INPROGRESS;
	/* start to synthesize */
	if(swift_port_speak_text(synth_channel->port,request->body.buf,0,NULL,&synth_channel->tts_stream,NULL) != SWIFT_SUCCESS) {
		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(channel,response);
	synth_channel->speak_request = request;
	return TRUE;
}
예제 #20
0
/** 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;
}
예제 #21
0
/** Dispatch MRCP request */
static apt_bool_t demo_synth_channel_request_dispatch(mrcp_engine_channel_t *channel, mrcp_message_t *request)
{
	apt_bool_t processed = FALSE;
	mrcp_message_t *response = mrcp_response_create(request,request->pool);
	switch(request->start_line.method_id) {
		case SYNTHESIZER_SET_PARAMS:
			processed = demo_synth_channel_set_params(channel,request,response);
			break;
		case SYNTHESIZER_GET_PARAMS:
			processed = demo_synth_channel_get_params(channel,request,response);
			break;
		case SYNTHESIZER_SPEAK:
			processed = demo_synth_channel_speak(channel,request,response);
			break;
		case SYNTHESIZER_STOP:
			processed = demo_synth_channel_stop(channel,request,response);
			break;
		case SYNTHESIZER_PAUSE:
			processed = demo_synth_channel_pause(channel,request,response);
			break;
		case SYNTHESIZER_RESUME:
			processed = demo_synth_channel_resume(channel,request,response);
			break;
		case SYNTHESIZER_BARGE_IN_OCCURRED:
			processed = demo_synth_channel_stop(channel,request,response);
			break;
		case SYNTHESIZER_CONTROL:
			break;
		case SYNTHESIZER_DEFINE_LEXICON:
			break;
		default:
			break;
	}
	if(processed == FALSE) {
		/* send asynchronous response for not handled request */
		mrcp_engine_channel_message_send(channel,response);
	}
	return TRUE;
}
예제 #22
0
/** Process SET-PARAMS request */
static apt_bool_t demo_synth_channel_set_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) {
		/* check voice age header */
		if(mrcp_resource_header_property_check(request,SYNTHESIZER_HEADER_VOICE_AGE) == TRUE) {
			apt_log(SYNTH_LOG_MARK,APT_PRIO_INFO,"Set Voice Age [%"APR_SIZE_T_FMT"]",
				req_synth_header->voice_param.age);
		}
		/* check voice name header */
		if(mrcp_resource_header_property_check(request,SYNTHESIZER_HEADER_VOICE_NAME) == TRUE) {
			apt_log(SYNTH_LOG_MARK,APT_PRIO_INFO,"Set Voice Name [%s]",
				req_synth_header->voice_param.name.buf);
		}
	}
	
	/* send asynchronous response */
	mrcp_engine_channel_message_send(channel,response);
	return TRUE;
}
예제 #23
0
/** 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;
}
예제 #24
0
/** Callback is called from MPF engine context to read/get new frame */
static apt_bool_t synth_stream_read(mpf_audio_stream_t *stream, mpf_frame_t *frame)
{
	mrcp_swift_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;
		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 */
		mpf_buffer_frame_read(synth_channel->audio_buffer,frame);
		
		if((frame->type & MEDIA_FRAME_TYPE_EVENT) == MEDIA_FRAME_TYPE_EVENT) {
			synth_speak_complete_raise(synth_channel);
		}
	}
	return TRUE;
}
예제 #25
0
/** Process GET-INTERMEDIATE-RESULT request */
static apt_bool_t demo_verifier_channel_get_result(mrcp_engine_channel_t *channel, mrcp_message_t *request, mrcp_message_t *response)
{
	demo_verifier_channel_t *verifier_channel = channel->method_obj;
	demo_verifier_result_load(verifier_channel,response);
	return mrcp_engine_channel_message_send(channel,response);
}
예제 #26
0
/** Process START-INPUT-TIMERS request */
static apt_bool_t demo_verifier_channel_timers_start(mrcp_engine_channel_t *channel, mrcp_message_t *request, mrcp_message_t *response)
{
	demo_verifier_channel_t *verifier_channel = channel->method_obj;
	verifier_channel->timers_started = TRUE;
	return mrcp_engine_channel_message_send(channel,response);
}
예제 #27
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;
}
예제 #28
0
/** Process START-INPUT-TIMERS request */
static apt_bool_t recorder_channel_timers_start(recorder_channel_t *recorder_channel, mrcp_message_t *request, mrcp_message_t *response)
{
	recorder_channel->timers_started = TRUE;
	return mrcp_engine_channel_message_send(recorder_channel->channel,response);
}