text
stringlengths
0
152
same => n,Set(step1count=0) ; Successful response; reset counters
same => n,Set(step2count=0)
same => n(step2),Set(step2count=$[${step2count} + 1])
same => n,GotoIf($[${step2count} > 2]?beginning) ; No response after 3 tries
; If the file doesn't exist, then don't ask whether to play it
same => n,GotoIf($[${STAT(f,/var/lib/asterisk/sounds/${which}.wav)} = 0]?recordonly)
same => n,Background(prompt-tolisten)
same => n(recordonly),Background(prompt-torecord)
same => n,WaitExten(10) ; Wait 10 seconds for a response
same => n,Goto(step2)
same => n(end),Playback(goodbye)
same => n,Hangup()
exten => 1,1,Set(step2count=0)
same => n,Background(/var/lib/asterisk/sounds/${which})
same => n,Goto(s,step2)
exten => 2,1,Set(step2count=0)
same => n,Playback(prompt-waitforbeep)
same => n,Record(${CHANNEL(uniqueid)}.wav)
same => n(listen),Playback(${CHANNEL(uniqueid)})
same => n,Set(step3count=0)
same => n,Read(saveornot,prompt-1tolisten-2tosave-3todiscard,1,,2,3)
same => n,GotoIf($["${saveornot}" = "1"]?listen)
same => n,GotoIf($["${saveornot}" = "2"]?saveit)
same => n,GotoIf($["${saveornot}" = "3"]?tossit)
same => n,Goto(listen)
same => n(tossit),System(rm -f /var/lib/asterisk/sounds/${CHANNEL(uniqueid)}.wav)
same => n,Goto(s,beginning)
same => n(saveit),Noop('Set' app used to shorten example)
same => n,Set(PromptToSave=/var/lib/asterisk/sounds/${CHANNEL(uniqueid)}.wav
same => n,Set(WhereToSave=/var/lib/asterisk/sounds/${which}.wav
same => n,System(mv -f ${PromptToSave} ${WhereToSave})
A Prompt-Recording IVR Function
|
295
same => n,Playback(prompt-saved)
same => n,Goto(s,beginning)
In this system, the name of the prompt is no longer descriptive; instead, it is a num‐
ber. This means that you can record a far greater variety of prompts using the same
mechanism, but the trade-off is that your prompts will no longer have descriptive
names.
If you want to test this, you’ll need to record the prompts this IVR function uses (it’s
kinda meta, but yup, our prompt creator needs prompts).
Drop this into your dialplan:
exten => 510,1,GoSub(subRecordPrompt,${EXTEN},1(prompt-tolisten)) ; press 1
exten => 511,1,GoSub(subRecordPrompt,${EXTEN},1(prompt-torecord)) ; press 2
exten => 512,1,GoSub(subRecordPrompt,${EXTEN},1(prompt-instructions)) ;3-digit (000 to 999)
exten => 513,1,GoSub(subRecordPrompt,${EXTEN},1(prompt-waitforbeep)) ; wait for beep
exten => 514,1,GoSub(subRecordPrompt,${EXTEN},1(prompt-1tolisten-2tosave-3todiscard))
exten => 515,1,GoSub(subRecordPrompt,${EXTEN},1(prompt-saved))
Then phone them one by one and record as required.
Once you’ve recorded the prompts your prompt recorder needs, you should be able
to test it out.
exten => *742,1,Noop(Prompts)
same => n,Goto(prompts,s,1)
same => n,Hangup()
From this point forward, you can record prompts using just a numeric identifier.
You’ll need a way to keep track of what prompt says what, but from a recording per‐
spective you shouldn’t need to write more dialplan every time you need a prompt.
Speech Recognition and Text-to-Speech
Although traditionally and still in most cases today, an IVR system presents prerecor‐
ded prompts to the caller and accepts input by way of the dialpad, it is also possible
to: a) generate prompts artificially, popularly known as text-to-speech; and b) accept
verbal inputs through a speech recognition engine.
While the concept of being able to have an intelligent conversation with a machine is
something sci-fi authors have been promising us for many long years, the actual sci‐
ence of this remains complex and error-prone. Despite their amazing capabilities,
computers are ill-suited to the task of appreciating the subtle nuances of human
speech.
Having said that, it should be noted that companies such as Google have achieved
amazing advances in both text-to-speech and speech recognition. There are now
APIs available that can do a remarkable job of making sense out of what is being said
to them. Google of course benefits from having a massive backend that can perform
296
|