Esempio n. 1
0
void UmcFramework::DestroyMrcpClient()
{
	if(m_pMrcpClient)
	{
		/* shutdown MRCP client stack processing first (blocking call) */
		mrcp_client_shutdown(m_pMrcpClient);
		/* destroy MRCP client stack */
		mrcp_client_destroy(m_pMrcpClient);
		m_pMrcpClient = NULL;
		m_pMrcpApplication = NULL;
	}
}
Esempio n. 2
0
AST_COMPAT_STATIC int unload_module(void)
{
	int res = 0;
	apr_hash_index_t *hi;

	/* First unregister the applications so no more calls arrive. */
	for (hi = apr_hash_first(NULL, globals.apps); hi; hi = apr_hash_next(hi)) {
		const void *key;
		const char *name;

		apr_hash_this(hi, &key, NULL, NULL);

		name = (const char *) key;

		res |= ast_unregister_application(name);
	}

	/* Unload the applications. */
	unload_mrcpsynth_app();
	unload_mrcprecog_app();
	unload_synthandrecog_app();

	/* Stop the MRCP client stack. */
	if (globals.mrcp_client != NULL) {
		if (!mrcp_client_shutdown(globals.mrcp_client))
			ast_log(LOG_WARNING, "Unable to shutdown MRCP client stack processing\n");
		else
			ast_log(LOG_DEBUG, "MRCP client stack processing shutdown\n");

		if (!mrcp_client_destroy(globals.mrcp_client))
			ast_log(LOG_WARNING, "Unable to destroy MRCP client stack\n");
		else
			ast_log(LOG_DEBUG, "MRCP client stack destroyed\n");

		globals.mrcp_client = NULL;
	}

	if (!apt_log_instance_destroy())
		ast_log(LOG_WARNING, "Unable to destroy UniMRCP logger instance\n");

	/* Destroy globals. */
	globals_destroy();

	if ((res == 0) && (apr_initialized != 0)) {
		apr_terminate();
		apr_initialized = 0;
	}

	return res;
}
Esempio n. 3
0
/** \brief Unload module */
static int unload_module(void)
{
	ast_log(LOG_NOTICE, "Unload UniMRCP module\n");
	if(ast_speech_unregister(UNI_ENGINE_NAME)) {
		ast_log(LOG_ERROR, "Failed to unregister module\n");
	}

	if(uni_engine.client) {
		mrcp_client_shutdown(uni_engine.client);
	}

	uni_engine_unload();
	return 0;
}
/** \brief Load module */
static int load_module(void)
{
	ast_log(LOG_NOTICE, "Load Res-Speech-UniMRCP module\n");

	if(uni_engine_load() == FALSE) {
		return AST_MODULE_LOAD_FAILURE;
	}

	if(mrcp_client_start(uni_engine.client) != TRUE) {
		ast_log(LOG_ERROR, "Failed to start MRCP client\n");
		uni_engine_unload();
		return AST_MODULE_LOAD_FAILURE;
	}

#if AST_VERSION_AT_LEAST(10,0,0)

#if AST_VERSION_AT_LEAST(13,0,0)
	ast_engine.formats = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
#elif AST_VERSION_AT_LEAST(12,0,0)
	ast_engine.formats = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK);
#else /* <= 11 */
	ast_engine.formats = ast_format_cap_alloc_nolock();
#endif
	if(!ast_engine.formats) {
		ast_log(LOG_ERROR, "Failed to alloc media format capabilities\n");
		uni_engine_unload();
		return AST_MODULE_LOAD_FAILURE;
	}
#if AST_VERSION_AT_LEAST(13,0,0)
	ast_format_cap_append(ast_engine.formats, ast_format_slin, 0);
#else
	struct ast_format format;
	ast_format_set(&format, AST_FORMAT_SLINEAR, 0);
	ast_format_cap_add(ast_engine.formats, &format);
#endif

#else /* <= 1.8 */
	ast_engine.formats = AST_FORMAT_SLINEAR;
