[Freeswitch-svn] [commit] r6012 - in freeswitch/trunk/src: . include mod/asr_tts/mod_openmrcp

Freeswitch SVN anthm at freeswitch.org
Sat Oct 20 13:42:36 EDT 2007


Author: anthm
Date: Sat Oct 20 13:42:35 2007
New Revision: 6012

Modified:
   freeswitch/trunk/src/include/switch_module_interfaces.h
   freeswitch/trunk/src/mod/asr_tts/mod_openmrcp/Makefile
   freeswitch/trunk/src/mod/asr_tts/mod_openmrcp/mod_openmrcp.c
   freeswitch/trunk/src/switch_core_asr.c
   freeswitch/trunk/src/switch_core_speech.c

Log:
make mod_openmrcp profile name choosable from engine_name parameter e.g. openmrcp:myprofile

Modified: freeswitch/trunk/src/include/switch_module_interfaces.h
==============================================================================
--- freeswitch/trunk/src/include/switch_module_interfaces.h	(original)
+++ freeswitch/trunk/src/include/switch_module_interfaces.h	Sat Oct 20 13:42:35 2007
@@ -327,6 +327,8 @@
 	/*! The Rate */
 	uint32_t rate;
 	char *grammar;
+	/*! module specific param*/
+	char *param;
 	/*! the handle's memory pool */
 	switch_memory_pool_t *memory_pool;
 	/*! private data for the format module to store handle specific info */
@@ -367,7 +369,9 @@
 	uint32_t speed;
 	uint32_t samples;
 	char voice[80];
-	char engine[80];
+	char *engine;
+	/*! module specific param*/
+	char *param;
 	/*! the handle's memory pool */
 	switch_memory_pool_t *memory_pool;
 	/*! private data for the format module to store handle specific info */

Modified: freeswitch/trunk/src/mod/asr_tts/mod_openmrcp/Makefile
==============================================================================
--- freeswitch/trunk/src/mod/asr_tts/mod_openmrcp/Makefile	(original)
+++ freeswitch/trunk/src/mod/asr_tts/mod_openmrcp/Makefile	Sat Oct 20 13:42:35 2007
@@ -25,12 +25,11 @@
 SOFIALA=$(SOFIAUA_DIR)/libsofia-sip-ua.la
 
 include ../../../../build/modmake.rules
-
-$(OPENMRCP_DIR)/Makefile:
+$(OPENMRCP_DIR)/.built:
 	cd $(OPENMRCP_DIR) && ./bootstrap && ./configure --with-apr=../apr --with-apr-util=../apr-util --with-sofia-sip=../sofia-sip
+	cd $(OPENMRCP_DIR) && $(MAKE) && touch $(OPENMRCP_DIR)/.built
 
-$(OPENMRCP_LIBS): $(OPENMRCP_DIR)/Makefile $(SOFIALA)
-	cd $(OPENMRCP_DIR) && $(MAKE)
+$(OPENMRCP_LIBS): $(SOFIALA) $(OPENMRCP_DIR)/.built
 
 $(SOFIALA): $(SOFIA_DIR) $(SOFIA_DIR)/.update
 	cd $(SOFIA_DIR) && $(MAKE)

Modified: freeswitch/trunk/src/mod/asr_tts/mod_openmrcp/mod_openmrcp.c
==============================================================================
--- freeswitch/trunk/src/mod/asr_tts/mod_openmrcp/mod_openmrcp.c	(original)
+++ freeswitch/trunk/src/mod/asr_tts/mod_openmrcp/mod_openmrcp.c	Sat Oct 20 13:42:35 2007
@@ -98,13 +98,14 @@
 typedef struct {
 	switch_memory_pool_t *pool;
 	switch_hash_t        *profile_hash;
-
-	openmrcp_profile_t   *asr_profile;
-	openmrcp_profile_t   *tts_profile;
+	char *asr_profile_name;
+	char *tts_profile_name;
+	//openmrcp_profile_t   *asr_profile;
+	//openmrcp_profile_t   *tts_profile;
 } openmrcp_module_t;
 
 static openmrcp_module_t openmrcp_module;
-
+static switch_status_t openmrcp_profile_run(openmrcp_profile_t *profile);
 
 static openmrcp_session_t* openmrcp_session_create(openmrcp_profile_t *profile)
 {
@@ -287,7 +288,9 @@
 {
 	openmrcp_session_t *asr_session;
 	mrcp_client_channel_t *asr_channel;
-	
+	char *profile_name = openmrcp_module.asr_profile_name;
+	openmrcp_profile_t   *asr_profile = NULL;
+
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "asr_open called, codec: %s, rate: %d\n", codec, rate);
 
 	if (strcmp(codec, "L16")) {
@@ -299,8 +302,19 @@
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Sorry, only 8kz supported\n");
 		return SWITCH_STATUS_GENERR;		
 	}
+
+	if (!switch_strlen_zero(ah->param)) {
+		profile_name = ah->param;
+	}
+
+	if (!(asr_profile = switch_core_hash_find(openmrcp_module.profile_hash, profile_name))) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot locate profile %s\n", profile_name);
+		return SWITCH_STATUS_GENERR;		
+	}
+
 	/* create session */
