/** Handle the responses sent to channel add requests */
static apt_bool_t synth_application_on_channel_add(mrcp_application_t *application, mrcp_session_t *session, mrcp_channel_t *channel, mrcp_sig_status_code_e status)
{
	synth_app_channel_t *synth_channel = mrcp_application_channel_object_get(channel);
	if(status == MRCP_SIG_STATUS_CODE_SUCCESS) {
		mrcp_message_t *mrcp_message;
		const apt_dir_layout_t *dir_layout = mrcp_application_dir_layout_get(application);
		/* create and send SPEAK request */
		mrcp_message = demo_speak_message_create(session,channel,dir_layout);
		if(mrcp_message) {
			mrcp_application_message_send(session,channel,mrcp_message);
		}

		if(synth_channel && session) {
			char *file_name = apr_pstrcat(session->pool,"synth-",session->id.buf,".pcm",NULL);
			char *file_path = apt_datadir_filepath_get(dir_layout,file_name,session->pool);
			if(file_path) {
				synth_channel->audio_out = fopen(file_path,"wb");
			}
		}
	}
	else {
		/* error case, just terminate the demo */
		mrcp_application_session_terminate(session);
	}
	return TRUE;
}
/** \brief Received channel add response */
static apt_bool_t on_channel_add(mrcp_application_t *application, mrcp_session_t *session, mrcp_channel_t *channel, mrcp_sig_status_code_e status)
{
	uni_speech_t *uni_speech = mrcp_application_channel_object_get(channel);

	ast_log(LOG_DEBUG, "(%s) Channel added status: %d\n",uni_speech->name, status);
	return uni_recog_sm_response_signal(uni_speech,MRCP_SIG_COMMAND_CHANNEL_ADD,status);
}
Esempio n. 3
0
bool SynthSession::OnChannelAdd(mrcp_channel_t* pMrcpChannel, mrcp_sig_status_code_e status)
{
	if(!UmcSession::OnChannelAdd(pMrcpChannel,status))
		return false;

	const mpf_codec_descriptor_t* pDescriptor = mrcp_application_sink_descriptor_get(pMrcpChannel);
	if(!pDescriptor) 
	{
		apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Failed to Get Media Sink Descriptor");
		return Terminate();
	}

	SynthChannel* pSynthChannel = (SynthChannel*) mrcp_application_channel_object_get(pMrcpChannel);
	if(status != MRCP_SIG_STATUS_CODE_SUCCESS)
	{
		/* error case, just terminate the demo */
		return Terminate();
	}

	/* create MRCP message */
	mrcp_message_t* pMrcpMessage = CreateSpeakRequest(pMrcpChannel);
	if(pMrcpMessage) 
	{
		SendMrcpRequest(pSynthChannel->m_pMrcpChannel,pMrcpMessage);
	}

	pSynthChannel->m_pAudioOut = GetAudioOut(pDescriptor,GetSessionPool());
	return true;
}
Esempio n. 4
0
/** \brief Received channel remove response */
static apt_bool_t on_channel_remove(mrcp_application_t *application, mrcp_session_t *session, mrcp_channel_t *channel, mrcp_sig_status_code_e status)
{
	uni_speech_t *uni_speech = mrcp_application_channel_object_get(channel);

	ast_log(LOG_DEBUG, "On channel remove\n");
	return uni_recog_sm_response_signal(uni_speech,MRCP_SIG_COMMAND_CHANNEL_REMOVE,status);
}
/** Handle the DEFINE-GRAMMAR responses */
static apt_bool_t recog_application_on_define_grammar(mrcp_application_t *application, mrcp_session_t *session, mrcp_channel_t *channel)
{
	recog_app_channel_t *recog_channel = mrcp_application_channel_object_get(channel);
	mrcp_message_t *mrcp_message;
	const apt_dir_layout_t *dir_layout = mrcp_application_dir_layout_get(application);
	/* create and send RECOGNIZE request */
	mrcp_message = demo_recognize_message_create(session,channel,dir_layout);
	if(mrcp_message) {
		mrcp_application_message_send(session,channel,mrcp_message);
	}
	if(recog_channel) {
		const mpf_codec_descriptor_t *descriptor = mrcp_application_source_descriptor_get(channel);
		char *file_name = apr_psprintf(session->pool,"one-%dkHz.pcm",
			descriptor ? descriptor->sampling_rate/1000 : 8);
		char *file_path = apt_datadir_filepath_get(dir_layout,file_name,session->pool);
		if(file_path) {
			recog_channel->audio_in = fopen(file_path,"rb");
			if(recog_channel->audio_in) {
				apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Set [%s] as Speech Source",file_path);
			}
			else {
				apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Cannot Find [%s]",file_path);
				/* set some estimated time to complete */
				recog_channel->time_to_complete = 5000; // 5 sec
			}
		}
	}
	return TRUE;
}
Esempio n. 6
0
/* Handle the UniMRCP responses sent to channel remove requests. */
static apt_bool_t speech_on_channel_remove(mrcp_application_t *application, mrcp_session_t *session, mrcp_channel_t *channel, mrcp_sig_status_code_e status)
{
	speech_channel_t *schannel;

	if (channel != NULL)
		schannel = (speech_channel_t *)mrcp_application_channel_object_get(channel);
	else
		schannel = NULL;

	ast_log(LOG_DEBUG, "(%s) speech_on_channel_remove\n", schannel->name);

	if (schannel != NULL) {
		ast_log(LOG_NOTICE, "(%s) Channel removed\n", schannel->name);
		schannel->unimrcp_channel = NULL;

		if (session != NULL) {
			ast_log(LOG_DEBUG, "(%s) Terminating MRCP session\n", schannel->name);

			if (!mrcp_application_session_terminate(session))
				ast_log(LOG_WARNING, "(%s) Unable to terminate application session\n", schannel->name);
		}
	} else
		ast_log(LOG_ERROR, "(unknown) channel error!\n");

	return TRUE;
}
Esempio n. 7
0
/** \brief Received MRCP message */
static apt_bool_t on_message_receive(mrcp_application_t *application, mrcp_session_t *session, mrcp_channel_t *channel, mrcp_message_t *message)
{
	uni_speech_t *uni_speech = mrcp_application_channel_object_get(channel);

	ast_log(LOG_DEBUG, "On message receive\n");
	if(message->start_line.message_type == MRCP_MESSAGE_TYPE_RESPONSE) {
		return uni_recog_mrcp_response_signal(uni_speech,message);
	}
	
	if(message->start_line.message_type == MRCP_MESSAGE_TYPE_EVENT) {
		if(message->start_line.method_id == RECOGNIZER_RECOGNITION_COMPLETE) {
			uni_speech->is_inprogress = FALSE;			
			if (uni_speech->speech_base->state != AST_SPEECH_STATE_NOT_READY) {
				uni_speech->mrcp_event = message;
				ast_speech_change_state(uni_speech->speech_base,AST_SPEECH_STATE_DONE);
			}
			else {
				uni_speech->mrcp_event = NULL;
				ast_speech_change_state(uni_speech->speech_base,AST_SPEECH_STATE_NOT_READY);
			}
		}
		else if(message->start_line.method_id == RECOGNIZER_START_OF_INPUT) {
			ast_set_flag(uni_speech->speech_base,AST_SPEECH_QUIET);
		}
	}

	return TRUE;
}
Esempio n. 8
0
bool VerifierSession::StartVerification(mrcp_channel_t* pMrcpChannel)
{
	const mpf_codec_descriptor_t* pDescriptor = mrcp_application_source_descriptor_get(pMrcpChannel);
	if(!pDescriptor)
	{
		apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Failed to Get Media Source Descriptor");
		return Terminate();
	}

	VerifierChannel* pVerifierChannel = (VerifierChannel*) mrcp_application_channel_object_get(pMrcpChannel);
	/* create and send Verification request */
	mrcp_message_t* pMrcpMessage = CreateStartSessionRequest(pMrcpChannel);
	if(pMrcpMessage)
	{
		SendMrcpRequest(pVerifierChannel->m_pMrcpChannel,pMrcpMessage);
	}

	pVerifierChannel->m_pAudioIn = GetAudioIn(pDescriptor,GetSessionPool());
	if(!pVerifierChannel->m_pAudioIn)
	{
		/* no audio input availble, set some estimated time to complete instead */
		pVerifierChannel->m_TimeToComplete = 5000; // 5 sec
	}
	return true;
}
Esempio n. 9
0
bool SynthSession::OnMessageReceive(mrcp_channel_t* pMrcpChannel, mrcp_message_t* pMrcpMessage)
{
	if(!UmcSession::OnMessageReceive(pMrcpChannel,pMrcpMessage))
		return false;

	if(pMrcpMessage->start_line.message_type == MRCP_MESSAGE_TYPE_RESPONSE) 
	{
		/* received MRCP response */
		if(pMrcpMessage->start_line.method_id == SYNTHESIZER_SPEAK) 
		{
			/* received the response to SPEAK request */
			if(pMrcpMessage->start_line.request_state == MRCP_REQUEST_STATE_INPROGRESS) 
			{
				SynthChannel* pSynthChannel = (SynthChannel*) mrcp_application_channel_object_get(pMrcpChannel);
				if(pSynthChannel)
					pSynthChannel->m_pSpeakRequest = GetMrcpMessage();
				
				/* waiting for SPEAK-COMPLETE event */
			}
			else 
			{
				/* received unexpected response, terminate the session */
				Terminate();
			}
		}
		else 
		{
			/* received unexpected response */
		}
	}
	else if(pMrcpMessage->start_line.message_type == MRCP_MESSAGE_TYPE_EVENT) 
	{
		/* received MRCP event */
		if(pMrcpMessage->start_line.method_id == SYNTHESIZER_SPEAK_COMPLETE) 
		{
			SynthChannel* pSynthChannel = (SynthChannel*) mrcp_application_channel_object_get(pMrcpChannel);
			if(pSynthChannel)
				pSynthChannel->m_pSpeakRequest = NULL;
			/* received SPEAK-COMPLETE event, terminate the session */
			Terminate();
		}
	}
	return true;
}
Esempio n. 10
0
bool DtmfSession::OnMessageReceive(mrcp_channel_t* pMrcpChannel, mrcp_message_t* pMrcpMessage)
{
	if(!UmcSession::OnMessageReceive(pMrcpChannel,pMrcpMessage))
		return false;

	const DtmfScenario* pScenario = GetScenario();
	RecogChannel* pRecogChannel = (RecogChannel*) mrcp_application_channel_object_get(pMrcpChannel);
	if(pMrcpMessage->start_line.message_type == MRCP_MESSAGE_TYPE_RESPONSE) 
	{
		if(pMrcpMessage->start_line.method_id == RECOGNIZER_RECOGNIZE)
		{
			/* received the response to RECOGNIZE request */
			if(pMrcpMessage->start_line.request_state == MRCP_REQUEST_STATE_INPROGRESS)
			{
				/* start to stream the DTMFs to recognize */
				if(pRecogChannel && pRecogChannel->m_pDtmfGenerator)
				{
					const char* digits = pScenario->GetDigits();
					if(digits)
					{
						mpf_dtmf_generator_enqueue(pRecogChannel->m_pDtmfGenerator,digits);
						pRecogChannel->m_Streaming = true;
					}
				}
			}
			else 
			{
				/* received unexpected response, terminate the session */
				Terminate();
			}
		}
		else 
		{
			/* received unexpected response */
		}
	}
	else if(pMrcpMessage->start_line.message_type == MRCP_MESSAGE_TYPE_EVENT) 
	{
		if(pMrcpMessage->start_line.method_id == RECOGNIZER_RECOGNITION_COMPLETE) 
		{
			ParseNLSMLResult(pMrcpMessage);
			if(pRecogChannel) 
			{
				pRecogChannel->m_Streaming = false;
			}
			Terminate();
		}
		else if(pMrcpMessage->start_line.method_id == RECOGNIZER_START_OF_INPUT) 
		{
			/* received start-of-input, do whatever you need here */
		}
	}
	return true;
}
Esempio n. 11
0
bool DtmfSession::StartRecognition(mrcp_channel_t* pMrcpChannel)
{
	RecogChannel* pRecogChannel = (RecogChannel*) mrcp_application_channel_object_get(pMrcpChannel);
	/* create and send RECOGNIZE request */
	mrcp_message_t* pMrcpMessage = CreateRecognizeRequest(pMrcpChannel);
	if(pMrcpMessage)
	{
		SendMrcpRequest(pRecogChannel->m_pMrcpChannel,pMrcpMessage);
	}

	return true;
}
Esempio n. 12
0
/* Handle the UniMRCP responses sent to channel add requests. */
static apt_bool_t speech_on_channel_add(mrcp_application_t *application, mrcp_session_t *session, mrcp_channel_t *channel, mrcp_sig_status_code_e status)
{
	speech_channel_t *schannel;

	if (channel != NULL)
		schannel = (speech_channel_t *)mrcp_application_channel_object_get(channel);
	else
		schannel = NULL;

	ast_log(LOG_DEBUG, "(%s) speech_on_channel_add\n", schannel->name);

	if ((schannel != NULL) && (application != NULL) && (session != NULL) && (channel != NULL)) {
		if ((session != NULL) && (status == MRCP_SIG_STATUS_CODE_SUCCESS)) {
			const mpf_codec_descriptor_t *descriptor = descriptor = mrcp_application_sink_descriptor_get(channel);
			if (!descriptor) {
				ast_log(LOG_ERROR, "(%s) Unable to determine codec descriptor\n", schannel->name);
				speech_channel_set_state(schannel, SPEECH_CHANNEL_ERROR);
				ast_log(LOG_DEBUG, "(%s) Terminating MRCP session\n", schannel->name);
				if (!mrcp_application_session_terminate(session))
					ast_log(LOG_WARNING, "(%s) Unable to terminate application session\n", schannel->name);
				return FALSE;
			}

			schannel->rate = descriptor->sampling_rate;
			const char *codec_name = NULL;
			if (descriptor->name.length > 0)
				codec_name = descriptor->name.buf;
			else
				codec_name = "unknown";

			ast_log(LOG_NOTICE, "(%s) Channel ready, codec=%s, sample rate=%d\n",
				schannel->name,
				codec_name,
				schannel->rate);
			speech_channel_set_state(schannel, SPEECH_CHANNEL_READY);
		} else {
			ast_log(LOG_ERROR, "(%s) Channel error!\n", schannel->name);

			if (session != NULL) {
				ast_log(LOG_DEBUG, "(%s) Terminating MRCP session\n", schannel->name);
				speech_channel_set_state(schannel, SPEECH_CHANNEL_ERROR);

				if (!mrcp_application_session_terminate(session))
					ast_log(LOG_WARNING, "(%s) Unable to terminate application session\n", schannel->name);
			}
		}
	} else
		ast_log(LOG_ERROR, "(unknown) channel error!\n");

	return TRUE;
}
Esempio n. 13
0
bool RecorderSession::StartRecorder(mrcp_channel_t* pMrcpChannel)
{
	RecorderChannel* pRecorderChannel = (RecorderChannel*) mrcp_application_channel_object_get(pMrcpChannel);
	/* create and send RECORD request */
	mrcp_message_t* pMrcpMessage = CreateRecordRequest(pMrcpChannel);
	if(pMrcpMessage)
	{
		SendMrcpRequest(pRecorderChannel->m_pMrcpChannel,pMrcpMessage);
	}

	const mpf_codec_descriptor_t* pDescriptor = mrcp_application_source_descriptor_get(pMrcpChannel);
	pRecorderChannel->m_pAudioIn = GetAudioIn(pDescriptor,GetSessionPool());
	return true;
}
Esempio n. 14
0
bool RecorderSession::OnMessageReceive(mrcp_channel_t* pMrcpChannel, mrcp_message_t* pMrcpMessage)
{
	if(!UmcSession::OnMessageReceive(pMrcpChannel,pMrcpMessage))
		return false;

	RecorderChannel* pRecorderChannel = (RecorderChannel*) mrcp_application_channel_object_get(pMrcpChannel);
	if(pMrcpMessage->start_line.message_type == MRCP_MESSAGE_TYPE_RESPONSE) 
	{
		/* received MRCP response */
		if(pMrcpMessage->start_line.method_id == RECORDER_RECORD)
		{
			/* received the response to RECORD request */
			if(pMrcpMessage->start_line.request_state == MRCP_REQUEST_STATE_INPROGRESS)
			{
				/* start to stream the speech to record */
				if(pRecorderChannel)
				{
					pRecorderChannel->m_Streaming = true;
				}
			}
			else 
			{
				/* received unexpected response, terminate the session */
				Terminate();
			}
		}
		else 
		{
			/* received unexpected response */
		}
	}
	else if(pMrcpMessage->start_line.message_type == MRCP_MESSAGE_TYPE_EVENT) 
	{
		if(pMrcpMessage->start_line.method_id == RECORDER_RECORD_COMPLETE) 
		{
			if(pRecorderChannel) 
			{
				pRecorderChannel->m_Streaming = false;
			}
			Terminate();
		}
		else if(pMrcpMessage->start_line.method_id == RECORDER_START_OF_INPUT) 
		{
			/* received start-of-input, do whatever you need here */
		}
	}
	return true;
}
Esempio n. 15
0
static apt_bool_t recog_application_on_channel_remove(mrcp_application_t *application, mrcp_session_t *session, mrcp_channel_t *channel, mrcp_sig_status_code_e status)
{
	recog_app_channel_t *recog_channel = mrcp_application_channel_object_get(channel);

	/* terminate the demo */
	mrcp_application_session_terminate(session);

	if(recog_channel) {
		FILE *audio_in = recog_channel->audio_in;
		if(audio_in) {
			recog_channel->audio_in = NULL;
			fclose(audio_in);
		}
	}
	return TRUE;
}
Esempio n. 16
0
/** Handle the responses sent to channel remove requests */
static apt_bool_t synth_application_on_channel_remove(mrcp_application_t *application, mrcp_session_t *session, mrcp_channel_t *channel, mrcp_sig_status_code_e status)
{
	synth_app_channel_t *synth_channel = mrcp_application_channel_object_get(channel);

	/* terminate the demo */
	mrcp_application_session_terminate(session);

	if(synth_channel) {
		FILE *audio_out = synth_channel->audio_out;
		if(audio_out) {
			synth_channel->audio_out = NULL;
			fclose(audio_out);
		}
	}
	return TRUE;
}
Esempio n. 17
0
static apt_bool_t recog_application_on_message_receive(mrcp_application_t *application, mrcp_session_t *session, mrcp_channel_t *channel, mrcp_message_t *message)
{
	recog_app_channel_t *recog_channel = mrcp_application_channel_object_get(channel);
	if(message->start_line.message_type == MRCP_MESSAGE_TYPE_RESPONSE) {
		/* received MRCP response */
		if(message->start_line.method_id == RECOGNIZER_DEFINE_GRAMMAR) {
			/* received the response to DEFINE-GRAMMAR request */
			if(message->start_line.request_state == MRCP_REQUEST_STATE_COMPLETE) {
				recog_application_on_define_grammar(application,session,channel);
			}
			else {
				/* received unexpected response, remove channel */
				mrcp_application_channel_remove(session,channel);
			}
		}
		else if(message->start_line.method_id == RECOGNIZER_RECOGNIZE) {
			/* received the response to RECOGNIZE request */
			if(message->start_line.request_state == MRCP_REQUEST_STATE_INPROGRESS) {
				/* start to stream the speech to recognize */
				if(recog_channel) {
					recog_channel->streaming = TRUE;
				}
			}
			else {
				/* received unexpected response, remove channel */
				mrcp_application_channel_remove(session,channel);
			}
		}
		else {
			/* received unexpected response */
		}
	}
	else if(message->start_line.message_type == MRCP_MESSAGE_TYPE_EVENT) {
		if(message->start_line.method_id == RECOGNIZER_RECOGNITION_COMPLETE) {
			demo_nlsml_result_parse(message);
			if(recog_channel) {
				recog_channel->streaming = FALSE;
			}
			mrcp_application_channel_remove(session,channel);
		}
		else if(message->start_line.method_id == RECOGNIZER_START_OF_INPUT) {
			/* received start-of-input, do whatever you need here */
		}
	}
	return TRUE;
}
Esempio n. 18
0
bool RecogSession::StartRecognition(mrcp_channel_t* pMrcpChannel)
{
	RecogChannel* pRecogChannel = (RecogChannel*) mrcp_application_channel_object_get(pMrcpChannel);
	/* create and send RECOGNIZE request */
	mrcp_message_t* pMrcpMessage = CreateRecognizeRequest(pMrcpChannel);
	if(pMrcpMessage)
	{
		SendMrcpRequest(pRecogChannel->m_pMrcpChannel,pMrcpMessage);
	}

	const mpf_codec_descriptor_t* pDescriptor = mrcp_application_source_descriptor_get(pMrcpChannel);
	pRecogChannel->m_pAudioIn = GetAudioIn(pDescriptor,GetSessionPool());
	if(!pRecogChannel->m_pAudioIn)
	{
		/* no audio input availble, set some estimated time to complete instead */
		pRecogChannel->m_TimeToComplete = 5000; // 5 sec
	}
	return true;
}
Esempio n. 19
0
bool RecorderSession::StartRecorder(mrcp_channel_t* pMrcpChannel)
{
	const mpf_codec_descriptor_t* pDescriptor = mrcp_application_source_descriptor_get(pMrcpChannel);
	if(!pDescriptor)
	{
		apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Failed to Get Media Source Descriptor");
		return Terminate();
	}

	RecorderChannel* pRecorderChannel = (RecorderChannel*) mrcp_application_channel_object_get(pMrcpChannel);
	/* create and send RECORD request */
	mrcp_message_t* pMrcpMessage = CreateRecordRequest(pMrcpChannel);
	if(pMrcpMessage)
	{
		SendMrcpRequest(pRecorderChannel->m_pMrcpChannel,pMrcpMessage);
	}

	pRecorderChannel->m_pAudioIn = GetAudioIn(pDescriptor,GetSessionPool());
	return true;
}
/** \brief Received MRCP message */
static apt_bool_t on_message_receive(mrcp_application_t *application, mrcp_session_t *session, mrcp_channel_t *channel, mrcp_message_t *message)
{
	uni_speech_t *uni_speech = mrcp_application_channel_object_get(channel);

	if(message->start_line.message_type == MRCP_MESSAGE_TYPE_RESPONSE) {
		ast_log(LOG_DEBUG, "(%s) Received MRCP response method-id: %d status-code: %d req-state: %d\n",
				uni_speech->name,
				(int)message->start_line.method_id,
				message->start_line.status_code,
				(int)message->start_line.request_state);
		return uni_recog_mrcp_response_signal(uni_speech,message);
	}

	if(message->start_line.message_type == MRCP_MESSAGE_TYPE_EVENT) {
		if(message->start_line.method_id == RECOGNIZER_RECOGNITION_COMPLETE) {
			ast_log(LOG_DEBUG, "(%s) Recognition complete req-state: %d\n",
					uni_speech->name,
					(int)message->start_line.request_state);
			uni_speech->is_inprogress = FALSE;
			if (uni_speech->speech_base->state != AST_SPEECH_STATE_NOT_READY) {
				uni_speech->mrcp_event = message;
				ast_speech_change_state(uni_speech->speech_base,AST_SPEECH_STATE_DONE);
			}
			else {
				ast_log(LOG_DEBUG, "(%s) Unexpected RECOGNITION-COMPLETE event\n",uni_speech->name);
			}
		}
		else if(message->start_line.method_id == RECOGNIZER_START_OF_INPUT) {
			ast_log(LOG_DEBUG, "(%s) Start of input\n",uni_speech->name);
			ast_set_flag(uni_speech->speech_base, AST_SPEECH_QUIET | AST_SPEECH_SPOKE);
		}
		else {
			ast_log(LOG_DEBUG, "(%s) Received unhandled MRCP event id: %d req-state: %d\n",
					uni_speech->name,
					(int)message->start_line.method_id,
					(int)message->start_line.request_state);
		}
	}

	return TRUE;
}
Esempio n. 21
0
bool DtmfSession::OnChannelAdd(mrcp_channel_t* pMrcpChannel, mrcp_sig_status_code_e status)
{
	if(!UmcSession::OnChannelAdd(pMrcpChannel,status))
		return false;

	if(status != MRCP_SIG_STATUS_CODE_SUCCESS)
	{
		/* error case, just terminate the demo */
		return Terminate();
	}

	RecogChannel* pRecogChannel = (RecogChannel*) mrcp_application_channel_object_get(pMrcpChannel);
	if(pRecogChannel)
	{
		const mpf_audio_stream_t* pStream = mrcp_application_audio_stream_get(pMrcpChannel);
		if(pStream)
		{
			pRecogChannel->m_pDtmfGenerator = mpf_dtmf_generator_create(pStream,GetSessionPool());
		}
	}

	return StartRecognition(pMrcpChannel);
}
/** Handle the responses sent to channel add requests */
static apt_bool_t synth_application_on_channel_add(mrcp_application_t *application, mrcp_session_t *session, mrcp_channel_t *channel, mrcp_sig_status_code_e status)
{
	if(status == MRCP_SIG_STATUS_CODE_SUCCESS) {
		mrcp_message_t *mrcp_message;
		synth_app_channel_t *synth_channel = mrcp_application_channel_object_get(channel);
		apr_pool_t *pool = mrcp_application_session_pool_get(session);
		const apt_dir_layout_t *dir_layout = mrcp_application_dir_layout_get(application);
		const mpf_codec_descriptor_t *descriptor = mrcp_application_sink_descriptor_get(channel);
		if(!descriptor) {
			/* terminate the demo */
			apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Failed to Get Media Sink Descriptor");
			return mrcp_application_session_terminate(session);
		}

		/* create and send SPEAK request */
		mrcp_message = demo_speak_message_create(session,channel,dir_layout);
		if(mrcp_message) {
			mrcp_application_message_send(session,channel,mrcp_message);
		}

		if(synth_channel) {
			const apt_str_t *id = mrcp_application_session_id_get(session);
			char *file_name = apr_psprintf(pool,"synth-%dkHz-%s.pcm",
									descriptor->sampling_rate/1000,
									id->buf);
			char *file_path = apt_datadir_filepath_get(dir_layout,file_name,pool);
			if(file_path) {
				synth_channel->audio_out = fopen(file_path,"wb");
			}
		}
	}
	else {
		/* error case, just terminate the demo */
		mrcp_application_session_terminate(session);
	}
	return TRUE;
}
/** \brief Received unexpected session/channel termination event */
static apt_bool_t on_terminate_event(mrcp_application_t *application, mrcp_session_t *session, mrcp_channel_t *channel)
{
	uni_speech_t *uni_speech = mrcp_application_channel_object_get(channel);
	ast_log(LOG_WARNING, "(%s) Received unexpected session termination event\n",uni_speech->name);
	return TRUE;
}
Esempio n. 24
0
/* Handle the MRCP synthesizer responses/events from UniMRCP. */
static apt_bool_t synth_on_message_receive(mrcp_application_t *application, mrcp_session_t *session, mrcp_channel_t *channel, mrcp_message_t *message)
{
	speech_channel_t *schannel;

	if (channel != NULL)
		schannel = (speech_channel_t *)mrcp_application_channel_object_get(channel);
	else
		schannel = NULL;

	if ((schannel != NULL) && (application != NULL) && (session != NULL) && (channel != NULL) && (message != NULL)) {
		if (message->start_line.message_type == MRCP_MESSAGE_TYPE_RESPONSE) {
			/* Received MRCP response. */
			if (message->start_line.method_id == SYNTHESIZER_SPEAK) {
				/* received the response to SPEAK request */
				if (message->start_line.request_state == MRCP_REQUEST_STATE_INPROGRESS) {
					/* Waiting for SPEAK-COMPLETE event. */
					ast_log(LOG_DEBUG, "(%s) REQUEST IN PROGRESS\n", schannel->name);
					speech_channel_set_state(schannel, SPEECH_CHANNEL_PROCESSING);
				} else {
					/* Received unexpected request_state. */
					ast_log(LOG_DEBUG, "(%s) Unexpected SPEAK response, request_state = %d\n", schannel->name, message->start_line.request_state);
					speech_channel_set_state(schannel, SPEECH_CHANNEL_ERROR);
				}
			} else if (message->start_line.method_id == SYNTHESIZER_STOP) {
				/* Received response to the STOP request. */
				if (message->start_line.request_state == MRCP_REQUEST_STATE_COMPLETE) {
					/* Got COMPLETE. */
					ast_log(LOG_DEBUG, "(%s) COMPLETE\n", schannel->name);
					speech_channel_set_state(schannel, SPEECH_CHANNEL_READY);
				} else {
					/* Received unexpected request state. */
					ast_log(LOG_DEBUG, "(%s) Unexpected STOP response, request_state = %d\n", schannel->name, message->start_line.request_state);
					speech_channel_set_state(schannel, SPEECH_CHANNEL_ERROR);
				}
			} else if (message->start_line.method_id == SYNTHESIZER_BARGE_IN_OCCURRED) {
				/* Received response to the BARGE_IN_OCCURRED request. */
				if (message->start_line.request_state == MRCP_REQUEST_STATE_COMPLETE) {
					/* Got COMPLETE. */
					ast_log(LOG_DEBUG, "(%s) COMPLETE\n", schannel->name);
					speech_channel_set_state(schannel, SPEECH_CHANNEL_READY);
				} else {
					/* Received unexpected request state. */
					ast_log(LOG_DEBUG, "(%s) Unexpected BARGE-IN-OCCURRED response, request_state = %d\n", schannel->name, message->start_line.request_state);
					speech_channel_set_state(schannel, SPEECH_CHANNEL_ERROR);
				}
			} else {
				/* Received unexpected response. */
				ast_log(LOG_DEBUG, "(%s) Unexpected response, method_id = %d\n", schannel->name, (int)message->start_line.method_id);
				speech_channel_set_state(schannel, SPEECH_CHANNEL_ERROR); 
			}
		} else if (message->start_line.message_type == MRCP_MESSAGE_TYPE_EVENT) {
			/* Received MRCP event. */
			if (message->start_line.method_id == SYNTHESIZER_SPEAK_COMPLETE) {
				/* Got SPEAK-COMPLETE. */
				ast_log(LOG_DEBUG, "(%s) SPEAK-COMPLETE\n", schannel->name);
				speech_channel_set_state(schannel, SPEECH_CHANNEL_READY);
			} else {
				ast_log(LOG_DEBUG, "(%s) Unexpected event, method_id = %d\n", schannel->name, (int)message->start_line.method_id);
				speech_channel_set_state(schannel, SPEECH_CHANNEL_ERROR);
			}
		} else {
			ast_log(LOG_DEBUG, "(%s) Unexpected message type, message_type = %d\n", schannel->name, message->start_line.message_type);
			speech_channel_set_state(schannel, SPEECH_CHANNEL_ERROR);
		}
	} else
		ast_log(LOG_ERROR, "(unknown) channel error!\n");

	return TRUE;
}
Esempio n. 25
0
bool RecogSession::OnMessageReceive(mrcp_channel_t* pMrcpChannel, mrcp_message_t* pMrcpMessage)
{
	if(!UmcSession::OnMessageReceive(pMrcpChannel,pMrcpMessage))
		return false;

	RecogChannel* pRecogChannel = (RecogChannel*) mrcp_application_channel_object_get(pMrcpChannel);
	if(pMrcpMessage->start_line.message_type == MRCP_MESSAGE_TYPE_RESPONSE) 
	{
		/* received MRCP response */
		if(pMrcpMessage->start_line.method_id == RECOGNIZER_DEFINE_GRAMMAR) 
		{
			/* received the response to DEFINE-GRAMMAR request */
			if(pMrcpMessage->start_line.request_state == MRCP_REQUEST_STATE_COMPLETE) 
			{
				OnDefineGrammar(pMrcpChannel);
			}
			else 
			{
				/* received unexpected response, terminate the session */
				Terminate();
			}
		}
		else if(pMrcpMessage->start_line.method_id == RECOGNIZER_RECOGNIZE)
		{
			/* received the response to RECOGNIZE request */
			if(pMrcpMessage->start_line.request_state == MRCP_REQUEST_STATE_INPROGRESS)
			{
				RecogChannel* pRecogChannel = (RecogChannel*) mrcp_application_channel_object_get(pMrcpChannel);
				if(pRecogChannel)
					pRecogChannel->m_pRecogRequest = GetMrcpMessage();

				/* start to stream the speech to recognize */
				if(pRecogChannel) 
					pRecogChannel->m_Streaming = true;
			}
			else 
			{
				/* received unexpected response, terminate the session */
				Terminate();
			}
		}
		else 
		{
			/* received unexpected response */
		}
	}
	else if(pMrcpMessage->start_line.message_type == MRCP_MESSAGE_TYPE_EVENT) 
	{
		if(pMrcpMessage->start_line.method_id == RECOGNIZER_RECOGNITION_COMPLETE) 
		{
			ParseNLSMLResult(pMrcpMessage);
			if(pRecogChannel) 
				pRecogChannel->m_Streaming = false;

			RecogChannel* pRecogChannel = (RecogChannel*) mrcp_application_channel_object_get(pMrcpChannel);
			if(pRecogChannel)
				pRecogChannel->m_pRecogRequest = NULL;

			Terminate();
		}
		else if(pMrcpMessage->start_line.method_id == RECOGNIZER_START_OF_INPUT) 
		{
			/* received start-of-input, do whatever you need here */
		}
	}
	return true;
}
Esempio n. 26
0
bool VerifierSession::OnMessageReceive(mrcp_channel_t* pMrcpChannel, mrcp_message_t* pMrcpMessage)
{
	if(!UmcSession::OnMessageReceive(pMrcpChannel,pMrcpMessage))
		return false;

	VerifierChannel* pVerifierChannel = (VerifierChannel*) mrcp_application_channel_object_get(pMrcpChannel);
	if(pMrcpMessage->start_line.message_type == MRCP_MESSAGE_TYPE_RESPONSE) 
	{
		/* received MRCP response */
		if(pMrcpMessage->start_line.method_id == VERIFIER_START_SESSION)
		{
			/* received the response to START-SESSION request */
			/* create and send VERIFY request */
			mrcp_message_t* pMrcpMessage = CreateVerificationRequest(pMrcpChannel);
			if(pMrcpMessage)
			{
				SendMrcpRequest(pVerifierChannel->m_pMrcpChannel,pMrcpMessage);
			}
		}
		else if(pMrcpMessage->start_line.method_id == VERIFIER_END_SESSION)
		{
			/* received the response to END-SESSION request */
			Terminate();
		}
		else if(pMrcpMessage->start_line.method_id == VERIFIER_VERIFY)
		{
			/* received the response to VERIFY request */
			if(pMrcpMessage->start_line.request_state == MRCP_REQUEST_STATE_INPROGRESS)
			{
				VerifierChannel* pVerifierChannel = (VerifierChannel*) mrcp_application_channel_object_get(pMrcpChannel);
				if(pVerifierChannel)
					pVerifierChannel->m_pVerificationRequest = GetMrcpMessage();

				/* start to stream the speech to Verify */
				if(pVerifierChannel) 
					pVerifierChannel->m_Streaming = true;
			}
			else
			{
				/* create and send END-SESSION request */
				mrcp_message_t* pMrcpMessage = CreateEndSessionRequest(pMrcpChannel);
				if(pMrcpMessage)
				{
					SendMrcpRequest(pVerifierChannel->m_pMrcpChannel,pMrcpMessage);
				}
			}
		}
		else 
		{
			/* received unexpected response */
		}
	}
	else if(pMrcpMessage->start_line.message_type == MRCP_MESSAGE_TYPE_EVENT) 
	{
		if(pMrcpMessage->start_line.method_id == VERIFIER_VERIFICATION_COMPLETE) 
		{
			if(pVerifierChannel) 
				pVerifierChannel->m_Streaming = false;

			VerifierChannel* pVerifierChannel = (VerifierChannel*) mrcp_application_channel_object_get(pMrcpChannel);
			if(pVerifierChannel)
				pVerifierChannel->m_pVerificationRequest = NULL;

			/* create and send END-SESSION request */
			mrcp_message_t* pMrcpMessage = CreateEndSessionRequest(pMrcpChannel);
			if(pVerifierChannel && pMrcpMessage)
			{
				SendMrcpRequest(pVerifierChannel->m_pMrcpChannel,pMrcpMessage);
			}
		}
		else if(pMrcpMessage->start_line.method_id == VERIFIER_START_OF_INPUT) 
		{
			/* received start-of-input, do whatever you need here */
		}
	}
	return true;
}