0
votes
import com.twilio.twiml.voice.Gather;
import com.twilio.twiml.VoiceResponse;
import com.twilio.twiml.voice.Say;
import com.twilio.twiml.TwiMLException;

public class Example {
public static void main(String[] args) {
    Say say = new Say
        .Builder("Welcome to Twilio, please tell us why you're calling").build();
    Gather gather = new Gather.Builder().input("speech")
        .action("/completed").say(say).build();
    VoiceResponse response = new VoiceResponse.Builder().gather(gather)
        .build();

    try {
        System.out.println(response.toXml());
    } catch (TwiMLException e) {
        e.printStackTrace();
    }
}

}

In the above code i want to know the funnction of action method.what is the use of "/completed" inside the action method.

in the twilio doc it says some thing like this

"This TwiML creates a with speech. When Twilio executes this TwiML the application will prompt the user and accept speech for up to 60 seconds. Once the caller stops speaking for five seconds, Twilio will post her transcribed speech to the action url."

I got the above code from the below link

https://www.twilio.com/docs/voice/twiml/gather

1

1 Answers

0
votes

hey i found the answer.

we can give any public url and replace "/completed".

it means once the speaker finished speaking, twilio will send a post request to that url. that post request body contain what twilio catched from the speaker

here is an example.

Gather gather = new Gather.Builder().input(Gather.Input.SPEECH).timeout(10).action("http://0838a6b6.ngrok.io/asr/test").speechTimeout("auto").say(say).language(Gather.Language.EN_US).build();

here http://0838a6b6.ngrok.io/asr/test = localhost:1234/asr/test

you can download ngrok from here

it will give you a public url to a specific port on your server.

hope this helpful. Thanks