如果您选择从调用方收集数字,Twilio对您的应用程序的请求将包括一个数字参数,其中包含调用方在调用期间输入的数字。
但是我在任何地方都找不到参数,如果选择是收集语音,以便能够根据用户发送的语音来分支调用逻辑。
我试过Speech和speech,但没有成功。
我的代码:
from flask import Flask, request
from TwilioPhoneCall import app
from twilio.twiml.voice_response import VoiceResponse, Gather, Say
from twilio.twiml.messaging_response import MessagingResponse, Message
@app.route('/', methods=['GET', 'POST'])
def message():
resp = VoiceResponse()
gather = Gather(input='speech', timeout=3, hints='yes, no', action='/gather')
gather.say('Hi, do you wanna go out tonight?'+
' Answer yes or no.')
resp.append(gather)
resp.redirect('/')
return str(resp)
@app.route('/gather', methods=['GET', 'POST'])
def gather():
resp = VoiceResponse()
if 'Speech' in request.values:
choice = request.values['Speech']
if choice == 'yes':
resp.say('Yay! See you later!')
resp.sms('She replied yes!', to='myphonenumber')
return str(resp)
elif choice == 'no':
resp.say('Oh... Ok.')
resp.sms('She replied no.', to='myphonenumber')
return str(resp)
else:
resp.say('Sorry, but the options are yes or no.')
resp.redirect('/')
return str(resp)我已经尝试了与dtmf (数字)完全相同的代码,并且工作得很好,我的问题是在语音方面:
在用户讲话之后,他的响应将返回到第一个gather.say,就好像没有输入一样。
发布于 2017-06-25 17:19:15
SpeechResult是您正在寻找的包含转录文本的返回值。
Twilio还返回信心,分数在0到1之间(在我的经验中是小数点到8位),以保证转录的准确性。
发布于 2017-06-25 16:44:03
正确的参数名是SpeechResult,而不是Speech。
@app.route('/gather', methods=['GET', 'POST'])
def gather():
resp = VoiceResponse()
if 'SpeechResult' in request.values:
choice = request.values['SpeechResult']
if choice == 'Yes.':
resp.say('Yay! See you later!')
resp.sms('She replied yes!', to='myphonenumber')
return str(resp)
elif choice == 'No.':
resp.say('Oh... Ok.')
resp.sms('She replied no.', to='myphonenumber')
return str(resp)
else:
resp.say('Sorry, but the options are yes or no.')
resp.redirect('/')
return str(resp)Twilio博客:介绍语音识别 https://www.twilio.com/blog/2017/05/introducing-speech-recognition.html
https://stackoverflow.com/questions/44748229
复制相似问题