0
votes

I am using the Twilio SDK (Java) to make a call to a U.S. mobile phone number and when the user answers the phone I want to have a TwiML file say a message and get the digit the user presses. But Twilio seems to completely ignore the Gather and Pause verbs in the TwiML. Twilio dials the phone number as expected but when the user answers the call, Twilio recites all the Say verbs in the TwiML below, the Gather and Pause have no effect and Twilio disconnects the call. Also although the Say verbs specify a woman's voice Twilio uses a male voice for these.

Is there a way to get the Gather and Pause working in the TwiML below? Is there a way to make the Say statements use a woman's voice? Note that I am using a trial Twilio account.

<?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>
1
If you're trying to debug, I suggest that you do one thing at a time. Put a 'Say' first and get it working with the voice you want. Move onto 'Pause' and get it working and then fix the 'Gather'.Alex Baban
I'm not sure why your voice change isn't working, though I would suggest using the voice "alice" rather than "woman" as it is a more up to date voice. Also, I would recommend nesting all of your <Say>s and <Pause>s inside the <Gather> so that users can press as soon as they know what they want.philnash

1 Answers

1
votes

I grabbed your TwiML from above and dusted off my Twilio-Java setup (thanks)!

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());
    }
}

All that Servlet code translates to the following 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>

Hope you'll find this helps. If you're curious for even more examples of using the <Gather> verb with Java, check out the tutorials.