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

edited July 2021 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:

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

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"""
  <Say>Hello world</Say>
    <Stream url="wss://{same url as above}.ngrok.io/"></Stream>
  <Pause length="360"/>
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


  • 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
    edited July 2021

    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

If this is an emergency, please contact Twilio Support. This is not an official Support channel. https://support.twilio.com/
Have an urgent question?
Please contact Twilio Support. This is not an official Support channel.
Contact Support