Asterisk cmd ASR



Automatic Speech Recognition ASR for Asterisk - based on an ASP model by accessing professional, multilanguage Speech Processors

To enable this command you will need to install an additional module as part of asterisk. (Read below)




  • txxxx Recognition timeout in xxxx milliseconds (default 10000)
  • cyy Required confidence level yy in percent (default 80)
  • lz Speakers language (1-German, 2-US English, 3-UK English, 4-Italian, 5-French, 6-Spanish, 7-Portuguese) (default 1)
  • d also recognize spoken digits (0..9, not numbers!). This might be followed by a range of how many digits you like to be recognized. ie: d2 | d3- | d4-9
  • b1 play a "beep" to caller when recognizer is up (requires at least revision 1.4 of app_asr)

If there is no voice signal (start-of-speech) detected within 5 seconds the cmd returns an error. (might make this configurable?)
The cmd will timeout after 30 seconds and return an error in any case.

Always select the language your callers speak natively. It won't work if you select "english" (to use english tokens) but your callers are native german speakers.


A token is simply a written word or phrase to be recognized by the engine. If the engine recognizes a spoken word, which matches those tokens and is above the given confidence level, it will "Goto(token,1)" in same context. The token will be lowercased, and space blanked upfront. Make sure you have an extension of that name defined in the dialplan.

Make sure you use letters, numbers or spaces in token only. Use ae, oe, ue instead of "German Umlaute". It is important that you write the words, even wrongly spelled, like your selected language would pronounce them. (Enable debug in asr.conf to see "Confidence levels" at the console)

For easier use and to group tokens you can prefix the tokens by a fixed extension like:


So if token1 or token2 matches, it will still jump to extension1, priority 1!

If you have used option d and a spoken number (of single digits) was recognized the extension jumped to is: 'digits'+<recognized number> priority 1



If the recognizer is more than 90% confident that the spoken (german) word is either "Support" or "Hilfe", asterisk will Goto(support,1). Or Goto(verkauf,1) if it has recognized "Verkauf". On Error, no match, not enough confidence or Timeout (in given example after 5 seconds), it will continue with next priority.


This module works based on an ASP model. This means: The actual ASR will be done on external servers. During the recognition process audio data will be forwarded to the Recognizer. To make this work you will be required to be connected to the internet and allow outgoing TCP connections to port 5060 and outgoing UDP connections to ports above 51000. Per concurrent ASR channel it will require 64kbps bandwidth (uLaw) for the time of recognition.

This service is provided for free, without any support or warranty.


In order to enable the command in your dialplan, you need to install the module and create an asr.conf in your /etc/asterisk directory.

The right steps

  • Download the app_asr.c and put it into "<asterisk source>/apps" directory
  • Edit the "Makefile" in that directory. Add to the module list, just at beginning of the file: ""
  • cd back into main asterisk source directory and "make install"
  • put the sample asr.conf into your /etc/asterisk directory
  • restart asterisk

  • Note: a version which has conditional code for all versions of asterisk through 1.8 is available at app_asr.c.

Now you can edit your dialplan and make use of the new ASR() command.

Binary - easy but not recommended

If you like to "just" use our precompiled binary of the module:
  • download: into /usr/lib/asterisk/modules/
  • put this asr.conf into your /etc/asterisk directory
  • restart asterisk

The binary was compiled on Debian 3.1 / Linux 2.4.27 /Asterisk 1.2.17

Dialplan example

exten => s,1,GotoIfTime(07:00-22:59|*|*|*?100)
exten => s,2,Ringing
exten => s,3,wait(3)
exten => s,4,SetLanguage(de)
exten => s,5,Voicemail(su8)
exten => s,6,Hangup

