我正在使用Twilio SDK(Java)拨打美国移动电话号码,当用户接听电话时,我想让TwiML文件说出一条消息并获取用户按下的数字。但Twilio似乎完全忽略了TwiML中的 Gather 和 Pause 动词。 Twilio按预期拨打电话号码,但当用户接听电话时,Twilio会在下面的TwiML中朗读所有 Say 动词, Gather 和 Pause 没有效果,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>
答案 0 :(得分: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>
希望你会发现这有帮助。如果您对使用<Gather>
动词和Java check out the tutorials的更多示例感到好奇。