SAPI - Audio Jukebox
Nowadays, people can listen to their favorite music live through telephones and other communication media.
Entertainment firms require the Jukebox systems to play the music as per the subscriber's choice.
The IVR script mentioned here is a simple approach to implement audio jukebox using SAPI engine that plays the patron's selection from a self-contained list.
Download the evaluation version of Xtend IVR and install the telephony application in your system.
Run the sample script from the Script Editor. Click here to refer the code.
The automated attendant will work as given below:
IVR waits for the call
Accepts the call and plays the Welcome message
IVR prompts the user to enter a number between 0 and 9
Caller has to give the input either by entering the number via keypad or speak out the number
IVR plays back the corresponding music
Download the
source file for the Speech Recognition - SAPI - Audio Jukebox
;------------------------------------------------------------------------------------------
;Script : Juke.dt
;Note : Speech Recognition Script for Audio Juke Box.
; You have to install SAPI 5.x to try this sample
;
; IVR will greet the user and will ask a number in between 0 and 9.
; The caller can either dial the digit or speak out the number to hear the music.
;
; If you are trying this sample using the Xtend IVR Developer Edition,
; remember to use a headset and microphone. Also remember to setup
; your mic as your default multimedia input device in the control panel.
; (Disable MIC Boost and keep the control in 50%)
;
; The accuracy and performance of speech recognition is fully depend upon
; the operating system and speech engine used. You can fine tune the recognition
; accuracy by implementing your own grammer. The grammer details are available
; in SAPI 5.0 documentation available on the web or along with
; your speech recognition engine
;----------------------------------------------------------------------------------------
* Maintain grammar across multiple inputs
srKeepGrammar(true)
* Create a lookup table for converting words to digits
* Since the recognition engine returns spoken words,
* we need to convert then to equivalent digits first
$LookupTable.zero = 0
$LookupTable.one = 1
$LookupTable.two = 2
$LookupTable.three = 3
$LookupTable.four = 4
$LookupTable.five = 5
$LookupTable.six = 6
$LookupTable.seven = 7
$LookupTable.eight = 8
$LookupTable.nine = 0
MAIN:
display "Waiting for call"
* Pickup incoming call on the first ring
answer 1
* Create the SAPI 5 grammar, set the words to be recognized and set it
* Scroll down to see the implementation of the srAcceptWords function
srAcceptWords("one","two","three","four","five","six","seven","eight","nine")
* Welcome the user
play "welcome.wav"
* Ask for Number and accept keypress/ recognize speech
display "Accept number"
$Key = accept("song.wav", 1, 3)
* Check for Speech Recognition
if $InputMode == "S"
* Perform a lookup to convert words to digits using the $$ macro operator
$Var = format("$LookupTable.%s", $Key)
$Key = $$Var
endif
* If a valid digit is present, then play
if $Key >= 1 and $key <= 9
play Format("Music%d.wav",$Key)
endif
* Say goodbye and quit.
play "thank.wav"
hangup
goto MAIN
* User has hung up
ONHANGUP:
hangup
goto MAIN
* An error has occurred
ONSYSTEMERROR:
log $error
display $error
hangup
goto MAIN
Function srAcceptWords()
* Takes in any number of parameters each containing a list of words
* separated by comma and constructs a SRGS Speech Recognition Grammar
* from it to recognise between the specified words in the string.
* Calls srGrammar() to set the grammar to be used.
* Define the basic templates
$GrmStart = '<GRAMMAR LANGID="409"> <DEFINE> <ID NAME="RID_Language" VAL="409"/>
</DEFINE> <RULE ID="RID_Language" TOPLEVEL="ACTIVE">
<LIST PROPID="RID_Language"> '
$GrmEnd = ' </LIST> </RULE> </GRAMMAR>'
$GrmWord = ' <P>%s</P> '
* Now start the loop that extracts each word and
* construct a grammar along the way
* We use internal script variables for supporting infinite no of parameters :-)
* Final grammar will be in $Grm
$Grm = $GrmStart
$Ctr = 1
while $Ctr <= $PluginParamCount
* Take each function parameter
$Var = format("$PluginParam%d",$Ctr)
* Create a grammar tag out of the parameter contents
$Tag = format($GrmWord,$$Var)
* Append to the grammar we are creating
$Grm = concat($Grm, $Tag)
* Increment to use next parameter
$Ctr += 1
endwhile
$Grm = concat($Grm, $GrmEnd)
* Now set the grammar to use
* For complicated grammar scenarios, refer the SRGS documentation
* and call srGrammar() directly in the script instead of using this function
* srGrammar() also supports loading grammar from a file
srGrammar($Grm)
return
*End of Script