-	asr_session = openmrcp_session_create(openmrcp_module.asr_profile);
+	asr_session = openmrcp_session_create(asr_profile);
+
 	if (!asr_session) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "asr_session creation FAILED\n");
 		return SWITCH_STATUS_GENERR;
@@ -593,9 +607,21 @@
 {
 	openmrcp_session_t *tts_session;
 	mrcp_client_channel_t *tts_channel;
+	char *profile_name = openmrcp_module.tts_profile_name;
+	openmrcp_profile_t   *tts_profile = NULL;
+
+	if (!switch_strlen_zero(sh->param)) {
+		profile_name = sh->param;
+	}
+
+	if (!(tts_profile = switch_core_hash_find(openmrcp_module.profile_hash, profile_name))) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot locate profile %s\n", profile_name);
+		return SWITCH_STATUS_GENERR;		
+	}
 
 	/* create session */
-	tts_session = openmrcp_session_create(openmrcp_module.tts_profile);
+	tts_session = openmrcp_session_create(tts_profile);
+
 	if (!tts_session) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "tts_session creation FAILED\n");
 		return SWITCH_STATUS_GENERR;
@@ -742,8 +768,6 @@
 static switch_status_t do_config()
 {
 	char *cf = "mod_openmrcp.conf";
-	const char *asr_profile_name = NULL;
-	const char *tts_profile_name = NULL;
 	switch_xml_t cfg, xml, settings, profiles, xprofile, param;
 	openmrcp_profile_t *mrcp_profile;
 	openmrcp_client_options_t *mrcp_options;
@@ -760,9 +784,9 @@
 			const char *val = switch_xml_attr_soft(param, "value");
 
 			if (!strcasecmp(var, "asr_default_profile")) {
-				asr_profile_name = val;
+				openmrcp_module.asr_profile_name = switch_core_strdup(openmrcp_module.pool, val);
 			} else if (!strcasecmp(var, "tts_default_profile")) {
-				tts_profile_name = val;
+				openmrcp_module.tts_profile_name = switch_core_strdup(openmrcp_module.pool, val);
 			} else if (!strcasecmp(var, "log_level")) {
 				mrcp_logger.priority = atoi(val);
 			}
@@ -805,33 +829,11 @@
 				}
 			}
 			mrcp_profile->mrcp_options = mrcp_options;
-
+			
 			/* add profile */
 			if (!switch_core_hash_find(openmrcp_module.profile_hash, mrcp_profile->name)) {
 				switch_core_hash_insert(openmrcp_module.profile_hash, mrcp_profile->name, mrcp_profile);
-
-				/* try to set default asr profile */
-				if (!openmrcp_module.asr_profile) {
-					if (asr_profile_name) {
-						if (!strcasecmp(mrcp_profile->name, asr_profile_name)) {
-							openmrcp_module.asr_profile = mrcp_profile;
-						}
-					}
-					else {
-						openmrcp_module.asr_profile = mrcp_profile;
-					}
-				}
-				/* try to set default tts profile */
-				if (!openmrcp_module.tts_profile) {
-					if (tts_profile_name) {
-						if (!strcasecmp(mrcp_profile->name, tts_profile_name)) {
-							openmrcp_module.tts_profile = mrcp_profile;
-						}
-					}
-					else {
-						openmrcp_module.tts_profile = mrcp_profile;
-					}
-				}
+				openmrcp_profile_run(mrcp_profile);
 			}
 		}
 	}
@@ -892,9 +894,6 @@
 	mrcp_global_init();
 
 	openmrcp_module.pool = mrcp_global_pool_get();
-	openmrcp_module.asr_profile = NULL;
-	openmrcp_module.tts_profile = NULL;
-
 	switch_core_hash_init(&openmrcp_module.profile_hash, openmrcp_module.pool);
 
 	/* read config */
@@ -902,43 +901,30 @@
 		return SWITCH_STATUS_FALSE;
 	}
 
