예제 #1
0
/** Initialize client -- common to unimrcp_client_create and unimrcp_client_create2 */
static unimrcp_client_loader_t* unimrcp_client_init(apt_dir_layout_t *dir_layout)
{
	apr_pool_t *pool;
	mrcp_client_t *client;
	unimrcp_client_loader_t *loader;

	apt_log(APT_LOG_MARK,APT_PRIO_NOTICE,"UniMRCP Client ["UNI_VERSION_STRING"] [r"UNI_REVISION_STRING"]");
	apt_log(APT_LOG_MARK,APT_PRIO_INFO,"APR ["APR_VERSION_STRING"]");
	client = mrcp_client_create(dir_layout);
	if(!client) {
		return NULL;
	}
	pool = mrcp_client_memory_pool_get(client);
	if(!pool) {
		return NULL;
	}

	loader = apr_palloc(pool,sizeof(unimrcp_client_loader_t));
	loader->dir_layout = dir_layout;
	loader->doc = NULL;
	loader->client = client;
	loader->pool = pool;
	loader->ip = NULL;
	loader->ext_ip = NULL;
	loader->server_ip = NULL;
	loader->auto_ip = NULL;
	return loader;
}
예제 #2
0
/** Create demo framework */
demo_framework_t* demo_framework_create(apt_dir_layout_t *dir_layout)
{
	demo_framework_t *framework = NULL;
	mrcp_client_t *client = unimrcp_client_create(dir_layout);
	if(client) {
		demo_application_t *demo_application;
		apr_pool_t *pool = mrcp_client_memory_pool_get(client);
		/* create demo framework */
		framework = apr_palloc(pool,sizeof(demo_framework_t));
		framework->pool = pool;
		framework->client = client;
		framework->application_table = apr_hash_make(pool);

		/* create demo synthesizer application */
		demo_application = demo_synth_application_create(framework->pool);
		if(demo_application) {
			demo_framework_app_register(framework,demo_application,"synth");
		}

		/* create demo recognizer application */
		demo_application = demo_recog_application_create(framework->pool);
		if(demo_application) {
			demo_framework_app_register(framework,demo_application,"recog");
		}

		/* create demo bypass media application */
		demo_application = demo_bypass_application_create(framework->pool);
		if(demo_application) {
			demo_framework_app_register(framework,demo_application,"bypass");
		}

		/* create demo resource discover application */
		demo_application = demo_discover_application_create(framework->pool);
		if(demo_application) {
			demo_framework_app_register(framework,demo_application,"discover");
		}

		demo_framework_consumer_task_create(framework);

		if(framework->task) {
			apt_task_t *task = apt_consumer_task_base_get(framework->task);
			apt_task_start(task);
		}
		
		/* start client stack */
		mrcp_client_start(client);
	}

	return framework;
}
예제 #3
0
/** Create and load UniMRCP client */
MRCP_DECLARE(mrcp_client_t*) unimrcp_client_create(apt_dir_layout_t *dir_layout)
{
	apr_pool_t *pool;
	mrcp_client_t *client;
	const char *dir_path;
	unimrcp_client_loader_t *loader;

	if(!dir_layout) {
		return NULL;
	}

	apt_log(APT_LOG_MARK,APT_PRIO_NOTICE,"UniMRCP Client ["UNI_VERSION_STRING"]");
	apt_log(APT_LOG_MARK,APT_PRIO_INFO,"APR ["APR_VERSION_STRING"]");
	client = mrcp_client_create(dir_layout);
	if(!client) {
		return NULL;
	}
	pool = mrcp_client_memory_pool_get(client);
	if(!pool) {
		return NULL;
	}

	loader = apr_palloc(pool,sizeof(unimrcp_client_loader_t));
	loader->doc = NULL;
	loader->client = client;
	loader->pool = pool;
	loader->ip = NULL;
	loader->ext_ip = NULL;
	loader->server_ip = NULL;
	loader->auto_ip = NULL;

	dir_path = dir_layout->conf_dir_path;
	if(!dir_path) {
		dir_path = DEFAULT_CONF_DIR_PATH;
	}

	if(unimrcp_client_load(loader,dir_path,CONF_FILE_NAME,pool) == FALSE) {
		apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Failed to Load UniMRCP Client Document");
	}

	return client;
}
예제 #4
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;
}
예제 #5
0
/* Create an MRCP client.
 *
 * Some code and ideas borrowed from unimrcp-client.c
 * Please check $unimrcp_dir$/platforms/libunimrcp-client/src/unimrcp_client.c
 * when upgrading the UniMRCP library to ensure nothing new needs to be set up.
 */
