Twilio how to add a PAUSE within a SAY Loop

时间秒杀一切 提交于 2021-02-10 12:49:47

问题


I am trying to repeat a SAY message to be played in loop for the entire call duration.

Currently it works. How can I get the message to be played, with a PAUSE of 2 seconds.

This is a sample code:

<Response>
<Gather>
    <Say voice="woman" loop="0">This is my SAY message, which is repeating. How to repeat this with a pause of 2 seconds.</Say>
    <Pause length="5"></Pause>
</Gather>
</Response>

The twilio documentation mention to use it outside a SAY.

https://www.twilio.com/docs/api/twiml/say "If you want to insert a long pause, try using the <Pause> verb. <Pause> should be placed outside <Say> tags, not nested inside them."

But with the current implementation, this pause will be never reached.

Can someone guide me on this.

Edit: Trying to use redirect to repeat a message but call gets dropped within 2 seconds once answered. Adding pause is not casuing this, the redirect is, Can someone guide me if there is anything wrong in this?

public TwiMLResponse myMethod(){
    TwiMLResponse twimlResponse = new TwiMLResponse();
    Gather gather = new Gather();
    gather.setFinishOnKey("any digit");
    gather.setNumDigits(1);
    gather.setAction("myendpoint");
    Say say = new Say("This message needs to repeat with a pause");
    //Pause pause = new Pause();
    //pause.setLength(2);
    Redirect redirect = new Redirect("myendpoint");

   try {
        gather.append(say);
        //gather.append(pause);
        gather.append(redirect);
        twimlResponse.append(gather);
    } catch (TwiMLException e) {
        LOGGER.warn("exception " + e);
    }
return twimlResponse;
}

回答1:


Twilio developer evangelist here.

You can actually use the <Redirect> verb in Twilio to loop a <Say> and a <Pause>. You could use it like this:

/gather.xml

<Response>
  <Gather>
    <Say voice="woman">This is my SAY message, which is repeating. How to repeat this with a pause of 2 seconds.</Say>
    <Pause length="2"></Pause>
  </Gather>
  <Redirect>/gather.xml</Redirect>
</Response>

Let me know if this helps.




回答2:


From the documentation for <say>

Punctuation, such as commas and periods will be interpreted as natural pauses by the speech engine.

So you can alter your say like this:

<Say voice="woman" loop="0">This is my SAY message, which is repeating. How to repeat this with a pause of 2 seconds, , ,</Say>


来源:https://stackoverflow.com/questions/29906937/twilio-how-to-add-a-pause-within-a-say-loop

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!