Exemplo n.º 1
0
static apt_bool_t mrcp_client_message_handler(mrcp_connection_t *connection, mrcp_message_t *message, apt_message_status_e status)
{
	if(status == APT_MESSAGE_STATUS_COMPLETE) {
		/* message is completely parsed */
		mrcp_control_channel_t *channel;
		apt_str_t identifier;
		apt_id_resource_generate(&message->channel_id.session_id,&message->channel_id.resource_name,'@',&identifier,message->pool);
		channel = mrcp_connection_channel_find(connection,&identifier);
		if(channel) {
			mrcp_connection_agent_t *agent = connection->agent;
			if(message->start_line.message_type == MRCP_MESSAGE_TYPE_RESPONSE) {
				if(!channel->active_request || 
					channel->active_request->start_line.request_id != message->start_line.request_id) {
					apt_obj_log(APT_LOG_MARK,APT_PRIO_WARNING,channel->log_obj,"Unexpected MRCP Response "APT_SIDRES_FMT" [%d]",
						MRCP_MESSAGE_SIDRES(message),
						message->start_line.request_id);
					return FALSE;
				}
				if(channel->request_timer) {
					apt_timer_kill(channel->request_timer);
				}
				channel->active_request = NULL;
			}

			mrcp_connection_message_receive(agent->vtable,channel,message);
		}
		else {
			apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Failed to Find Channel "APT_SIDRES_FMT" in Connection %s [%d]",
				MRCP_MESSAGE_SIDRES(message),
				connection->id,
				apr_hash_count(connection->channel_table));
		}
	}
	return TRUE;
}
Exemplo n.º 2
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;
}
Exemplo n.º 3
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;
}
/** Update state according to received outgoing response from recognition engine */
static apt_bool_t recog_response_state_update(mrcp_recog_state_machine_t *state_machine, mrcp_message_t *message)
{
	recog_method_f method;
	if(!state_machine->active_request) {
		/* unexpected response, no active request waiting for response */
		return FALSE;
	}
	if(state_machine->active_request->start_line.request_id != message->start_line.request_id) {
		/* unexpected response, request id doesn't match */
		return FALSE;
	}

	if(message->start_line.method_id >= RECOGNIZER_METHOD_COUNT) {
		return FALSE;
	}
	
	apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Process %s Response "APT_SIDRES_FMT" [%"MRCP_REQUEST_ID_FMT"]",
		message->start_line.method_name.buf,
		MRCP_MESSAGE_SIDRES(message),
		message->start_line.request_id);
	method = recog_response_method_array[message->start_line.method_id];
	if(method) {
		return method(state_machine,message);
	}
	return recog_response_dispatch(state_machine,message);
}
/** Deactivate state machine */
static apt_bool_t recog_state_deactivate(mrcp_state_machine_t *base)
{
	mrcp_recog_state_machine_t *state_machine = (mrcp_recog_state_machine_t*)base;
	mrcp_message_t *message;
	mrcp_message_t *source;
	if(state_machine->state != RECOGNIZER_STATE_RECOGNIZING) {
		/* no in-progress RECOGNIZE request to deactivate */
		return FALSE;
	}
	source = state_machine->recog;
	if(!source) {
		return FALSE;
	}

	/* create internal STOP request */
	message = mrcp_request_create(
						source->resource,
						source->start_line.version,
						RECOGNIZER_STOP,
						source->pool);
	message->channel_id = source->channel_id;
	message->start_line.request_id = source->start_line.request_id + 1;
	apt_string_set(&message->start_line.method_name,"DEACTIVATE"); /* informative only */
	message->header = source->header;
	apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Create and Process STOP Request "APT_SIDRES_FMT" [%"MRCP_REQUEST_ID_FMT"]",
		MRCP_MESSAGE_SIDRES(message),
		message->start_line.request_id);
	return recog_request_dispatch(state_machine,message);
}
Exemplo n.º 6
0
static apt_bool_t mrcp_server_message_handler(mrcp_connection_t *connection, mrcp_message_t *message, apt_message_status_e status)
{
	mrcp_connection_agent_t *agent = connection->agent;
	if(status == APT_MESSAGE_STATUS_COMPLETE) {
		/* message is completely parsed */
		mrcp_control_channel_t *channel = mrcp_connection_channel_associate(agent,connection,message);
		if(channel) {
			mrcp_connection_message_receive(agent->vtable,channel,message);
		}
		else {
			apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Failed to Find Channel "APT_SIDRES_FMT" in Connection %s",
				MRCP_MESSAGE_SIDRES(message),
				connection->id);
		}
	}
	else if(status == APT_MESSAGE_STATUS_INVALID) {
		/* error case */
		apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Failed to Parse MRCPv2 Data");
		if(message && message->resource) {
			mrcp_message_t *response;
			response = mrcp_response_create(message,message->pool);
			response->start_line.status_code = MRCP_STATUS_CODE_UNRECOGNIZED_MESSAGE;
			if(mrcp_server_agent_messsage_send(agent,connection,response) == FALSE) {
				apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Failed to Send MRCPv2 Response");
			}
		}
	}
	return TRUE;
}
static apt_bool_t recog_request_stop(mrcp_recog_state_machine_t *state_machine, mrcp_message_t *message)
{
	mrcp_message_t *response_message;
	if(state_machine->state == RECOGNIZER_STATE_RECOGNIZING) {
		mrcp_request_id_list_t *request_id_list = NULL;
		mrcp_generic_header_t *generic_header = mrcp_generic_header_get(message);
		if(generic_header && mrcp_generic_header_property_check(message,GENERIC_HEADER_ACTIVE_REQUEST_ID_LIST) == TRUE) {
			if(generic_header->active_request_id_list.count) {
				/* selective STOP request */
				request_id_list = &generic_header->active_request_id_list;
			}
		}

		if(!request_id_list || active_request_id_list_find(generic_header,state_machine->recog->start_line.request_id) == TRUE) {
			/* found in-progress RECOGNIZE request, stop it */
			apt_log(APT_LOG_MARK,APT_PRIO_DEBUG,"Found IN-PROGRESS RECOGNIZE Request "APT_SIDRES_FMT" [%"MRCP_REQUEST_ID_FMT"]",
				MRCP_MESSAGE_SIDRES(message),
				message->start_line.request_id);
			return recog_request_dispatch(state_machine,message);
		}
	}
	else if(state_machine->state == RECOGNIZER_STATE_RECOGNIZED) {
		recog_state_change(state_machine,RECOGNIZER_STATE_IDLE,message);
	}

	/* found no in-progress RECOGNIZE request, sending immediate response */
	response_message = mrcp_response_create(message,message->pool);
	recog_pending_requests_remove(state_machine,message,response_message);
	return recog_response_dispatch(state_machine,response_message);
}
static apt_bool_t recog_pending_requests_remove(mrcp_recog_state_machine_t *state_machine, mrcp_message_t *request_message, mrcp_message_t *response_message)
{
	apt_list_elem_t *elem;
	mrcp_message_t *pending_message;
	mrcp_request_id_list_t *request_id_list = NULL;
	mrcp_generic_header_t *generic_header = mrcp_generic_header_get(request_message);
	mrcp_generic_header_t *response_generic_header = mrcp_generic_header_prepare(response_message);
	if(generic_header && mrcp_generic_header_property_check(request_message,GENERIC_HEADER_ACTIVE_REQUEST_ID_LIST) == TRUE) {
		if(generic_header->active_request_id_list.count) {
			/* selective STOP request */
			request_id_list = &generic_header->active_request_id_list;
		}
	}

	elem = apt_list_first_elem_get(state_machine->queue);
	while(elem) {
		pending_message = apt_list_elem_object_get(elem);
		if(!request_id_list || active_request_id_list_find(generic_header,pending_message->start_line.request_id) == TRUE) {
			apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Remove Pending RECOGNIZE Request "APT_SIDRES_FMT" [%"MRCP_REQUEST_ID_FMT"]",
				MRCP_MESSAGE_SIDRES(pending_message),
				pending_message->start_line.request_id);
			elem = apt_list_elem_remove(state_machine->queue,elem);
			/* append active id list */
			active_request_id_list_append(response_generic_header,pending_message->start_line.request_id);
		}
		else {
			/* speak request remains in the queue, just proceed to the next one */
			elem = apt_list_next_elem_get(state_machine->queue,elem);
		}
	}
	if(response_generic_header->active_request_id_list.count) {
		mrcp_generic_header_property_add(response_message,GENERIC_HEADER_ACTIVE_REQUEST_ID_LIST);
	}
	return TRUE;
}
Exemplo n.º 9
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;
}
Exemplo n.º 10
0
static apt_bool_t mrcp_client_agent_request_cancel(mrcp_connection_agent_t *agent, mrcp_control_channel_t *channel, mrcp_message_t *message)
{
	mrcp_message_t *response;
	apt_obj_log(APT_LOG_MARK,APT_PRIO_WARNING,channel->log_obj,"Cancel MRCP Request <%s@%s> [%d]",
		MRCP_MESSAGE_SIDRES(message),
		message->start_line.request_id);
	response = mrcp_response_create(message,message->pool);
	response->start_line.status_code = MRCP_STATUS_CODE_METHOD_FAILED;
	return mrcp_connection_message_receive(agent->vtable,channel,response);
}
Exemplo n.º 11
0
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;
}
Exemplo n.º 12
0
static APR_INLINE void recog_state_change(mrcp_recog_state_machine_t *state_machine, mrcp_recog_state_e state, mrcp_message_t *message)
{
	apt_log(APT_LOG_MARK,APT_PRIO_INFO,"State Transition %s -> %s "APT_SIDRES_FMT,
		state_names[state_machine->state],
		state_names[state],
		MRCP_MESSAGE_SIDRES(message));
	state_machine->state = state;
	if(state == RECOGNIZER_STATE_IDLE) {
		state_machine->recog = NULL;
	}
}
Exemplo n.º 13
0
static apt_bool_t mrcp_client_agent_messsage_send(mrcp_connection_agent_t *agent, mrcp_control_channel_t *channel, mrcp_message_t *message)
{
	apt_bool_t status = FALSE;
	mrcp_connection_t *connection = channel->connection;
	apt_text_stream_t stream;
	apt_message_status_e result;

	if(!connection || !connection->sock) {
		apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Null MRCPv2 Connection "APT_SIDRES_FMT,MRCP_MESSAGE_SIDRES(message));
		mrcp_client_agent_request_cancel(agent,channel,message);
		return FALSE;
	}

	do {
		apt_text_stream_init(&stream,connection->tx_buffer,connection->tx_buffer_size);
		result = mrcp_generator_run(connection->generator,message,&stream);
		if(result != APT_MESSAGE_STATUS_INVALID) {
			stream.text.length = stream.pos - stream.text.buf;
			*stream.pos = '\0';

			apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Send MRCPv2 Stream %s [%"APR_SIZE_T_FMT" bytes]\n%.*s",
				connection->id,
				stream.text.length,
				connection->verbose == TRUE ? stream.text.length : 0,
				stream.text.buf);

			if(apr_socket_send(connection->sock,stream.text.buf,&stream.text.length) == APR_SUCCESS) {
				status = TRUE;
			}
			else {
				apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Failed to Send MRCPv2 Stream %s",
					connection->id);
			}
		}
		else {
			apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Failed to Generate MRCPv2 Stream %s",
				connection->id);
		}
	}
	while(result == APT_MESSAGE_STATUS_INCOMPLETE);

	if(status == TRUE) {
		channel->active_request = message;
		if(channel->request_timer && agent->request_timeout) {
			apt_timer_set(channel->request_timer,agent->request_timeout);
		}
	}
	else {
		mrcp_client_agent_request_cancel(agent,channel,message);
	}
	return status;
}
Exemplo n.º 14
0
/** Update state according to received outgoing event from recognition engine */
static apt_bool_t recog_event_state_update(mrcp_recog_state_machine_t *state_machine, mrcp_message_t *message)
{
	recog_method_f method;
	if(message->start_line.method_id >= RECOGNIZER_EVENT_COUNT) {
		return FALSE;
	}
	
	apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Process %s Event "APT_SIDRES_FMT" [%"MRCP_REQUEST_ID_FMT"]",
		message->start_line.method_name.buf,
		MRCP_MESSAGE_SIDRES(message),
		message->start_line.request_id);
	method = recog_event_method_array[message->start_line.method_id];
	if(method) {
		return method(state_machine,message);
	}
	return recog_event_dispatch(state_machine,message);
}
Exemplo n.º 15
0
static apt_bool_t recog_request_recognize(mrcp_recog_state_machine_t *state_machine, mrcp_message_t *message)
{
	mrcp_header_fields_inherit(&message->header,state_machine->properties,message->pool);
	if(state_machine->state == RECOGNIZER_STATE_RECOGNIZING) {
		mrcp_message_t *response;
		apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Queue Up RECOGNIZE Request "APT_SIDRES_FMT" [%"MRCP_REQUEST_ID_FMT"]",
			MRCP_MESSAGE_SIDRES(message),
			message->start_line.request_id);
		message->start_line.request_state = MRCP_REQUEST_STATE_PENDING;
		apt_list_push_back(state_machine->queue,message,message->pool);
		
		response = mrcp_response_create(message,message->pool);
		response->start_line.request_state = MRCP_REQUEST_STATE_PENDING;
		return recog_response_dispatch(state_machine,response);
	}

	return recog_request_dispatch(state_machine,message);
}
Exemplo n.º 16
0
static apt_bool_t recog_response_stop(mrcp_recog_state_machine_t *state_machine, mrcp_message_t *message)
{
	mrcp_message_t *pending_request;
	mrcp_generic_header_t *generic_header = mrcp_generic_header_prepare(message);
	/* append active id list */
	active_request_id_list_append(generic_header,state_machine->recog->start_line.request_id);
	mrcp_generic_header_property_add(message,GENERIC_HEADER_ACTIVE_REQUEST_ID_LIST);
	recog_pending_requests_remove(state_machine,state_machine->active_request,message);
	recog_state_change(state_machine,RECOGNIZER_STATE_IDLE,message);
	pending_request = apt_list_pop_front(state_machine->queue);
	recog_response_dispatch(state_machine,message);

	/* process pending RECOGNIZE requests / if any */
	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;
}
Exemplo n.º 17
0
static apt_bool_t mrcp_server_agent_messsage_send(mrcp_connection_agent_t *agent, mrcp_connection_t *connection, mrcp_message_t *message)
{
	apt_bool_t status = FALSE;
	apt_text_stream_t stream;
	apt_message_status_e result;
	if(!connection || !connection->sock) {
		apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Null MRCPv2 Connection "APT_SIDRES_FMT,MRCP_MESSAGE_SIDRES(message));
		return FALSE;
	}

	do {
		apt_text_stream_init(&stream,connection->tx_buffer,connection->tx_buffer_size);
		result = mrcp_generator_run(connection->generator,message,&stream);
		if(result != APT_MESSAGE_STATUS_INVALID) {
			stream.text.length = stream.pos - stream.text.buf;
			*stream.pos = '\0';

			apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Send MRCPv2 Data %s [%"APR_SIZE_T_FMT" bytes]\n%.*s",
					connection->id,
					stream.text.length,
					connection->verbose == TRUE ? stream.text.length : 0,
					stream.text.buf);

			if(apr_socket_send(connection->sock,stream.text.buf,&stream.text.length) == APR_SUCCESS) {
				status = TRUE;
			}
			else {
				apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Failed to Send MRCPv2 Data");
			}
		}
		else {
			apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Failed to Generate MRCPv2 Data");
		}
	}
	while(result == APT_MESSAGE_STATUS_INCOMPLETE);

	return status;
}
Exemplo n.º 18
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;
}
Exemplo n.º 19
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;
}