Twilio query parameter for speech

The documentation for the tag <Gather>(Python) says that:

If you decide to collect numbers from the caller, the Twilio request for your application will include a Digits parameter containing the numbers of your caller entered during.

But I can not find anywhere what is the parameter, if the choice is to collect the speech, in order to be able to branch out the logic of the call based on the speech sent by the user.

I tried Speech and Speech , but did not work.

My code is:

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)

I already tried the same code with dtmf (Digits) and worked fine, my problem with speech:

, , gather.say, .

+4
2

[SpeechResult] - , .

Twilio [] 0 1 ( 8 ) .

+2

SpeechResult not 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

+2

Source: https://habr.com/ru/post/1680071/


All Articles