Cann't send back data using websocket for Twilio call

47 views Asked by At

I've been working on Twilio project and have set up everything like in this tutorial: link.

I receive bytes using "ws.receive()", but I have trouble on the stage of sending bytes of voice back.

For this I used this function:

ws.send(bytes)

Also I saw the post on StackOverflow, that says "Media Streams only supports streaming the data to your server one way. You cannot stream media back to Twilio via the websocket connection."(link). But this post was 4 years before the project, I mentioned earlier was posted on "medium.com".

I'm interested is it actually possible to send data back using "ws.send()", because I didn't found better explanation why this might not work. If not so, please let me know how can I do this instead.

1

There are 1 answers

0
Daniel O. On

Twilio Support Engineer here. It's possible to send data back if the stream is setup as a bi-directional media stream using the noun. For example:

<?xml version="1.0" encoding="UTF-8"?>
<Response>
   <Connect>
       <Stream url="wss://mystream.ngrok.io/audiostream" />
   </Connect>
</Response>

The only support events are Media Message and Mark Message. When sending media, you need to ensure that you are sending audio that is encoded in mulaw and that does not contain any header information.