首页 > 解决方案 > 如何在系统说话时阻止用户对 Twilio 的语音输入?

问题描述

如何在系统说话时阻止用户对 Twilio 的语音输入?我有一个<Say> Some long text</Say>之后应该有来自用户的语音输入。但是,当系统正在阅读长文本时用户说话时,阅读将被中断。我需要用户听完文本,然后才准备好进行语音输入。

可以在 Twilio 中进行吗?

这是我发回的 XML 响应:

`<Response>
  <Gather input="speech" action="MyControllername/MyMethodName" speechTimeout="auto">
    <Say>Here is my very long confidential text</Say>
  </Gather>
  <Redirect>/MyControllername/IncorrectOrNoInputMethod</Redirect>
</Response>
`

这是代码:

`public async Task<TwiMLResult> MyMethodName()
        {
            var response = new VoiceResponse();
            var message = await _logic.GetMyLongText(); // This test I get from BL, it is an async method
            var gather = new Gather(new [] {Gather.InputEnum.Speech}.ToList(), Url.ActionUri(nameof(AnotherMethodName), ControllerName), speechTimeout: "auto");
            gather.Append(new Say(message));
            response.Append(gather);
            response.Redirect(Url.ActionUri(nameof(IncorrectOrNoInputMethod), ControllerName));
            return TwilioResultFrom(response);
}`

标签: twilio

解决方案


Twilio 布道者在这里。

你需要让 Say 动词出现在 Gather 之前:

<Response>
  <Say>Here is my very long confidential text</Say>
  <Gather input="speech" action="MyControllername/MyMethodName" speechTimeout="auto">
  </Gather>
  <Redirect>/MyControllername/IncorrectOrNoInputMethod</Redirect>
</Response>

因此,在 C# 中,您只需Say直接在response对象诗句上调用该方法,并将其附加到gather

public async Task<TwiMLResult> MyMethodName()
{
    var response = new VoiceResponse();
    var message = await _logic.GetMyLongText(); // This test I get from BL, it is an async method
    response.Say(message);
    var gather = new Gather(new [] {Gather.InputEnum.Speech}.ToList(), Url.ActionUri(nameof(AnotherMethodName), ControllerName), speechTimeout: "auto");
    response.Append(gather);
    response.Redirect(Url.ActionUri(nameof(IncorrectOrNoInputMethod), ControllerName));
    return TwilioResultFrom(response);
}

希望有帮助。


推荐阅读