#endif

	if(ast_speech_register(&ast_engine)) {
		ast_log(LOG_ERROR, "Failed to register module\n");
		mrcp_client_shutdown(uni_engine.client);
		uni_engine_unload();
		return AST_MODULE_LOAD_FAILURE;
	}

	return AST_MODULE_LOAD_SUCCESS;
}
Esempio n. 5
0
/** Destroy demo framework */
apt_bool_t demo_framework_destroy(demo_framework_t *framework)
{
	if(!framework) {
		return FALSE;
	}

	if(framework->task) {
		apt_task_t *task = apt_consumer_task_base_get(framework->task);
		apt_task_terminate(task,TRUE);
		apt_task_destroy(task);
		framework->task = NULL;
	}

	mrcp_client_shutdown(framework->client);
	return mrcp_client_destroy(framework->client);
}
Esempio n. 6
0
/** Destroy ASR engine */
ASR_CLIENT_DECLARE(apt_bool_t) asr_engine_destroy(asr_engine_t *engine)
{
	if(engine->mrcp_client) {
		/* shutdown client stack */
		mrcp_client_shutdown(engine->mrcp_client);
		/* destroy client stack */
		mrcp_client_destroy(engine->mrcp_client);
		engine->mrcp_client = NULL;
		engine->mrcp_app = NULL;
	}

	/* destroy singleton logger */
	apt_log_instance_destroy();
	/* destroy APR pool */
	apr_pool_destroy(engine->pool);
	return TRUE;
}
Esempio n. 7
0
int main(int argc, char const* argv[])
{
	apr_pool_t* pool = NULL;
	apr_pool_t* spool = NULL;
	int i;
	struct iovec cattext[101];
	static char const SP = ' ';
	char const* outfile;
	apr_status_t status;
	apt_dir_layout_t* dirLayout = NULL;
	mrcp_client_t* client = NULL;
	mrcp_application_t* app = NULL;
	mrcp_session_t* sess = NULL;
	mpf_stream_capabilities_t* caps = NULL;
	mpf_termination_t* term = NULL;
	mrcp_channel_t* chan = NULL;
	struct stat info;

	if (argc < 2) {
		puts("Usage:");
		printf("\t%s \"This is a synthetic voice.\"", argv[0]);
		exit(1);
	}

	/* Just detect various directory layout constellations */
	if (stat(ROOT_DIR, &info))
		ROOT_DIR = ROOT_DIR2;
	if (stat(ROOT_DIR, &info))
		ROOT_DIR = ROOT_DIR3;

	/* Initialize platform first */
	if (apr_initialize() != APR_SUCCESS) FAIL("Cannot initialize APR platform");
	pool = apt_pool_create();
	if (!pool) FAIL("Not enough memory");
	for (i = 0; (i < argc - 2) && (i < 50); i += 2) {
		cattext[2 * i].iov_base = (void*) argv[i + 1];
		cattext[2 * i].iov_len = strlen(argv[i + 1]);
		cattext[2 * i + 1].iov_base = (void*) &SP;
		cattext[2 * i + 1].iov_len = 1;
	}
	cattext[2 * i].iov_base = (void*) argv[i + 1];
	cattext[2 * i].iov_len = strlen(argv[i + 1]);
	text = apr_pstrcatv(pool, cattext, 2 * i + 1, NULL);
	if (!text) FAIL("Not enough memory");
	outfile = apr_pstrcat(pool, ROOT_DIR, "/data/", PCM_OUT_FILE, NULL);
	
	printf("This is a sample C UniMRCP client synthesizer scenario.\n");
	printf("Use client configuration from %s/conf/unimrcpclient.xml\n", ROOT_DIR);
	printf("Use profile %s\n", MRCP_PROFILE);
	printf("Synthesize text: `%s'\n", text);
	printf("Write output to file: %s\n", outfile);
	printf("\n");
	printf("Press enter to start the session...\n");
	(void) getchar();

	apt_log_instance_create(APT_LOG_OUTPUT_NONE, APT_PRIO_DEBUG, pool);
	apt_log_ext_handler_set(UniSynth_logger);
	dirLayout = apt_default_dir_layout_create(ROOT_DIR, pool);

	/* Create and start the client in a root dir */
	client = unimrcp_client_create(dirLayout);
	if (!client) FAIL("Cannot create UniMRCP client");
	app = mrcp_application_create(UniSynthAppMsgHandler, NULL, mrcp_client_memory_pool_get(client));
	if (!app) FAIL("Cannot create MRCP application");
	if (!mrcp_client_application_register(client, app, "Sample C app"))
		FAIL("Cannot register MRCP application");
	if (!mrcp_client_start(client)) FAIL("Cannot start MRCP client");

	/* Create a session using MRCP profile MRCP_PROFILE */
	sess = mrcp_application_session_create(app, MRCP_PROFILE, NULL);
	if (!sess) FAIL("Cannot create session");
	spool = mrcp_application_session_pool_get(sess);
	/* Create audio termination with capabilities */
	caps = mpf_stream_capabilities_create(STREAM_DIRECTION_SEND, spool);
	if (!caps) FAIL("Error creating capabilities");
	if (!mpf_codec_capabilities_add(&caps->codecs, MPF_SAMPLE_RATE_8000, "LPCM"))
		FAIL("Error adding codec capabilities");
	term = mrcp_application_audio_termination_create(sess, &stream_vtable, caps, NULL);
	if (!term) FAIL("Cannot create audio termination");
	/* Add signaling channel (and start processing in OnAdd method */
	f = fopen(outfile, "wb");
	if (!f) FAIL("Cannot open output file");
	status = apr_thread_mutex_create(&mutex, APR_THREAD_MUTEX_DEFAULT, pool);
	if (status != APR_SUCCESS) FAIL("Cannot create mutex");
	status = apr_thread_cond_create(&cond, pool);
	if (status != APR_SUCCESS) FAIL("Cannot create condition variable");
	chan = mrcp_application_channel_create(sess, MRCP_SYNTHESIZER_RESOURCE, term, NULL, NULL);
	if (!chan) FAIL("Cannot create channel");
	if (!mrcp_application_channel_add(sess, chan))
		FAIL("Cannot add channel");

	/* Now wait until the processing finishes */
	apr_thread_mutex_lock(mutex);
	while (err < 0) apr_thread_cond_wait(cond, mutex);
	apr_thread_mutex_unlock(mutex);

cleanup:
	if (sess) mrcp_application_session_terminate(sess);
	if (f) fclose(f);
	if (client) mrcp_client_shutdown(client);
	if (app) mrcp_application_destroy(app);
	if (client) mrcp_client_destroy(client);
	apt_log_instance_destroy();
	if (pool) apr_pool_destroy(pool);
	apr_terminate();
	puts("Program finished, memory released. Press any key to exit.");
	(void) getchar();
	return err;
}