我正在尝试编写一个 Alexa intent ,该 intent 将计算用户用西类牙语给出的英文号码。我可以让 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'
}
关于node.js - 使用 Alexa 计数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59439985/