[asterisk-speech-rec] Grammar Question

Stephen Keller StephenKeller at LumenVox.com
Wed Apr 21 12:13:44 CDT 2010


> The speech engine does not handle DTMF, Asterisk does that.  The following code handles yes/no both verbally and DTMF:

Actually, a better way to do this is to just build your grammar such that it returns a number, that way you can handle both cases with the same logic in the dialplan.

So let's say you used the following yes/no grammar:

root $yesno;
$yesno = ($yes | $no) {out=rules.latest()};
$yes = (yes [please] | yeah | yup) {out="1"};
$no = (no [thanks] | nope) {out="2"};

Assuming your prompt says "Say 'yes' or press 1, or say 'no' and press 2" then the dialplan can be:

exten => s,1,Set(SPEECH_DTMF_MAXLEN=1)                              ; Set max # DTMF digits to accept per transaction
exten => s,n,SpeechCreate
exten => s,n,SpeechLoadGrammar(yesno,pathtoyesnogrammar)
exten => s,n,SpeechActivateGrammar(yesno)
exten => s,n,SpeechBackground(is-this-john-smith|5)                 ; Ask your question and wait 5 sec for reply
exten => s,n,SpeechDeactivateGrammar(yesno)
exten => s,n,GotoIf($["${SPEECH_TEXT(0)}" = "0"]?oper)              ; caller pressed "0" - go to Operator handler (not shown)
exten => s,n,GotoIf($["${SPEECH_TEXT(0)}" = "1"]?score)             ; caller pressed "1" or said "yes"
exten => s,n,GotoIf($["${SPEECH_TEXT(0)}" = "2"]?score)             ; caller pressed "2" or said "no"
exten => s,n,Goto(invalid)                                          ; unexpected response - go to retry logic (not shown)
exten => s,n(score),GotoIf($[${SPEECH_SCORE(0)} > 650]?proceed)     ; if speech engine was 65+% confident then accept response (not shown)
exten => s,n,Goto(nocomp)                                           ; confidence too low - go to "didn't understand" logic (not shown)

Obviously both cases will work, but it can be a good idea to always get in the habit of normalizing your speech and DTMF outputs, such that you don't need to know which was used.

Thanks,

Stephen Keller
Project Manager
LumenVox
P: 1-877-977-0707 - just say, "Support" 
P: +1-858-707-7700
F: +1-858-707-7072 
support at LumenVox.com
www.LumenVox.com





More information about the asterisk-speech-rec mailing list