[Solved] Is there a limit in updating the twiml?

ejsan
ejsan
edited July 20 in Voice

I'm trying to use the twilio's text-to-speech during a Media Streams call.

I get the audio stream of the phone call correctly, using this twiml at the beginning of the call:

<Response>  
  <Say>Base</Say>  
  <Start>  
    <Stream url="wss://{ngrok url here}.ngrok.io/"></Stream>
  </Start>
  <Pause length="360"/>
</Response>

During the call I can update the twiml only four times, then I simply stop receiving the stream. The websocket remains open but mute.

This is the update I send up to 4 times, some 10 seconds apart:

say_twiml = f"""
<Response>
  <Say>Hello world</Say>
  <Start>
    <Stream url="wss://{same url as above}.ngrok.io/"></Stream>
  </Start>
  <Pause length="360"/>
</Response>
"""
client.calls('call sid here').update(twiml=say_twiml)

I'm asking if there's a limit to the updates, or if I'm misusing the verb and if I should use another way to use the text-to-speech during a call instead

Best Answer

Answers

  • I think your issue here is that you don't need to send the <Start><Stream> parts of the TwiML when you make the updates. When you initially use <Start><Stream> the call audio is forked so that your websocket receives the audio, but TwiML can keep interacting with it too.

    Also, according to the docs:

    There are a maximum of 4 forked streams allowed per call. Each track, inbound or outbound, is a forked stream.

    In your case you are creating those 4 forks and then the 5th one you lose the audio.

    I would try removing <Start><Stream> from your TwiML updates and just include the <Say> and <Pause>.

  • ejsan
    ejsan
    edited July 20

    Everything works, thank you Pnash!

    I'm editing my previous answer. I already tried your solution, but I probably did something wrong, because now it works.

    Let me try to mark this question as solved, if I can

  • Yes, it works. Now the question should be marked as solved

Sign In or Register to comment.