- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试创建一个 Amazon Alexa Skills Kit 来执行某种自动化,这需要采用由字符串和数字 ( a-test12fish
) 组成的语音输入。
当我在 Alexa Skills Kit 中使用自定义插槽时,它不允许我用数字键入字符串。当我尝试输入 ask alexa, dangerZone find a-test12fish
时,我收到以下错误:
Error: Invalid text input. Text should begin with alphabets and should only contain alphabets, whitespaces, periods or apostrophes
最佳答案
这是一个解决方案。
您可能不想在 intent 模式中完成此操作。而是尝试使用 Node.js 创建自定义模式,将字母、数字和符号编译为单个响应。这是我对字母数字输入模式的演绎。请注意:我只是在回答您的问题时写了这篇文章,并没有在更大的技能中对其进行测试。话虽如此,我在 MODES
上取得了巨大的成功。当我有机会时,我肯定会用我自己的技能来实现这一点。
此代码背后的想法是您将用户插入一个单独的模式,该模式忽略除 NumberIntent
之外的所有 intent 。 , LetterIntent
, SymbolIntent
,以及一些帮助功能。用户快速输入他们的字母数字值,完成后激活 CompletedIntent。然后可以在您的技能的其他地方使用该字母数字值。如果您还没有使用过 Modes
请注意,在完成或退出时,您将被重定向回 LOBBYMODE
您可以在其中继续访问技能中的其他 intent 。
var lobbyHandlers = Alexa.CreateStateHandler(states.LOBBYMODE, {
'enterPasswordIntent': function () {
this.attributes['BUILDPASSWORD'] = '';
this.handler.state = states.PASSWORDMODE;
message = ` You will now create a password one letter, number or symbol at a time. there will be no message after each entry. simply wait for alexa's ring to become solid blue then stay your next value. When you are satisfied say complete. Begin now by saying a number, letter, or keyboard symbol. `;
reprompt = `Please say a number letter or symbol`;
this.emit(':ask', message, reprompt);
},
//Place other useful intents for your Skill here
'Unhandled': function() {
console.log("UNHANDLED");
var reprompt = ` You're kind of in the middle of something. Say exit to end createing this password. otherwise say complete if you've stated the whole password. or repeat to hear the current password you've entered. `;
this.emit(':ask', reprompt, reprompt);
}
});
var buildAlphaNumericPasswordHandlers = Alexa.CreateStateHandler(states.PASSWORDMODE, {
'numberIntent': function () {// Sample Utterance: ninty nine AMAZON.NUMBER
var number = this.event.request.intent.slots.number.value; //I believe this returns a string of digits ex: '999'
this.attributes['BUILDPASSWORD'] = this.attributes['BUILDPASSWORD'].concat(number);
message = ``; //No message to make saying the next letter, number or symbol as fluid as possible.
reprompt = `Please say the next number letter or symbol`;
this.emit(':ask', message, reprompt);
},
'letterIntent': function () {// Sample Utterance: A -- Custom Slot LETTERS [A, b, c, d, e, ... ]
var letter = this.event.request.intent.slots.letter.value;
this.attributes['BUILDPASSWORD'] = this.attributes['BUILDPASSWORD'].concat(letter);
message = ``; //No message to make saying the next letter, number or symbol as fluid as possible.
reprompt = `Please say the next number letter or symbol`;
this.emit(':ask', message, reprompt);
},
'symbolIntent': function () {// Sample Utterance: Dash -- Custom Slot SYMBOLS [Pound, Dash, Dollar Sign, At, Exclamation point... ]
var symbol = this.event.request.intent.slots.symbol.value;
// Create a dictionary object to map words to symbols ex Dollar Sign => $. Will need this because you likely cant put $ as a custom slot value. Can also map multiple names to the same value ex. Dash => Tack = \> "-"
var singleCharacterSymbol = symbolDict[symbol]; //^^^ Need to create dictionary
this.attributes['BUILDPASSWORD'] = this.attributes['BUILDPASSWORD'].concat(singleCharacterSymbol);
message = ``; //No message to make saying the next letter, number or symbol as fluid as possible.
reprompt = `Please say the next number letter or symbol`;
this.emit(':ask', message, reprompt);
},
'CompleteIntent': function() { //Sample Utterance: Complete
console.log("COMPLETE");
this.handler.state = states.LOBBYMODE;
var reprompt = ` Your entry has been saved, used to execute another function or checked against our database. `;
this.emit(':ask', reprompt, reprompt);
},
'ExitIntent': function() { //Sample Utterance: Exit
console.log("EXIT");
this.handler.state = states.LOBBYMODE;
message = `You have returned to the lobby, continue with the app or say quit to exit.`;
this.emit(':ask', message, message);
},
'RepeatIntent': function() {
var currentPassword = this.attributes['BUILDPASSWORD'];
var currentPasswordExploded = currentPassword.replace(/(.)(?=.)/g, "$1 "); //insert a space between each character so alexa reads correctly.
var message = ` Your current entry is as follows. `+currentPasswordExploded;
var reprompt = ` say complete if you've stated the whole password. Otherwise continue to say numbers letters and symbols. `;
this.emit(':ask', reprompt, reprompt);
},
'Unhandled': function() {
console.log("UNHANDLED");
var reprompt = ` You're kind of in the middle of something. Say exit to end creating this password, say complete if you've stated the whole password, say repeat to hear the current password you've entered, or continue to state letters, numbers and symbols `;
this.emit(':ask', reprompt, reprompt);
}
});
关于amazon-web-services - 如何向 Amazon Alexa Skills Kit (ASK) 混合数字字符串提供输入?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36061358/
我是一名优秀的程序员,十分优秀!