c# - Twilio语音识别无法在c#中记录语音结果
问题描述
我正在尝试使用 Twilio 可编程语音编写一个应用程序,以便能够从客户那里收集语音和数字。我的代码正在获取数字但没有响应语音结果。顺便说一句,在最新版本的 Twilio 中,'gather' 的'input' 参数不允许将“dmfs speech”字符串放在一起使用这两个选项,因为它只接受带有 Dtmf 和 Speech by 的 [InputEnums] 列表定义。如果有人可以帮助我找出我做错了什么,这是我的代码示例:
public List<InputEnum> inputEnum = new List<InputEnum>() {InputEnum.Speech , InputEnum.Dtmf}; // creating a list with Dtmf and Speech options
var gather = new Gather(input: inputEnum, action: new Uri(baseUri,"IVR/MainMenu"), hints: "returning customer , agent", timeout: 4, numDigits: 1);
gather.Say("If you are a returning customer and would like to place your last order, say returning customer or press 1." );
gather.Say("To speak to an agent, say agent or press 2");
_response.Append(gather);
return new TwiMLResult(_response.ToString());
}
[HttpPost]
public ActionResult MainMenu(string digits)
{
if ((digits == "1") || ( digits == "returning customer"))
{
_response.Say("Please hold while we pull up your information.");
_response.Pause(6);
var gather = new Gather(input: inputEnum, hints: "last order, place last order , agent", timeout: 4, action: new Uri(baseUri, "IVR/ReturnInstructions"), numDigits: 1);
gather.Say("If you would like us to read your last order to you, say last order or press 1");
gather.Say("To place your last order, say place last order or press 2");
gather.Say("To speak to an agent, say agent or press 0");
_response.Append(gather);
return new TwiMLResult(_response.ToString());
}
解决方案
我尝试了不同的方法,结果我必须将另一个专门用于语音结果的参数传递给我的操作,并确保将其转换为小写,否则它将始终返回 false 到字符串比较。这是我的 MainMenu ActionResult 的示例:
public ActionResult MainMenu(string digits = null, string speechresult = null)
{
if ((digits == "1") || (speechresult != null && speechresult.ToLower() == "returning customer"))
{
_response.Say("Please hold while we pull up your information.");
_response.Pause(6);
gather.Say("If you would like us to read your last order to you, say last order or press 1");
return new TwiMLResult(_response.ToString());
}
else if ((digits == "0") || (speechresult != null && speechresult.ToLower() == "agent"))
{
return connectToAnAgent();
}
return connectToAnAgent();
}
推荐阅读
- postgresql - Postgresq:子查询和数学
- java - 带有 SimpleAsyncTaskExecutor 的 Spring Batch 未保存到 DB
- postgresql - TimesclaleDB 中的空间分区和维度是什么
- node.js - React 状态挂钩适用于开发,但不适用于构建(生产)
- angular - 如何将 Markdown-it 添加到 Angular 8
- angular - NG发球需要很长时间才能开始
- swift - Swift 5.1 - 是否有一种干净的方法来处理子字符串/模式匹配的位置
- r - 将 NA 分配到 R 中的数据帧中
- amazon-web-services - 如何将云端 url 重定向到主域?
- javascript - TypeError:projects.map 不是函数(React)