plivo/plivoframework — pull request #99 by englercj (2013-03-27 14:28:43+00:00)
Title: Fix Multiple Grammars

I made an incorrect assumption with the way multiple grammar loading in FreeSWITCH worked, so the last patch was doing it incorrectly.

From `mod_unimrcp.c` lines 3085-3097, inside `recog_asr_load_grammar()`:

```C
start_recognize = (char *) switch_core_hash_find(schannel->params, "start-recognize");
if (zstr(start_recognize) || strcasecmp(start_recognize, "false"))
{
if (recog_channel_disable_all_grammars(schannel) != SWITCH_STATUS_SUCCESS) {
status = SWITCH_STATUS_FALSE;
goto done;
}
if (recog_channel_enable_grammar(schannel, name) != SWITCH_STATUS_SUCCESS) {
status = SWITCH_STATUS_FALSE;
goto done;
}
status = recog_channel_start(schannel);
}
```

As you can see unless `start-recognize` is set to `false` in your unimrcp profile (under ``) FreeSWITCH will *disable* all grammars whenever you load one. Which means recognition will only work for the last grammar you load. Also, you need to initialize speech detection with a `detect_speech` call *before* loading other grammars.

This patch makes sure to initialize detection first, then load grammars second, then finally after all are loaded running a `detect_speech resume` to start using them all. However multiple grammars will **only work if `start-recognize` is set to `false`** as mentioned above.

This seems to be working well for me to load multiple grammars, including DTMF grammars with LumenVox; and I am getting speech results properly for any matches to the grammars.