Twilio的语音请求参数 [英] Twilio's request parameter for speech
问题描述
The documentation for the <Gather>
tag (Python) says that:
如果您选择从呼叫者那里收集数字,Twilio的请求将您的应用程序将包含一个数字参数,其中包含您的呼叫方在期间输入的电话号码.
If you chose to gather digits from the caller, Twilio's request to your application will include a Digits parameter containing which numbers your caller entered during the .
但是如果选择收集语音以能够根据用户发送的语音来分支呼叫逻辑,那么我什么地方都找不到参数.
But I can't find anywhere what is the parameter if the choice is to gather speech to be able to branch the call logic based on the speech sent by the user.
我尝试了语音和语音,但是没有用.
I tried Speech and speech, but didn't work.
我的代码:
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(Digits)尝试了完全相同的代码,并且工作正常,我的问题是语音:
I already tried the exact same code with dtmf (Digits) and worked fine, my problem is with speech:
用户发言后,程序将循环回第一个 gather.say
,就像没有输入任何内容一样.
After the user speech his response the program will loop back to the first gather.say
as if no input was made.
推荐答案
[SpeechResult]是您要查找的包含抄录文本的返回值.
[SpeechResult] is the return value you are looking for which contains the transcribed text.
Twilio还返回[Confidence],其得分可能在0到1之间(根据我的经验,该得分为小数点后8位).
Twilio also returns [Confidence] with a score between 0 and 1 (to 8 decimal places in my experience) for the likely indicated accuracy of the transcription.
这篇关于Twilio的语音请求参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!