我的目标是在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”。 有人可以提供指导吗?