以下是筆者看到的一個比較完整的示例,此示例支持了Asterisk,google ASR/TTS API接口。通過API調(diào)用返回的結(jié)果來實現(xiàn)呼叫的處理,F(xiàn)在和大家分享一下具體的處理流程:
首先,我們一下基于Google的語音識別的處理。首先需要安裝依賴支持包:
然后把speech-recog.agi的AGI文件拷貝到 /var/lib/asterisk/agi-bin/
拷貝進去以后,處理執(zhí)行權(quán)限,保證agi那個正常工作。此agi配置文件配置了API接口的調(diào)用機制。
使用語法:
agi(speech-recog.agi,[lang],[timeout],[intkey],[NOBEEP])
通過撥號規(guī)則的AGI接口調(diào)用語音識別和TTS數(shù)據(jù):
imple speech recognition
exten => 1234,1,Answer()
exten => 1234,n,agi(speech-recog.agi,en-US) //
exten => 1234,n,Verbose(1,The text you just said is: ${utterance})
exten => 1234,n,Verbose(1,The probability to be right is: ${confidence})
exten => 1234,n,Hangup()
;;Speech recognition demo:
exten => 1235,1,Answer()
exten => 1235,n,agi(googletts.agi,"Say something in English, when done press the pound key.",en)
exten => 1235,n(record),agi(speech-recog.agi,en-US)
exten => 1235,n,Verbose(1,Script returned: ${confidence} , ${utterance})
;Check the probability of a successful recognition:
exten => 1235,n(success),GotoIf($["${confidence}" > "0.8"]?playback:retry)
;Playback the text:
exten => 1235,n(playback),agi(googletts.agi,"The text you just said was…",en)
exten => 1235,n,agi(googletts.agi,"${utterance}",en)
exten => 1235,n,goto(end)
;Retry in case speech recognition wasn't successful:
exten => 1235,n(retry),agi(googletts.agi,"Can you please repeat more clearly?",en)
exten => 1235,n,goto(record)
exten => 1235,n(fail),agi(googletts.agi,"Failed to get speech data.",en)
exten => 1235,n(end),Hangup()
;;Voice dialing example
exten => 1236,1,Answer()
exten => 1236,n,agi(googletts.agi,"Please say the number you want to dial.",en)
exten => 1236,n(record),agi(speech-recog.agi,en-US)
exten => 1236,n,GotoIf($["${confidence}" > "0.8"]?success:retry)
exten => 1236,n(success),goto(${utterance},1)
exten => 1236,n(retry),agi(googletts.agi,"Can you please repeat?",en)
exten => 1236,n,goto(record)
以上是ASR的接口調(diào)用,用戶也可以使用TTS調(diào)用方式。當然,首先需要創(chuàng)建一個tts.agi 文件,拷貝此文件到agi默認路徑,執(zhí)行權(quán)限設置,保證其可執(zhí)行。
使用語法:
agi(googletts.agi,text,[language],[intkey])
TTS和asterisk的測試示例:
GoogleTTS Demo
exten => 1234,1,Answer()
;;Play mesage in English:
exten => 1234,n,agi(googletts.agi,"This is a simple google text to speech test in english.",en)
;;Play message in Spanish:
exten => 1234,n,agi(googletts.agi,"Esta es una simple prueba en espa?ol.",es)
;;Play message in Greek:
exten => 1234,n,agi(googletts.agi,"Αυτ? ε?ναι ?να απλ? τ?στ στα ελληνικ?.",el)
;;Play message in Japanese:
exten => 1234,n,agi(googletts.agi,"これは、日本の簡単なテストです。良い一日を。",ja)
;;Play message in simplified Chinese:
exten => 1234,n,agi(googletts.agi,"這是一個簡單的測試,在中國。有一個愉快的一天。",zh-CN)
;A simple dynamic IVR using GoogleTTS
[my_ivr]
exten => s,1,Answer()
exten => s,n,Set(TIMEOUT(digit)=5)
exten => s,n,agi(googletts.agi,"Welcome to my small interactive voice response menu.",en)
;;Wait for digit:
exten => s,n(start),agi(googletts.agi,"Please dial a digit.",en,any)
exten => s,n,WaitExten()
;;PLayback the name of the digit and wait for another one:
exten => _X,1,agi(googletts.agi,"You just pressed ${EXTEN}. Try another one please.",en,any)
exten => _X,n,WaitExten()
exten => i,1,agi(googletts.agi,"Invalid extension.",en)
exten => i,n,goto(s,start)
exten => t,1,agi(googletts.agi,"Request timed out.",en)
exten => t,n,goto(s,start)
exten => h,1,Hangup()
以上示例是一個國外開發(fā)人員的開源代碼分享,筆者沒有測試,因為訪問Google還是有很多不方便的地方。開發(fā)人員也提供了語音合成的接口,支持微軟的翻譯工具來實現(xiàn),讀者可以進一步研究。讀者可以根據(jù)ASR和TTS的接口給的大概思路,利用我們國內(nèi)的ASR和TTS廠家(例如,百度,科大訊飛等)的API接口進行調(diào)整來實現(xiàn)ASR/TTS/IVR的流程處理。
參考資料以及源代碼下載:
http://zaf.github.io/asterisk-speech-recog/