LumenVox Call Router Application
Call Router

This simple speech-enabled call router by LumenVox helps to complete the basic speech demonstration that comes with the Asterisk Speech API. Using an included "directory" grammar, the application prompts a user to speak a name and then routes the caller to that person's extension, as specified in the grammar file.

The application also includes the basic confirmation and error handling that is important for every good speech application. It includes several prompts that must be put into your Asterisk sounds directory, and two grammars that should go into the /etc/asterisk/grammars/ directory (you will need to create that directory if it does not already exist).

This application was originally developed for a talk at Astricon 2007. The zip file which can be downloaded by clicking Download Code below includes a PDF of the slides for that tutorial.

Simple Speech–Enabled Call Router Using Dial Plan

Author: Stephen Keller

; The confirmation macro will be used when the application receives input
; that has a middling confidence score. It will ask the user to confirm
; what he or she said. To do this, there are three prompts:
; confirm990.gsm, confirm991.gsm, and confirm992.gsm. The macro knows
; which to play based on the CONFIRMPROMPT variable, which is a string
; with the filname in it, made by combining the word "confirm" with 
; the recognized extension.
exten => s,1,SpeechLoadGrammar(yesno|/etc/asterisk/grammars/yesno.gram)
exten => s,n,SpeechActivateGrammar(yesno)
exten => s,n,Set(CONFIRMPROMPT=$[confirm${ARG1}])
exten => s,n(PlayConfirm),SpeechBackground(didyouwant&${CONFIRMPROMPT}|5)
exten => s,n,GotoIf($[ ${SPEECH(results)} > 0]?Deactivate)
exten => s,n,Playback(NI)
exten => s,n,Goto(PlayConfirm)
exten => s,n(Deactivate),SpeechDeactivateGrammar(yesno)

; Answer the phone, create a speech port, load our directory grammar, call
; SpeechBackground to perform speech recognition while playing the sayname
; prompt. Then deactivate the grammar.
exten => s,1,Answer()
exten => s,n,SpeechCreate()
exten => s,n,SpeechLoadGrammar(directory|/etc/asterisk/grammars/directory.gram)
exten => s,n(Sayname),SpeechActivateGrammar(directory)
exten => s,n,SpeechBackground(sayname|10)
exten => s,n,SpeechDeactivateGrammar(directory)

; Check SPEECH(results) to ensure there was at least one result (i.e. we
; actually received spoken input). If not, we play the no input prompt and
; ask the caller to say something.
exten => s,n,GotoIf($[ ${SPEECH(results)} > 0]?InputOK)
exten => s,n,Playback(NI)
exten => s,n,Goto(Sayname)

; Now that we know there was input, we save the recognized extension to the
; variable DIALTHIS (important to do in case we overwrite SPEECH_TEXT with a 
; confirmation) and print some log messages to the console. Then we run
; a few checks on the confidence score. If it was really low (below 400), we
; will reject the utterance and have the user repeat what was said.
; If it was between 400 and 700, we launch the confirmation macro, passing in
; the recognized result as the only argument. If the user confirms by saying
; yes, or if the confidence score was above 700, we send the user to the
; specified extension.
exten => s,n(InputOK),Set(DIALTHIS=${SPEECH_TEXT(0)})
exten => s,n,Verbose(1,The recognized extension was ${SPEECH_TEXT(0)})
exten => s,n,Verbose(1,The score was ${SPEECH_SCORE(0)})
exten => s,n,GotoIf($[ ${SPEECH_SCORE(0)} < 400]?BadInput)
exten => s,n,GotoIf($[ ${SPEECH_SCORE(0)} > 700]?Dial)
exten => s,n,Macro(confirm,${SPEECH_TEXT(0)})
exten => s,n,GotoIf($[ "${SPEECH_TEXT(0)}" = "yes"]?Dial:Sayname)
exten => s,n(BadInput),Playback(didnotunderstand)
exten => s,n,Goto(Sayname)
exten => s,n(Dial),SpeechDestroy()
exten => s,n,Goto(${DIALTHIS},1)

exten => 990,1,Verbose(1,You called Tom Smith)
exten => 990,n,Playback(tomsmithgreeting)
exten => 990,n,Hangup()

exten => 991,1,Verbose(1,You called Joe Jones)
exten => 991,n,Playback(joejonesgreeting)
exten => 991,n,Hangup

exten => 992,1,Verbose(1,You called Bob Johnson)
exten => 991,n,Playback(bobjohnsongreeting)
exten => 992,n,Hangup
Download Code

© 2016 LumenVox, LLC. All rights reserved.