首页 > 解决方案 > Twilio/Flask - 将调用者的语音存储到字符串变量

问题描述

我的目标是在 Twilio 上支付一条简单的消息,该消息可以捕获来电者的回复。根据回复将呼叫者发送到下一个选项。我的挑战:如何将呼叫者的语音转换为文本?下面的示例是演示这将起作用的代码:

from flask import Flask, request, redirect
from twilio.twiml.voice_response import VoiceResponse, Gather, Say
from datetime import datetime
import time

app = Flask(__name__)

@app.route("/test1", methods=['GET', 'POST'])
def test1():
    response = VoiceResponse()
    gather = Gather(input='speech',timeout=3,hints='cat, numbers, chuck')
    gather.say('Welcome to the fact hotline. Say cat numbers or chuck')
    response.append(gather)
    resp = VoiceResponse()
    resp.say('you said' + str(response))
    print(str(response))
    return str(response)

if __name__ == "__main__":
    app.run(debug=True)

结果是:

<?xml version="1.0" encoding="UTF-8"?><Response><Gather hints= "cat, numbers, chuck" input="speech" timeout=3><Say>Welcome to the fact hotline. Say cat numbers or chuck</Say></Gather></Response>

如果我说“chuck”,我想要一个变量 =“chuck”。有人可以提供指导吗?

标签: pythonflasktwilio

解决方案


推荐阅读