Search code examples
twiliotwilio-functionstwilio-studio

How can i add pause to Twilio studio Say/Play widget


I have a say widget

> "Hello ... Thanks"

I've tried add a pause string like twilML to that element like so

> "Hello  <Pause length="10"/> ... Thanks"

but it just speaks out the Pause length="10" section

how can i add a pause to a Say/Play widget ?


Solution

  • According to Twilio documentation on widgets, pauses can be added by placing space separated periods, where 15 of these is equivalent to 1 second delay.

    So, the following Text to say would have a 1 second delay between sentences:

    Hello, John!
     . . . . . . . . . . . . . . .
    Today is a very nice day.
    

    EDIT: this will only work for non-[Polly] voices (Alice, Man, Woman - options in "Message Voice" field in the widget's configuration).

    Another alternative to it is using Twilio Functions and adding a Run Function widget to the Flow. For more instructions, follow Twilio's instructions for "Add Delay" (specifically mentioning for using in Studio Flow.

    // Description
    // Add a delay, useful for using with Twilio Studio Run Function Widget
    
    exports.handler = function (context, event, callback) {
      // Function can run up to 10 seconds (value of delay is milliseconds)
    
      // Pass in delay as a URL query parameter
      // Example: https://x.x.x.x/<path>?delay=5000
      let delayInMs = event.delay || 5000;
    
      let timerUp = () => {
        return callback(null, `Timer Up: ${delayInMs}ms`);
      };
    
      setTimeout(timerUp, delayInMs);
    };