Revamp mod_pocketsphinx to use jsgf format. Known bugs which are going to be fixed are:
Using words in your grammar that aren't in the dictionary will segfault. Bug is already brought up with the pocketsphinx maintainer. /b git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@12224 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
parent
5467d03a96
commit
54ff389b09
|
@ -0,0 +1,14 @@
|
||||||
|
#JSGF V1.0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* JSGF Grammar for example
|
||||||
|
*/
|
||||||
|
|
||||||
|
grammar example;
|
||||||
|
|
||||||
|
<yes> = [ yes ];
|
||||||
|
<no> = [ no ];
|
||||||
|
|
||||||
|
public <results> = [ <yes> | <no> ];
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@ BASE=../../../..
|
||||||
include $(BASE)/build/modmake.rules
|
include $(BASE)/build/modmake.rules
|
||||||
|
|
||||||
$(SPHINXBASE_DIR):
|
$(SPHINXBASE_DIR):
|
||||||
$(GETLIB) $(SPHINXBASE).tar.gz
|
$(GETLIB) $(SPHINXBASE)-latest.tar.gz
|
||||||
|
|
||||||
$(SPHINXBASE_DIR)/buildstamp: $(SPHINXBASE_DIR)
|
$(SPHINXBASE_DIR)/buildstamp: $(SPHINXBASE_DIR)
|
||||||
test -f $(SPHINXBASE_DIR)/Makefile || (cd $(SPHINXBASE_DIR) && ./configure --with-pic --without-python --disable-shared CFLAGS=)
|
test -f $(SPHINXBASE_DIR)/Makefile || (cd $(SPHINXBASE_DIR) && ./configure --with-pic --without-python --disable-shared CFLAGS=)
|
||||||
|
@ -26,7 +26,7 @@ $(SPHINXBASE_LA): $(SPHINXBASE_DIR)/buildstamp
|
||||||
$(TOUCH_TARGET)
|
$(TOUCH_TARGET)
|
||||||
|
|
||||||
$(POCKETSPHINX_DIR):
|
$(POCKETSPHINX_DIR):
|
||||||
$(GETLIB) $(POCKETSPHINX).tar.gz
|
$(GETLIB) $(POCKETSPHINX)-latest.tar.gz
|
||||||
|
|
||||||
$(POCKETSPHINX_DIR)/Makefile: $(POCKETSPHINX_DIR)
|
$(POCKETSPHINX_DIR)/Makefile: $(POCKETSPHINX_DIR)
|
||||||
cd $(POCKETSPHINX_DIR) && ./configure --with-pic --without-python --disable-shared --with-sphinxbase=$(SPHINXBASE_DIR) CFLAGS=
|
cd $(POCKETSPHINX_DIR) && ./configure --with-pic --without-python --disable-shared --with-sphinxbase=$(SPHINXBASE_DIR) CFLAGS=
|
||||||
|
@ -51,12 +51,7 @@ $(DESTDIR)$(PREFIX)/grammar/model/wsj1:
|
||||||
mkdir -p $(DESTDIR)$(PREFIX)/grammar/model/wsj1
|
mkdir -p $(DESTDIR)$(PREFIX)/grammar/model/wsj1
|
||||||
mv $(POCKETSPHINX_DIR)/model/hmm/wsj1/* $(DESTDIR)$(PREFIX)/grammar/model/wsj1
|
mv $(POCKETSPHINX_DIR)/model/hmm/wsj1/* $(DESTDIR)$(PREFIX)/grammar/model/wsj1
|
||||||
|
|
||||||
grammar_maker:
|
dictionary:
|
||||||
@cp -f $(BASE)/scripts/mklm $(DESTDIR)$(PREFIX)/bin/mklm
|
@cp -f $(POCKETSPHINX_DIR)/model/lm/cmudict.0.6d $(DESTDIR)$(PREFIX)/grammar/default.dic
|
||||||
@cp -f $(BASE)/scripts/quick_lm.pl $(DESTDIR)$(PREFIX)/bin/quick_lm.pl
|
|
||||||
@chmod 755 $(DESTDIR)$(PREFIX)/bin/mklm
|
|
||||||
@chmod 755 $(DESTDIR)$(PREFIX)/bin/quick_lm.pl
|
|
||||||
@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 $(DESTDIR)$(PREFIX)/grammar/model/wsj1 grammar_maker
|
local_install: $(DESTDIR)$(PREFIX)/grammar/model $(DESTDIR)$(PREFIX)/grammar/model/communicator $(DESTDIR)$(PREFIX)/grammar/model/wsj1 dictionary
|
||||||
|
|
|
@ -113,7 +113,7 @@ static switch_status_t pocketsphinx_asr_open(switch_asr_handle_t *ah, const char
|
||||||
/*! function to load a grammar to the asr interface */
|
/*! 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)
|
static switch_status_t pocketsphinx_asr_load_grammar(switch_asr_handle_t *ah, const char *grammar, const char *path)
|
||||||
{
|
{
|
||||||
char *lm, *dic, *model, *rate = NULL;
|
char *jsgf, *dic, *model, *rate = NULL;
|
||||||
pocketsphinx_t *ps = (pocketsphinx_t *) ah->private_info;
|
pocketsphinx_t *ps = (pocketsphinx_t *) ah->private_info;
|
||||||
switch_status_t status = SWITCH_STATUS_FALSE;
|
switch_status_t status = SWITCH_STATUS_FALSE;
|
||||||
|
|
||||||
|
@ -123,11 +123,9 @@ static switch_status_t pocketsphinx_asr_load_grammar(switch_asr_handle_t *ah, co
|
||||||
}
|
}
|
||||||
|
|
||||||
if (switch_is_file_path(grammar)) {
|
if (switch_is_file_path(grammar)) {
|
||||||
lm = switch_mprintf("%s%s%s.lm", grammar, SWITCH_PATH_SEPARATOR, grammar);
|
jsgf = switch_mprintf("%s.gram", grammar);
|
||||||
dic = switch_mprintf("%s%s%s.dic", grammar, SWITCH_PATH_SEPARATOR, grammar);
|
|
||||||
} else {
|
} else {
|
||||||
lm = switch_mprintf("%s%s%s%s%s.lm", SWITCH_GLOBAL_dirs.grammar_dir, SWITCH_PATH_SEPARATOR, grammar, SWITCH_PATH_SEPARATOR, grammar);
|
jsgf = switch_mprintf("%s%s%s.gram", SWITCH_GLOBAL_dirs.grammar_dir, SWITCH_PATH_SEPARATOR, grammar);
|
||||||
dic = switch_mprintf("%s%s%s%s%s.dic", SWITCH_GLOBAL_dirs.grammar_dir, SWITCH_PATH_SEPARATOR, grammar, SWITCH_PATH_SEPARATOR, grammar);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ah->rate == 8000) {
|
if (ah->rate == 8000) {
|
||||||
|
@ -135,24 +133,27 @@ static switch_status_t pocketsphinx_asr_load_grammar(switch_asr_handle_t *ah, co
|
||||||
} else {
|
} else {
|
||||||
model = switch_mprintf("%s%smodel%s%s", SWITCH_GLOBAL_dirs.grammar_dir, SWITCH_PATH_SEPARATOR, SWITCH_PATH_SEPARATOR, globals.model16k);
|
model = switch_mprintf("%s%smodel%s%s", SWITCH_GLOBAL_dirs.grammar_dir, SWITCH_PATH_SEPARATOR, SWITCH_PATH_SEPARATOR, globals.model16k);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dic = switch_mprintf("%s%sdefault.dic", SWITCH_GLOBAL_dirs.grammar_dir, SWITCH_PATH_SEPARATOR, grammar);
|
||||||
|
|
||||||
if (switch_file_exists(dic, ah->memory_pool) != SWITCH_STATUS_SUCCESS) {
|
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);
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't open dictionary %s.\n", dic);
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (switch_file_exists(lm, ah->memory_pool) != SWITCH_STATUS_SUCCESS) {
|
if (switch_file_exists(jsgf, ah->memory_pool) != SWITCH_STATUS_SUCCESS) {
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Can't open language model %s.\n", model);
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Can't open language model %s.\n", model);
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
rate = switch_mprintf("%d", ah->rate);
|
rate = switch_mprintf("%d", ah->rate);
|
||||||
|
|
||||||
switch_assert(lm && dic && model);
|
switch_assert(jsgf && dic && model);
|
||||||
|
|
||||||
ps->config = cmd_ln_init(ps->config, ps_args(), FALSE,
|
ps->config = cmd_ln_init(ps->config, ps_args(), FALSE,
|
||||||
"-samprate", rate,
|
"-samprate", rate,
|
||||||
"-hmm", model,
|
"-hmm", model,
|
||||||
"-lm", lm,
|
"-jsgf", jsgf,
|
||||||
"-dict", dic,
|
"-dict", dic,
|
||||||
"-frate", "50",
|
"-frate", "50",
|
||||||
"-silprob", "0.005",
|
"-silprob", "0.005",
|
||||||
|
@ -185,7 +186,7 @@ static switch_status_t pocketsphinx_asr_load_grammar(switch_asr_handle_t *ah, co
|
||||||
end:
|
end:
|
||||||
|
|
||||||
switch_safe_free(rate);
|
switch_safe_free(rate);
|
||||||
switch_safe_free(lm);
|
switch_safe_free(jsgf);
|
||||||
switch_safe_free(dic);
|
switch_safe_free(dic);
|
||||||
switch_safe_free(model);
|
switch_safe_free(model);
|
||||||
|
|
||||||
|
@ -201,15 +202,12 @@ static switch_status_t pocketsphinx_asr_unload_grammar(switch_asr_handle_t *ah,
|
||||||
/*! function to close the asr interface */
|
/*! function to close the asr interface */
|
||||||
static switch_status_t pocketsphinx_asr_close(switch_asr_handle_t *ah, switch_asr_flag_t *flags)
|
static switch_status_t pocketsphinx_asr_close(switch_asr_handle_t *ah, switch_asr_flag_t *flags)
|
||||||
{
|
{
|
||||||
char const *hyp;
|
|
||||||
int32_t score;
|
|
||||||
pocketsphinx_t *ps = (pocketsphinx_t *) ah->private_info;
|
pocketsphinx_t *ps = (pocketsphinx_t *) ah->private_info;
|
||||||
|
|
||||||
switch_mutex_lock(ps->flag_mutex);
|
switch_mutex_lock(ps->flag_mutex);
|
||||||
if (switch_test_flag(ps, PSFLAG_ALLOCATED)) {
|
if (switch_test_flag(ps, PSFLAG_ALLOCATED)) {
|
||||||
if (switch_test_flag(ps, PSFLAG_READY)) {
|
if (switch_test_flag(ps, PSFLAG_READY)) {
|
||||||
ps_end_utt(ps->ps);
|
ps_end_utt(ps->ps);
|
||||||
hyp = ps_get_hyp(ps->ps, &score, &ps->uttid);
|
|
||||||
}
|
}
|
||||||
ps_free(ps->ps);
|
ps_free(ps->ps);
|
||||||
ps->ps = NULL;
|
ps->ps = NULL;
|
||||||
|
|
Loading…
Reference in New Issue