【发布时间】:2021-09-17 17:00:26
【问题描述】:
我正在开发一个使用 twilio 媒体流 (Google STT) 的语音机器人,它处理文本并使用 TwiML Say Object 将响应返回给用户。 我正在使用用户开始呼叫后触发的端点(状态呼叫正在响铃):
@app.route("/twilio_call", methods=['POST'])
def voice(request):
"""Respond to incoming phone calls with a greet message"""
call_status = request.form.get("CallStatus")
if call_status == "ringing":
voice_respond = VoiceResponse()
voice_respond.say("hello! how can I help!", voice='women')
return response.text(str(voice_response), content_type="text/xml")
这条消息传递给用户后,我想用媒体流直接触发 websocket 服务器。
@app.websockets('/media')
def transcribe_media(request, ws):
while True:
message = ws.recv()
if message is None:
continue
data = json.loads(message)
if data['event'] == "media":
....
#here I'm sending data to google and getting the transcription back
我无法像在文档中那样修改正在进行的通话:https://www.twilio.com/docs/voice/tutorials/how-to-modify-calls-in-progress-python
我已经尝试过:
client = Client(ACCOUNT_SID, AUTH_TOKEN)
call = client.calls(conversation_id).update(
twiml='<Response><Say voice="woman" language="de-DE">' + msg_text + '</Say></Response>')
但是我收到一个错误,状态调用不在进行中(它正在“响铃)..
我也尝试过使用 TwiML"STREAM" 对象,但是当它与 TwiML "Say" 对象一起使用时它没有启动服务器(当我只通过 STREAM 时它会触发服务器):
voice_response = VoiceResponse()
start = Start()
start.stream(url='wss://<NGROK_IP>.ngrok.io/webhooks/twilio_voice/media')
voice_response.say("Hello, how can I help?", language="en-GB")
voice_response.append(start)
response.text(str(voice_response), content_type="text/xml")
有人知道我该如何解决这个问题吗? 将 Twiml"Say" 对象传递给用户后如何触发 websocket 服务器?
【问题讨论】:
-
请修剪您的代码,以便更容易找到您的问题。请按照以下指南创建minimal reproducible example。
标签: python twilio twilio-api twilio-twiml