首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Twilio的语音请求参数

Twilio的语音请求参数
EN

Stack Overflow用户
提问于 2017-06-25 16:15:28
回答 2查看 689关注 0票数 4

tag (Python)说:

如果您选择从调用方收集数字,Twilio对您的应用程序的请求将包括一个数字参数,其中包含调用方在调用期间输入的数字。

但是我在任何地方都找不到参数,如果选择是收集语音,以便能够根据用户发送的语音来分支调用逻辑。

我试过Speechspeech,但没有成功。

我的代码:

代码语言:javascript
运行
复制
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,就好像没有输入一样。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2017-06-25 17:19:15

SpeechResult是您正在寻找的包含转录文本的返回值。

Twilio还返回信心,分数在0到1之间(在我的经验中是小数点到8位),以保证转录的准确性。

票数 2
EN

Stack Overflow用户

发布于 2017-06-25 16:44:03

正确的参数名是SpeechResult,而不是Speech

代码语言:javascript
运行
复制
   @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

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44748229

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档