-	/* run default asr/tts profiles */
-	if(openmrcp_module.asr_profile) {
-		openmrcp_profile_run(openmrcp_module.asr_profile);
-	}
-	if(openmrcp_module.tts_profile && openmrcp_module.tts_profile != openmrcp_module.asr_profile) {
-		openmrcp_profile_run(openmrcp_module.tts_profile);
-	}
-
 	return SWITCH_STATUS_SUCCESS;
 }
 
 static switch_status_t openmrcp_destroy()
 {
 	/* destroy asr/tts profiles */
-	if(openmrcp_module.asr_profile) {
-		/* shutdown client engine */
-		openmrcp_client_shutdown(openmrcp_module.asr_profile->mrcp_client);
-		/* destroy client context */
-		mrcp_client_context_destroy(openmrcp_module.asr_profile->mrcp_context);
-		if(openmrcp_module.tts_profile == openmrcp_module.asr_profile) {
-			openmrcp_module.tts_profile = NULL;
-		}
-		openmrcp_module.asr_profile = NULL;
-	}
-	if(openmrcp_module.tts_profile) {
+	switch_hash_index_t *hi;
+	void *val;
+	openmrcp_profile_t *mrcp_profile;
+
+	for (hi = switch_hash_first(NULL, openmrcp_module.profile_hash); hi; hi = switch_hash_next(hi)) {
+		switch_hash_this(hi, NULL, NULL, &val);
+		mrcp_profile = (openmrcp_profile_t *) val;
 		/* shutdown client engine */
-		openmrcp_client_shutdown(openmrcp_module.tts_profile->mrcp_client);
+		openmrcp_client_shutdown(mrcp_profile->mrcp_client);
 		/* destroy client context */
-		mrcp_client_context_destroy(openmrcp_module.tts_profile->mrcp_context);
-		openmrcp_module.tts_profile = NULL;
+		mrcp_client_context_destroy(mrcp_profile->mrcp_context);		
 	}
-
 	switch_core_hash_destroy(&openmrcp_module.profile_hash);
 	openmrcp_module.profile_hash = NULL;
 
 	/* one-time mrcp global destroy */
 	mrcp_global_destroy();
+
 	return SWITCH_STATUS_SUCCESS;
 }
 

Modified: freeswitch/trunk/src/switch_core_asr.c
==============================================================================
--- freeswitch/trunk/src/switch_core_asr.c	(original)
+++ freeswitch/trunk/src/switch_core_asr.c	Sat Oct 20 13:42:35 2007
@@ -39,6 +39,16 @@
 													 char *codec, int rate, char *dest, switch_asr_flag_t *flags, switch_memory_pool_t *pool)
 {
 	switch_status_t status;
+	char buf[256] = "";
+	char *param = NULL;
+
+	if (strchr(module_name, ':')) {
+		switch_set_string(buf, module_name);
+		if ((param = strchr(buf, ':'))) {
+			*param++ = '\0';
+			module_name = buf;
+		}
+	}
 
 	assert(ah != NULL);
 
@@ -58,6 +68,9 @@
 		switch_set_flag(ah, SWITCH_ASR_FLAG_FREE_POOL);
 	}
 
+	if (param) {
+		ah->param = switch_core_strdup(ah->memory_pool, param);
+	}
 	ah->rate = rate;
 	ah->name = switch_core_strdup(ah->memory_pool, module_name);
 

Modified: freeswitch/trunk/src/switch_core_speech.c
==============================================================================
--- freeswitch/trunk/src/switch_core_speech.c	(original)
+++ freeswitch/trunk/src/switch_core_speech.c	Sat Oct 20 13:42:35 2007
@@ -44,13 +44,23 @@
 														switch_memory_pool_t *pool)
 {
 	switch_status_t status;
+	char buf[256] = "";
+	char *param = NULL;
+
+	if (strchr(module_name, ':')) {
+		switch_set_string(buf, module_name);
+		if ((param = strchr(buf, ':'))) {
+			*param++ = '\0';
+			module_name = buf;
+		}
+	}
+
 
 	if ((sh->speech_interface = switch_loadable_module_get_speech_interface(module_name)) == 0) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "invalid speech module [%s]!\n", module_name);
 		return SWITCH_STATUS_GENERR;
 	}
 
-	switch_copy_string(sh->engine, module_name, sizeof(sh->engine));
 	sh->flags = *flags;
 	if (pool) {
 		sh->memory_pool = pool;
@@ -60,6 +70,13 @@
 		}
 		switch_set_flag(sh, SWITCH_SPEECH_FLAG_FREE_POOL);
 	}
+
+	sh->engine = switch_core_strdup(sh->memory_pool, module_name);
+	if (param) {
+		sh->param = switch_core_strdup(sh->memory_pool, param);
+	}
+
+
 	sh->rate = rate;
 	sh->name = switch_core_strdup(pool, module_name);
 	sh->samples = switch_bytes_per_frame(rate, interval);



More information about the Freeswitch-svn mailing list