[Freeswitch-svn] [commit] r9082 - freeswitch/trunk/src/mod/asr_tts/mod_pocketsphinx
Freeswitch SVN
brian at freeswitch.org
Thu Jul 17 19:13:12 EDT 2008
Author: brian
Date: Thu Jul 17 19:13:11 2008
New Revision: 9082
Modified:
freeswitch/trunk/src/mod/asr_tts/mod_pocketsphinx/Makefile
freeswitch/trunk/src/mod/asr_tts/mod_pocketsphinx/mod_pocketsphinx.c
Log:
add 16k support to pocketsphinx using the wsj1 model.
Modified: freeswitch/trunk/src/mod/asr_tts/mod_pocketsphinx/Makefile
==============================================================================
--- freeswitch/trunk/src/mod/asr_tts/mod_pocketsphinx/Makefile (original)
+++ freeswitch/trunk/src/mod/asr_tts/mod_pocketsphinx/Makefile Thu Jul 17 19:13:11 2008
@@ -47,6 +47,10 @@
mkdir -p $(DESTDIR)$(PREFIX)/grammar/model/communicator
mv $(BASE)/libs/Communicator_semi_40.cd_semi_6000/* $(DESTDIR)$(PREFIX)/grammar/model/communicator
+$(DESTDIR)$(PREFIX)/grammar/model/wsj1:
+ mkdir -p $(DESTDIR)$(PREFIX)/grammar/model/wjs1
+ mv $(POCKETSPHINX_DIR)/model/hmm/wsj1/* $(DESTDIR)$(PREFIX)/grammar/model/communicator/wsj1
+
grammar_maker:
@cp -f $(BASE)/scripts/mklm $(DESTDIR)$(PREFIX)/bin/mklm
@cp -f $(BASE)/scripts/quick_lm.pl $(DESTDIR)$(PREFIX)/bin/quick_lm.pl
@@ -55,4 +59,4 @@
@cp -f $(BASE)/scripts/Makefile.gram $(DESTDIR)$(PREFIX)/grammar/Makefile
@cp -f $(POCKETSPHINX_DIR)/model/lm/cmudict.0.6d $(DESTDIR)$(PREFIX)/conf/cmudict.0.6d
-local_install: $(DESTDIR)$(PREFIX)/grammar/model $(DESTDIR)$(PREFIX)/grammar/model/communicator grammar_maker
+local_install: $(DESTDIR)$(PREFIX)/grammar/model $(DESTDIR)$(PREFIX)/grammar/model/communicator $(DESTDIR)$(PREFIX)/grammar/model/wsj1 grammar_maker
Modified: freeswitch/trunk/src/mod/asr_tts/mod_pocketsphinx/mod_pocketsphinx.c
==============================================================================
--- freeswitch/trunk/src/mod/asr_tts/mod_pocketsphinx/mod_pocketsphinx.c (original)
+++ freeswitch/trunk/src/mod/asr_tts/mod_pocketsphinx/mod_pocketsphinx.c Thu Jul 17 19:13:11 2008
@@ -43,7 +43,8 @@
static switch_event_node_t *NODE = NULL;
static struct {
- char *model;
+ char *model8k;
+ char *model16k;
uint32_t thresh;
uint32_t silence_hits;
uint32_t listen_hits;
@@ -78,19 +79,25 @@
/*! function to open the asr interface */
static switch_status_t pocketsphinx_asr_open(switch_asr_handle_t *ah, const char *codec, int rate, const char *dest, switch_asr_flag_t *flags)
{
-
pocketsphinx_t *ps;
if (!(ps = (pocketsphinx_t *) switch_core_alloc(ah->memory_pool, sizeof(*ps)))) {
return SWITCH_STATUS_MEMERR;
}
-
switch_mutex_init(&ps->flag_mutex, SWITCH_MUTEX_NESTED, ah->memory_pool);
ah->private_info = ps;
+ if (rate == 8000) {
+ ah->rate = 8000;
+ } else if (rate == 16000) {
+ ah->rate = 16000;
+ } else {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "invalid rate %d. Only 8000 and 16000 are supported.\n", rate);
+ }
+
codec = "L16";
- ah->rate = 8000;
+
ah->codec = switch_core_strdup(ah->memory_pool, codec);
@@ -105,7 +112,7 @@
/*! function to load a grammar to the asr interface */
static switch_status_t pocketsphinx_asr_load_grammar(switch_asr_handle_t *ah, const char *grammar, const char *path)
{
- char *lm, *dic, *model;
+ char *lm, *dic, *model, *rate = NULL;
pocketsphinx_t *ps = (pocketsphinx_t *) ah->private_info;
switch_status_t status = SWITCH_STATUS_FALSE;
@@ -122,8 +129,11 @@
dic = switch_mprintf("%s%s%s%s%s.dic", SWITCH_GLOBAL_dirs.grammar_dir, SWITCH_PATH_SEPARATOR, grammar, SWITCH_PATH_SEPARATOR, grammar);
}
- model = switch_mprintf("%s%smodel%s%s", SWITCH_GLOBAL_dirs.grammar_dir, SWITCH_PATH_SEPARATOR, SWITCH_PATH_SEPARATOR, globals.model);
-
+ if (ah->rate == 8000) {
+ model = switch_mprintf("%s%smodel%s%s", SWITCH_GLOBAL_dirs.grammar_dir, SWITCH_PATH_SEPARATOR, SWITCH_PATH_SEPARATOR, globals.model8k);
+ } else {
+ model = switch_mprintf("%s%smodel%s%s", SWITCH_GLOBAL_dirs.grammar_dir, SWITCH_PATH_SEPARATOR, SWITCH_PATH_SEPARATOR, globals.model16k);
+ }
if (switch_file_exists(dic, ah->memory_pool) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't open dictionary %s.\n", dic);
goto end;
@@ -134,10 +144,12 @@
goto end;
}
+ rate = switch_mprintf("%d", ah->rate);
+
switch_assert(lm && dic && model);
ps->config = cmd_ln_init(ps->config, ps_args(), FALSE,
- "-samprate", "8000",
+ "-samprate", rate,
"-hmm", model,
"-lm", lm,
"-dict", dic,
@@ -175,6 +187,7 @@
end:
+ switch_safe_free(rate);
switch_safe_free(lm);
switch_safe_free(dic);
switch_safe_free(model);
@@ -366,8 +379,8 @@
lconf = (int32_t)logmath_log_to_ln(ps_get_logmath(ps->ps), conf);
ps->confidence = lconf - lconf - lconf;
- if (ps->confidence > 100) {
- ps->confidence = 100;
+ if (ps->confidence > 1000) {
+ ps->confidence = 1000;
} else if (ps->confidence < 0) {
ps->confidence = 0;
}
@@ -482,7 +495,9 @@
asr_interface->asr_check_results = pocketsphinx_asr_check_results;
asr_interface->asr_get_results = pocketsphinx_asr_get_results;
- globals.model = switch_core_strdup(pool, "communicator");
+ globals.model8k = switch_core_strdup(pool, "communicator");
+ globals.model16k = switch_core_strdup(pool, "wsj1");
+
err_set_logfp(NULL);
/* indicate that the module should continue to be loaded */
More information about the Freeswitch-svn
mailing list