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

4

5

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 ?

Joaquin answered 21/6, 2018 at 21:34 Comment(0)
F
8

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);
};
Fung answered 1/10, 2018 at 19:42 Comment(3)
NOTE This only works with the traditional voices, not polly.Lilalilac
using this method Robot says "dot" that is not fine.Dy
@NomanJaved, as per other answers, make sure you're using traditional voices. It won't work for "[Polly]" voices.Fung
I
10

Got this from Twilio support

The spaced out periods only works for the legacy voices (man, woman, alice).

If you're using the new Polly voices, you need to embed SSML in the Say text area, such as:

<speak>Hello. <break time="5s"/> Goodbye.</speak>

Worked fine for me.

Iffy answered 21/11, 2018 at 9:44 Comment(3)
I have confirmed that this does work in Studio flow. Just paste the SSML code in the "Say text area as indicated. In my case I was using Polly voices, don't know if that matters or not..Hebrew
You have to add the full <speak> xxxx </speak> tags.Lilalilac
You can see all options here: twilio.com/docs/voice/twiml/say/text-speechExhort
F
8

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);
};
Fung answered 1/10, 2018 at 19:42 Comment(3)
NOTE This only works with the traditional voices, not polly.Lilalilac
using this method Robot says "dot" that is not fine.Dy
@NomanJaved, as per other answers, make sure you're using traditional voices. It won't work for "[Polly]" voices.Fung
S
7

Really somebody at Twilio should create a PAUSE widget for Studio.

Until then if you're happy using an ugly hack... here it is:

Since you can add a function widget in the flow, create a Twilio "Runtime Function" (I called it "Pause")


    exports.handler = function(context, event, callback) {

        const duration = event.duration || 1500; 

        setTimeout(
            function() {
                // console.log(duration);
                callback();          
            } , duration);

    };

then, replace one "Say" widget with "Say" widget + "Pause" function widget + "Say" widget.

When you add the "Pause" widget configure it with parameters, add a duration parameter with a value that is no more than about 3000 to 4000 (I don't know exactly how to explain why but functions will 'runtime timeout' if the function takes more than 5 seconds to execute).

When you add parameters, make sure they are in fact added..., I had some trouble until I figured out that you need to click on "Add Parameter" link after you fill the "Key", "Value" fields, instead I was clicking on the big "Save" button.

Since you are looking for a 10 seconds pause, you might try to cascade 3 "Pause" widgets with duration parameter (3000, 3000, 4000), between your "Say" widgets.

I've tested this and I was able to make a pause between 2 "Say" widgets of 7 seconds by inserting one 3000 pause and one 4000 pause functions.

I hope it helps.

Shirtwaist answered 25/6, 2018 at 20:53 Comment(0)
B
0

As a follow-up to Alex's answer and for anyone looking at this now, the timeout has been increased in Twilio (as of Sept 2019) from 5 sec to 10 sec:

https://www.twilio.com/changelog/twilio-functions-increased-timeout

Blanco answered 8/2, 2021 at 16:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.