【问题标题】:TwiML: verbs Gather and Pause have no effectTwiML:动词 Gather 和 Pause 无效
【发布时间】:2016-06-10 19:04:11
【问题描述】:

我正在使用 Twilio SDK (Java) 拨打美国手机号码,当用户接听电话时,我希望 TwiML 文件说出一条消息并获取用户按下的数字。但是 Twilio 似乎完全忽略了 TwiML 中的 GatherPause 动词。 Twilio 按预期拨打电话号码,但当用户接听电话时,Twilio 会背诵下面 TwiML 中的所有 Say 动词、GatherPause 没有任何效果,Twilio 会断开呼叫。此外,虽然 Say 动词指定了女性的声音,但 Twilio 使用男性声音来表示这些。

有没有办法让 GatherPause 在下面的 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>

【问题讨论】:

  • 如果您尝试调试,我建议您一次只做一件事。先放一个“说”,让它与你想要的声音一起工作。进入“暂停”并让它工作,然后修复“收集”。
  • 我不知道为什么你的声音改变不起作用,但我建议使用声音“alice”而不是“woman”,因为它是一种更新的声音。另外,我建议您将所有&lt;Say&gt;s 和&lt;Pause&gt;s 嵌套在&lt;Gather&gt; 中,这样用户就可以在知道自己想要什么后立即按下。

标签: twilio twilio-twiml


【解决方案1】:

我从上面抓住了你的 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 中使用 &lt;Gather&gt; 动词的示例,请查看 check out the tutorials

【讨论】:

  • 谢谢,但我知道这种在 Java 代码中构建 TwiML 的方式。维护起来既麻烦又痛苦。所以我更愿意将 TwiML 托管在我的服务器上。
  • 酷,只是想我会把这两个都留给上下文。希望它能够满足您的需求。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-07-01
  • 2012-07-25
相关资源
最近更新 更多