Exemplo n.º 1
0
/** Open file to record */
static apt_bool_t recorder_file_open(recorder_channel_t *recorder_channel, mrcp_message_t *request)
{
	mrcp_engine_channel_t *channel = recorder_channel->channel;
	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,"rec-%dkHz-%s-%"MRCP_REQUEST_ID_FMT".pcm",
		descriptor ? descriptor->sampling_rate/1000 : 8,
		request->channel_id.session_id.buf,
		request->start_line.request_id);
	char *file_path = apt_datadir_filepath_get(dir_layout,file_name,channel->pool);
	if(!file_path) {
		return FALSE;
	}

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

	recorder_channel->audio_out = fopen(file_path,"wb");
	if(!recorder_channel->audio_out) {
		return FALSE;
	}

	recorder_channel->file_name = file_name;
	return TRUE;
}
Exemplo n.º 2
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 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;
}
Exemplo n.º 4
0
/** Open file to record */
static apt_bool_t recorder_file_open(recorder_channel_t *recorder_channel, mrcp_message_t *request)
{
	char *file_path;
	char *file_name;
	mrcp_engine_channel_t *channel = recorder_channel->channel;
	const apt_dir_layout_t *dir_layout = channel->engine->dir_layout;
	const mpf_codec_descriptor_t *descriptor = mrcp_engine_sink_stream_codec_get(channel);

	if(!descriptor) {
		apt_log(RECORD_LOG_MARK,APT_PRIO_WARNING,"Failed to Get Codec Descriptor "APT_SIDRES_FMT, MRCP_MESSAGE_SIDRES(request));
		return FALSE;
	}

	file_name = apr_psprintf(channel->pool,"rec-%dkHz-%s-%"MRCP_REQUEST_ID_FMT".pcm",
		descriptor->sampling_rate/1000,
		request->channel_id.session_id.buf,
		request->start_line.request_id);
	file_path = apt_vardir_filepath_get(dir_layout,file_name,channel->pool);
	if(!file_path) {
		return FALSE;
	}

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

	apt_log(RECORD_LOG_MARK,APT_PRIO_INFO,"Open Utterance Output File [%s] for Writing",file_path);
	recorder_channel->audio_out = fopen(file_path,"wb");
	if(!recorder_channel->audio_out) {
		apt_log(RECORD_LOG_MARK,APT_PRIO_WARNING,"Failed to Open Utterance Output File [%s] for Writing",file_path);
		return FALSE;
	}

	recorder_channel->file_name = file_name;
	return TRUE;
}