Ejemplo n.º 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);
}
Ejemplo n.º 2
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);
}
Ejemplo n.º 3
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);
}
Ejemplo n.º 4
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);
}
Ejemplo n.º 5
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);
}
Ejemplo n.º 6
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);
}
/* 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) {
		apt_header_field_t *header_field;
		header_field = apt_header_field_create_c("Completion-Cause","000 normal",event_message->pool);
		if(header_field) {
			mrcp_message_header_field_add(event_message,header_field);
		}

		/* set request state */
		event_message->start_line.request_state = MRCP_REQUEST_STATE_COMPLETE;
	}
	return event_message;
}
Ejemplo n.º 8
0
/* 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 synth_response_speak(mrcp_synth_state_machine_t *state_machine, mrcp_message_t *message)
{
	apt_log(APT_PRIO_INFO,"Process SPEAK Response [%d]",message->start_line.request_id);
	if(message->start_line.request_state == MRCP_REQUEST_STATE_INPROGRESS) {
		state_machine->speaker = state_machine->active_request;
		synth_state_change(state_machine,SYNTHESIZER_STATE_SPEAKING);
	}
	if(state_machine->is_pending == TRUE) {
		mrcp_message_t *event_message = mrcp_event_create(
							state_machine->active_request,
							SYNTHESIZER_SPEECH_MARKER,
							state_machine->active_request->pool);
		event_message->start_line.request_state = MRCP_REQUEST_STATE_INPROGRESS;
		state_machine->is_pending = FALSE;
		/* not to send the response for pending request, instead send SPEECH-MARKER event */
		return synth_event_dispatch(state_machine,event_message);
	}
	return synth_response_dispatch(state_machine,message);
}
Ejemplo n.º 10
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;
}