我正在尝试在整个通话期间重复播放要循环播放的 SAY 消息。
目前它有效。如何获得要播放的消息,暂停 2 秒。
这是一个示例代码:
<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>
Run Code Online (Sandbox Code Playgroud)
twilio 文档提到在 SAY 之外使用它。
https://www.twilio.com/docs/api/twiml/say
“如果您想插入一个长时间的停顿,请尝试使用<Pause>动词。<Pause>应该放在<Say>标签外,而不是嵌套在标签内。”
但是在当前的实现中,永远不会达到这个暂停。
有人可以指导我吗。
编辑:尝试使用重定向来重复一条消息,但一旦接听电话就会在 2 秒内掉线。添加暂停不是这样,重定向是,如果这有什么问题,有人可以指导我吗?
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;
}
Run Code Online (Sandbox Code Playgroud)
Twilio 开发人员布道者在这里。
您实际上可以使用<Redirect>Twilio 中的动词来循环 a<Say>和 a <Pause>。你可以这样使用它:
/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>
Run Code Online (Sandbox Code Playgroud)
如果这有帮助,请告诉我。