TwiML:动词 聚集和暂停不起作用



我正在使用Twilio SDK(Java)拨打美国手机号码,当用户接听电话时,我希望TwiML文件说一条消息并获取用户按下的数字。但 Twilio 似乎完全忽略了 TwiML 中的 GatherPause 动词。Twilio 按预期拨打电话号码,但当用户接听电话时,Twilio 会背诵下面的 TwiML 中的所有 Say 动词,"聚集"和"暂停"不起作用,Twilio 会断开呼叫。此外,尽管 Say 动词指定了女性的声音,但 Twilio 为这些动词使用了男性声音。

有没有办法让下面的 TwiML 中的收集和暂停工作?有没有办法让 Say 语句使用女性的声音?请注意,我使用的是试用版 Twilio 帐户。

<?xml version="1.0" encoding="UTF-8"?>
<Response>
    <Say voice="woman">This is a courtesy phone call from YourCompany.</Say>
    <Say voice="woman">Please press one to buy our products.</Say>
    <Say voice="woman">Press two to be removed from our list.</Say>
    <Pause length="5" />
    <Gather timeout="60" numDigits="1" method="POST" action="http://twimlets.com/echo?Twiml=%3CResponse%3E%3CSay%3EHi+there.%3C%2FSay%3E%3C%2FResponse%3E" >
        <Pause length="30" />
    </Gather>
    <Say voice="woman">Goodbye.</Say>
</Response>

我从上面抓住了你的TwiML,并掸掉了我的Twilio-Java设置(谢谢)!

package com.twilio;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import com.twilio.sdk.verbs.TwiMLResponse;
import com.twilio.sdk.verbs.TwiMLException;
import com.twilio.sdk.verbs.Say;
import com.twilio.sdk.verbs.Gather;
import com.twilio.sdk.verbs.Pause;

public class StackOverflow extends HttpServlet {
    public void service(HttpServletRequest request, HttpServletResponse response) throws IOException {
        TwiMLResponse twiml = new TwiMLResponse();

        Gather gather = new Gather();
        gather.setTimeout(60);
        gather.setNumDigits(1);
        gather.setMethod("POST");
        gather.setAction("http://twimlets.com/echo?Twiml=%3CResponse%3E%3CSay%3EHi+there.%3C%2FSay%3E%3C%2FResponse%3E");
        Say sayInGather1 = new Say("This is a courtesy phone call from YourCompany.");
        sayInGather1.setVoice("alice");
        Say sayInGather2 = new Say("Please press one to buy our products.");
        sayInGather2.setVoice("alice");
        Say sayInGather3 = new Say("Press two to be removed from our list.");
        sayInGather3.setVoice("alice");
        Pause hanging = new Pause();
        hanging.setLength(30);
        Say sayInGather4 = new Say("Goodbye.");
        sayInGather4.setVoice("alice");
        try{
            gather.append(sayInGather1);
            gather.append(sayInGather2);
            gather.append(sayInGather3);
            gather.append(hanging);
            gather.append(sayInGather4);
            twiml.append(gather);
        } catch (TwiMLException e) {
            e.printStackTrace();
        }
        response.setContentType("application/xml");
        response.getWriter().print(twiml.toXML());
    }
}

所有这些 Servlet 代码都转换为以下 XML:

<Response>
  <Gather timeout="60" numDigits="1" method="POST" action="http://twimlets.com/echo?Twiml=%3CResponse%3E%3CSay%3EHi+there.%3C%2FSay%3E%3C%2FResponse%3E">
    <Say voice="alice">This is a courtesy phone call from YourCompany.</Say>
    <Say voice="alice">Please press one to buy our products.</Say>
    <Say voice="alice">Press two to be removed from our list.</Say>
    <Pause length="30"/>
    <Say voice="alice">Goodbye.</Say>
  </Gather>
</Response>

希望这会有所帮助。如果您对在 Java 中使用 <Gather> 动词的更多示例感到好奇,请查看教程。

最新更新