如何接收字节音频数据并将其发送回 Twilio? [英] How to receive and send back bytes audio data to Twilio?

查看:24
本文介绍了如何接收字节音频数据并将其发送回 Twilio?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在从事一个 Twilio 项目,我已经使用本指南设置了所有内容:StreamTwiML

I have been working on a Twilio project and i have set everything up using this guide: Stream TwiML

我已经在 Alan 的帮助下解决了一个常见问题 答案

i have already resolved a common issue with the help of Alan here Answer

我无法发回我正在使用的已处理字节.

I'm unable to send back the processed bytes I'm using.

ws.send(bytes)
ws.receive()

我认为这两种方法是使用 Web 套接字来回发送和接收数据所必需的.但是我从 twilio 接收到一个恒定的数据流.

These two methods i assume are required to send and receive back and forth data using the web socket. But im receving a constant data stream from twilio.

那就是:<代码>b'\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xf

这没有任何意义.该指南官方说您可以从实时调用中获取字节然后发送它们.因此,假设我接收字节并使用我的自定义逻辑处理它们,可能将其存储在某处.我的处理以字节为单位输出相同的 PCM/16Bit Mono 音频数据.我认为 twilio 也会向我发送原始字节,因为它在文档中说它给出了原始字节(我认为它没有任何类型的编码).所以我想要的只是接收从调用者发送到 twilio 的音频数据,以接收字节并将字节发送到我之前在 Flask 中设置的端点来处理,然后我可以稍微处理它并将 PCM 字节返回给它可以在呼叫方播放.

Which does not makes any sense. The guide officially says you can get bytes from real time call and then send them. So let's say i receive bytes and process them using my custom logic maybe storing it somewhere. My processing outputs the same PCM/16Bit Mono audio data in bytes. Which i think twilio is also send me raw bytes as it says in the documentation that it gives out raw bytes (which i assume are without any kind of encoding). So all i want here is to receive audio data sent from the caller to twilio to receive and send bytes to an endpoint which i have setup ed earlier in flask to handle and then i can process it a little bit and return PCM bytes to it which can be played back at the caller side.

我想要的只是呼叫者发送他的声音并得到处理并接收回,也许我们的声音也添加到其中.在这里如何处理字节并不重要,我的概念是向其中添加一些音频数据并发送回来.

All i want is to caller send his voice and gets processed and receives back maybe our voices added to it as well. It wont matter how the byte is treated here my concept is to add some audio data to it and send back.

但是由于 动词是新的,所以我无法找到如何正确处理字节并将它们发回.

But since verb is new so there's no where i can find how to properly handle the bytes and send them back.

如果有人能指出 twilio 期望在 web 套接字中返回什么作为音频数据,它可以在调用方播放,那就太好了.我应该对 twilio 有什么期待.但是因为在文档中它说有效载荷发送原始字节,所以我假设它是一个以字节为单位的普通 PCM 数据.

It would be nice if someone can point me what twilio expects in the web socket return as a audio data that it can be played on the caller side. And what i should be expecting from twilio. But since in the documentation it says that payload sends out raw bytes so i assume its a plain PCM data in bytes.

请告诉我,以便我可以从 twilio 接收字节并将它们发回,这些字节可以在调用方播放,并且可以从这里听到调用方的声音.我也设置了播放器和客户端来播放字节数据,但是由于数据是简单的或递归的,我无法播放它.

Please let me know so i can receive bytes from twilio and send them back which can be played at the caller side and caller's voice can be heard from here.I have players and clients setup ed as well to play the byte data but since the data is plain or recursive i cannot play it.

提前致谢.

推荐答案

Twilio 开发人员布道者在这里.

Twilio developer evangelist here.

据我所知,Media Streams 仅支持以一种方式将数据流式传输到您的服务器.您无法通过 websocket 连接将媒体流回 Twilio.

As far as I know right now Media Streams only supports streaming the data to your server one way. You cannot stream media back to Twilio via the websocket connection.

如果您能够将要发送回的字节保存为音频文件,则可以通过 将呼叫重定向到一些s 音频到通话中.

If you were able to save the bytes you want to send back as an audio file, you can play it back to the call by redirecting the call to some TwiML that <Play>s the audio to the call.

让我知道这是否有帮助.

Let me know if that helps at all.

这篇关于如何接收字节音频数据并将其发送回 Twilio?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