Twilio 语音识别 <gather>?

Twilio speech recognition <gather>?

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

}

在上面的代码中我想知道action的功能method.what是在action方法中使用“/completed”。

在 twilio 文档中它是这样说的

"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."

我从下面得到上面的代码link

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

嘿,我找到了答案。

我们可以给出任何 public url 并替换“/completed”。

这意味着一旦发言者结束发言,twilio 将向 url 发送 post 请求。 post 请求正文包含 twilio 从演讲者那里捕获的内容

这里有一个例子。

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

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

您可以从 here

下载 ngrok

它会给你一个 public url 到你服务器上的特定端口。

希望这对您有所帮助。 谢谢