我是Amazon Echo编程的新手 . 我正在使用Node.js并且我试图根据我的名字来回复不同的回复 .
例如,如果我说“David”或“James”或“Benjy”这个名字,Alexa应该只说“欢迎[和我说的名字]”,但如果我说“Jonathan”它应该说“Yay!Welcome home Jonathan” .
但当我说“乔纳森”时,它只是说“欢迎乔纳森” .
我一直在修改基本的alexa-skills-kit-color-expert Lambda并修改了该代码中的setColorInSession()函数 . 我已经重命名了函数setAndWelcomePerson() .
我试过了:
-
使用if语句来测试我的话语,并根据我的话语让Alexa回复
-
给出不同的话语例子,试图教Alexa区分一个名字和下一个名字 .
这似乎都不起作用 . 请告诉我我做错了什么,并提出修复建议 . 下面的一些代码:
我的Lambda代码中的setAndWelcomePerson()函数:
/**
* Sets the name of the person(s) and welcomes them.
*/
function setAndWelcomePerson(intent, session, callback) {
var cardTitle = intent.name;
var whoToGreetSlot = intent.slots.Person;
var repromptText = null;
var sessionAttributes = {};
var shouldEndSession = false;
var speechOutput = "";
if (whoToGreetSlot) {
var whoToGreet = whoToGreetSlot.value;
sessionAttributes = createWhoToGreetAttributes(whoToGreet);
if (whoToGreet === "Jonathan") {
speechOutput = "Yay! Welcome home " + whoToGreet + "!";
} else {
speechOutput = "Welcome " + whoToGreet + ".";
}
} else {
speechOutput = "I'm not sure who you want me to welcome. Please try again.";
}
callback(sessionAttributes,
buildSpeechletResponse(cardTitle, speechOutput, repromptText, shouldEndSession));
}
我的意图架构:
{
"intents": [
{
"intent": "WhoShouldBeGreeted",
"slots": [
{
"name": "Person",
"type": "LITERAL"
}
]
},
{
"intent": "AdditionalGreetingRequest",
"slots": []
}
]
}
我的样本话语:
WhoShouldBeGreeted {Sam and Cat|Person}
WhoShouldBeGreeted {Jonathan|Person}
WhoShouldBeGreeted {James|Person}
WhoShouldBeGreeted {Benji|Person}
WhoShouldBeGreeted welcome {Sam and Cat|Person}
WhoShouldBeGreeted welcome {Jonathan|Person}
WhoShouldBeGreeted welcome {James|Person}
WhoShouldBeGreeted welcome {Benji|Person}
谢谢您的帮助 .
1 回答
您正在使用“LITERAL”插槽类型 . (这是不鼓励的,但它仍然受到支持 . )这意味着你只是在识别一个单词 . 口语没有案例 . 但是Javascript中的===运算符区分大小写 . 如果你检查你的日志,我怀疑当你说“Jonathan”你得到的是“jonathan”,你的比赛就失败了 .
要解决此问题,您可以将比较更改为小写,或将运算符更改为不区分大小写的字符串比较(请参阅here) .
另一种方法是不使用LITERAL插槽类型,而是使用AMAZON.US_FIRST_NAME . 因为它知道它是一个名称,所以它返回大写 .