node.js - 用 Alexa 数数
问题描述
我正在尝试编写一个 Alexa 意图,该意图将计算到用户给定的西班牙语英文数字。我可以让 Alexa 用西班牙语说出正确的数字,但我在试图弄清楚如何让她说出多个数字时遇到了麻烦。
这是我的代码:
const numbers = {
'Zero':'Cero',
'One': 'Uno',
'Two' : 'Dos',
'Three': 'Tres'
}
const CountUpToIntentHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === 'IntentRequest'
&& handlerInput.requestEnvelope.request.intent.name === 'CountUpToIntent';
},
handle(handlerInput) {
const numberToCountTo =
handlerInput.requestEnvelope.request.intent.slots.numberr.resolutions.resolutionsPerAuthority[0].values[0].value.name;
const speechOutput = [];
while (allTheNumbers !== 'Zero') {
var allTheNumbers = numbers[numberToCountTo];
speechOutput.push(allTheNumbers--);
}
return handlerInput.responseBuilder
.speak(speechOutput)
.reprompt(speechOutput)
.getResponse();
}
};
有人可以帮我正确地编写循环,所以 Alexa 说的不止一个数字吗?
谢谢
解决方案
我认为你做错了,你在比较allTheNumbers
变量时甚至没有声明它。您可以通过使用号码槽来解决此问题的一种方法,当用户说出某个号码时,然后用给定的号码循环它。并检查给定的数字进行比较,这样更容易。
const numbers = {
'1':'Cero',
'2':'Uno',
'3':'Dos',
'4':'Tres'
}
推荐阅读
- flutter - 有什么方法可以更改图像选择器的文件名?
- c - 当一个程序同时包含套接字服务器和客户端时,我们应该注意什么?
- react-native - 使用 mobx 或 redux 还是使用存储库模式和持久本地存储领域或 sqlite?
- android - 'onRequestPermissionsResult' 不覆盖任何内容
- winapi - winapi中STR的数据类型是什么?
- flutter - 在设备浏览器中打开 PDF 链接 - Flutter
- django - Django 模型表单未保存到数据库
- flutter - Flutter ValueListenableBuilder 结果更新状态以显示/隐藏小部件
- r - R:数据框操作
- reactjs - 拒绝从“chunk.js”执行脚本,因为它的 MIME 类型(“text/html”)不可执行,并且启用了严格的 MIME 类型检查