MRCP - 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 MRCP server 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 enters the input either through speech or through keypad
IVR plays back the corresponding music
Download the
source file for the Speech Recognition - MRCP - Audio Jukebox
;----------------------------------------------------------------------------------------
;Script : Juke.dt
;Note : Speech Recognition Script for Audio Juke Box.
; You have to install a MRCP Server 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
; SRGS documentation available on the web or
; along with your speech recognition engine
;-----------------------------------------------------------------------------------------
* Recognition language you would be using, currently English-Indian
* This setting is used in the creation of the xml:lang
* tag by the srAcceptWord() function
$srLanguage = "en-IN"
* 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 = 9
MAIN:
display "Waiting for call"
* Pickup incoming call on the first ring
answer 1
* Welcome the user
play "welcome.wav"
while true
* Ask for Number and accept keypress/ recognize speech
display "Accept number"
play "song.wav"
wait 0
* Create the SRGS grammar, set the words to be recognized and set it
* Scroll down to see the implementation of the srAcceptWords function
srAcceptWords("zero", "one","two","three", "four","five","six","seven",
"eight","nine")
$Key = input(1)
* Check for Speech Recognition
if $InputMode == "S"
* On Valid Match, $Key contains MRCP 1.0 XML result
* Extract the tag we need... this will be <instance>
* Other tags like confidence can also be extracted if needed.
$Var = ExtractXmlTag($Key,"instance>","instance>")
if $Var <> ""
$Var = Left($Var,Find($Var,"<"))
endif
* Perform a lookup to convert words
* to digits using the $$ macro operator
$Var = format("$LookupTable.%s", $Var)
if IsVariable($Var)
$Key = $$Var
endif
endif
srAcceptWords("")
if $Key == 0
break
endif
* If a valid digit is present, then play
if $Key >= 1 and $key <= 9
play Format("Music%d.wav",$Key)
endif
endwhile
* 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 = concat('<?xml version="1.0" encoding="UTF8"?> <grammar
version="1.0" xml:lang="', $srLanguage, '" mode="voice"
root="start"> <rule id="start" scope="public"> <one-of>')
$GrmEnd = '</one-of> </rule> </grammar>'
$GrmWord = ' <item>%s</item> '
* 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