exten => s,100,Ringing
exten => s,101,SetLanguage(de)
exten => s,102,Wait(3)
exten => s,103,Answer
exten => s,104,PlayBack(jdtelefon)
exten => s,105,ASR(t5000c80l1,1:tosti,1:Dirk,1:Dirk Tostmann,1:Tostmann,1:Herr Tostmann,1:Technik,1:enum,1:Tiimspiik,2:niki,2:Nikolaus,2:Starzacher,2:Herr Starzacher,2:Nikolaus Starzacher,2:Geschaeftsfuehrer,2:Presse,2:Interviu,2:Gema,2:G V L,radio,sparruf,fonekaaster,telefon,hilfe,support)

; In case of any problem we end up here
exten => s,106,Goto(queue,1)

; These are the ASR() targets
exten => 1,1,PlayBack(gototosti)
exten => 1,2,Goto(accfwd,4,1)

exten => 2,1,PlayBack(gotoniki)
exten => 2,2,Goto(accfwd,8,1)

; Fallback
exten => queue,1,PlayBack(gotoqueue)
exten => queue,2,Queue(justdigits,,,,90)
exten => queue,3,Goto(4)
exten => queue,103,Goto(3)

As you can see: certain words like "radio,sparruf,fonekaaster,telefon,hilfe,support" have no valid extentions in this context. If they get recognized, the recognition will stop and the priority+1 is executed, like an error. The effect: The user doesn't need to wait for the timeout and will be dropped to queue anyway!

Here's another demo example, using ASR() to allow Asterisk to serve an antique manual telephone (with no dial). When you pick up the telephone, an "operator" says "Number please." The telephone is connected to an FXS port on either an ATA (SIP or IAX) or a Zap card arranged for "off-hook" service directly to extension s in context operatordemo. (This example is by John Covert.)

exten => s,1,Ringing()
exten => s,n,Set(l=2) ; U.S. English
exten => s,n,Wait(1)
exten => s,n,Answer
exten => s,n,Ringing()
exten => s,n,Noop(${CALLERID})
exten => s,n,ASR(t1l${l}d) ; 1 millisecond to prime the server connection after long idle time
exten => s,n,Wait(1)
exten => s,n(num),Playback(numplse) ; "Number please"
exten => s,n(asr),ASR(t20000l${l}d) ; Accept digits for up to 20 seconds with default timeout
exten => s,n,Noop(${ASRMSG})
exten => s,n,Gotoif($["${ASRMSG}" != "Server timeout"]?want) ; Recognition failure
exten => s,n,Playback(server&connection-failed)
exten => s,n(want),Playback(numwant) "What number are you wanting, please?"
exten => s,n,Goto(asr)
exten => _digits.,1,Noop(${ASRMSG})
exten => _digits.,n,SayDigits(${EXTEN:6}) ; tell him what we heard him say
exten => _digits.,n,Playback(trying) ; "I'm trying to get them"
exten => _digits.,n,Goto(${EXTEN:6},1)

; include here enough of a dialplan to validate the number given
; or maybe even an enum lookup.

exten => 21,1,Goto(regularcontext,${EXTEN},1) ; for example, 21 might be a valid extension
exten => _NXXNXXXXXX,1,Goto(regularcontext,${EXTEN},1) ; and we might have local ten digit numbers

exten => i,1,Playback(invalid) ; if it doesn't match the above, give him another chance
exten => i,2,Goto(s,want)      ; without having to hang up.


The ASR-cmd sets two variables:

  • ${ASRRES} - contains the name of the extension for the token successfully recognized, otherwise empty
  • ${ASRMSG} - contains additional information about the recognition process in format "<errorcode>|<recognized token>|<confidence>|<additional message>"

The function will always return 0. Only fatal errors, like "Hangup" or "Out of Memory" will cause an result code of -1. Therefor you will need to check contents of variables above.


Dirk Tostmann
just digits GmbH

For questions or feed back email me: tostmann at justdigits doot de

Created by: tostmann, Last modification: Thu 03 of May, 2012 (21:37 UTC) by admin
Please update this page with new information, just login and click on the "Edit" or "Discussion" tab. Get a free login here: Register Thanks! - Find us on Google+