Пример #1
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;
}
Пример #2
0
/** 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;
}
Пример #3
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;
}
Пример #4
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;
}
Пример #5
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;
}
Пример #6
0
/** \brief Set up the speech structure within the engine */
static int uni_recog_create_internal(struct ast_speech *speech, ast_format_compat *format)
{
	uni_speech_t *uni_speech;
	mrcp_session_t *session;
	apr_pool_t *pool;
	const mpf_codec_descriptor_t *descriptor;

	/* Create session instance */
	session = mrcp_application_session_create(uni_engine.application,uni_engine.profile,speech);
	if(!session) {
		ast_log(LOG_ERROR, "Failed to create session\n");
		return -1;
	}
	pool = mrcp_application_session_pool_get(session);
	uni_speech = apr_palloc(pool,sizeof(uni_speech_t));
	uni_speech->session = session;
	uni_speech->channel = NULL;
	uni_speech->wait_object = NULL;
	uni_speech->mutex = NULL;
	uni_speech->media_buffer = NULL;
	uni_speech->active_grammars = apr_hash_make(pool);
	uni_speech->is_sm_request = FALSE;
	uni_speech->is_inprogress = FALSE;
	uni_speech->sm_request = 0;
	uni_speech->sm_response = MRCP_SIG_STATUS_CODE_SUCCESS;
	uni_speech->mrcp_request = NULL;
	uni_speech->mrcp_response = NULL;
	uni_speech->mrcp_event = NULL;

	uni_speech->speech_base = speech;
	speech->data = uni_speech;

	/* Create cond wait object and mutex */
	apr_thread_mutex_create(&uni_speech->mutex,APR_THREAD_MUTEX_DEFAULT,pool);
	apr_thread_cond_create(&uni_speech->wait_object,pool);

	/* Create recognition channel instance */
	if(uni_recog_channel_create(uni_speech,format) != TRUE) {
		ast_log(LOG_ERROR, "Failed to create channel\n");
		uni_recog_cleanup(uni_speech);
		return -1;
	}

	/* Send add channel request and wait for response */
	if(uni_recog_sm_request_send(uni_speech,MRCP_SIG_COMMAND_CHANNEL_ADD) != TRUE) {
		ast_log(LOG_WARNING, "Failed to send add channel request\n");
		uni_recog_cleanup(uni_speech);
		return -1;
	}

	/* Check received response */
	if(uni_speech->sm_response != MRCP_SIG_STATUS_CODE_SUCCESS) {
		ast_log(LOG_WARNING, "Failed to add channel\n");
		uni_recog_sm_request_send(uni_speech,MRCP_SIG_COMMAND_SESSION_TERMINATE);
		uni_recog_cleanup(uni_speech);
		return -1;
	}

	descriptor = mrcp_application_source_descriptor_get(uni_speech->channel);
	if(descriptor) {
		mpf_frame_buffer_t *media_buffer;
		apr_size_t frame_size = mpf_codec_linear_frame_size_calculate(descriptor->sampling_rate,descriptor->channel_count);
		/* Create media buffer */
		ast_log(LOG_DEBUG, "Create media buffer frame_size:%"APR_SIZE_T_FMT"\n",frame_size);
		media_buffer = mpf_frame_buffer_create(frame_size,20,pool);
		uni_speech->media_buffer = media_buffer;
	}
	
	if(!uni_speech->media_buffer) {
		ast_log(LOG_WARNING, "Failed to create media buffer\n");
		uni_recog_sm_request_send(uni_speech,MRCP_SIG_COMMAND_SESSION_TERMINATE);
		uni_recog_cleanup(uni_speech);
		return -1;
	}

	ast_log(LOG_NOTICE, "Created speech instance '%s'\n",uni_speech_id_get(uni_speech));

	/* Set properties for session */
	uni_recog_properties_set(uni_speech);
	/* Preload grammars */
	uni_recog_grammars_preload(uni_speech);
	return 0;
}