mrcp_client_t *mod_unimrcp_client_create(apr_pool_t *mod_pool)
{
	mrcp_client_t *client = NULL;
	apt_dir_layout_t *dir_layout = NULL;
	apr_pool_t *pool = NULL;
	mrcp_resource_factory_t *resource_factory = NULL;
	mpf_codec_manager_t *codec_manager = NULL;
	apr_size_t max_connection_count = 0;
	apt_bool_t offer_new_connection = FALSE;
	mrcp_connection_agent_t *shared_connection_agent = NULL;
	mpf_engine_t *shared_media_engine = NULL;

	if (!globals.profiles) {
		ast_log(LOG_ERROR, "Profiles hash is NULL\n");
		return NULL;
	}

	/* Create the client. */
	if ((dir_layout = apt_default_dir_layout_create("../", mod_pool)) == NULL) {
		ast_log(LOG_ERROR, "Unable to create directory layout\n");
		return NULL;
	}

	if ((client = mrcp_client_create(dir_layout)) == NULL) {
		ast_log(LOG_ERROR, "Unable to create MRCP client stack\n");
		return NULL;
	}

	if ((pool = mrcp_client_memory_pool_get(client)) == NULL) {
		ast_log(LOG_ERROR, "MRCP client pool is NULL\n");
		return NULL;
	}

	mrcp_resource_loader_t *resource_loader = mrcp_resource_loader_create(FALSE, pool);
	if (resource_loader == NULL) {
		ast_log(LOG_ERROR, "Unable to create MRCP resource loader.\n");
		return NULL;
	}

	apt_str_t resource_class_synth;
	apt_str_t resource_class_recog;
	apt_string_set(&resource_class_synth, "speechsynth");
	apt_string_set(&resource_class_recog, "speechrecog");
	mrcp_resource_load(resource_loader, &resource_class_synth);
	mrcp_resource_load(resource_loader, &resource_class_recog);

	resource_factory = mrcp_resource_factory_get(resource_loader);

	if (!mrcp_client_resource_factory_register(client, resource_factory))
		ast_log(LOG_WARNING, "Unable to register MRCP client resource factory\n");

	if ((codec_manager = mpf_engine_codec_manager_create(pool)) != NULL) {
		if (!mrcp_client_codec_manager_register(client, codec_manager))
			ast_log(LOG_WARNING, "Unable to register MRCP client codec manager\n");
	}

	/* Set up MRCPv2 connection agent that will be shared with all profiles. */
	if ((globals.unimrcp_max_connection_count != NULL) && (strlen(globals.unimrcp_max_connection_count) > 0))
		max_connection_count = atoi(globals.unimrcp_max_connection_count);

	if (max_connection_count <= 0)
		max_connection_count = DEFAULT_UNIMRCP_MAX_CONNECTION_COUNT;

	if (globals.unimrcp_offer_new_connection != NULL) {
		if (strcasecmp(globals.unimrcp_offer_new_connection, "true") == 0 || atoi(globals.unimrcp_offer_new_connection) == 1)
			offer_new_connection = TRUE;
	}
	else {
		offer_new_connection = DEFAULT_UNIMRCP_OFFER_NEW_CONNECTION;
	}

	if ((shared_connection_agent = mrcp_client_connection_agent_create("MRCPv2ConnectionAgent", max_connection_count, offer_new_connection, pool)) != NULL) {
		if (shared_connection_agent != NULL) {
 			if (globals.unimrcp_rx_buffer_size != NULL) {
				apr_size_t rx_buffer_size = (apr_size_t)atol(globals.unimrcp_rx_buffer_size);
				if (rx_buffer_size > 0) {
	 				mrcp_client_connection_rx_size_set(shared_connection_agent, rx_buffer_size);
				}
 			}
 			if (globals.unimrcp_tx_buffer_size != NULL) {
				apr_size_t tx_buffer_size = (apr_size_t)atol(globals.unimrcp_tx_buffer_size);
				if (tx_buffer_size > 0) {
	 				mrcp_client_connection_tx_size_set(shared_connection_agent, tx_buffer_size);
				}
 			}
			if (globals.unimrcp_request_timeout != NULL) {
				apr_size_t request_timeout = (apr_size_t)atol(globals.unimrcp_request_timeout);
				if (request_timeout > 0) {
	 				mrcp_client_connection_timeout_set(shared_connection_agent, request_timeout);
				}
			}
 		}

		if (!mrcp_client_connection_agent_register(client, shared_connection_agent))
			ast_log(LOG_WARNING, "Unable to register MRCP client connection agent\n");
	}

	/* Set up the media engine that will be shared with all profiles. */
	if ((shared_media_engine = mpf_engine_create("MediaEngine", pool)) != NULL) {
		unsigned long realtime_rate = 1;

		if (!mpf_engine_scheduler_rate_set(shared_media_engine, realtime_rate))
			ast_log(LOG_WARNING, "Unable to set scheduler rate for MRCP client media engine\n");

		if (!mrcp_client_media_engine_register(client, shared_media_engine))
			ast_log(LOG_WARNING, "Unable to register MRCP client media engine\n");
	}

	if (globals.profiles) {
		if(load_profiles(client, shared_connection_agent, shared_media_engine, pool) !=0)
			return NULL;
	}

	return client;
}