How to receive and send back bytes audio data to Twilio?

梦想的初衷 提交于 2020-01-05 05:10:39

问题


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

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()

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.

That's: 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

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.

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.

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.

Thanks in advance.


回答1:


Twilio developer evangelist here.

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.

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.



来源:https://stackoverflow.com/questions/58803813/how-to-receive-and-send-back-bytes-audio-data-to-twilio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!