如何向 Amazon Alexa Skills Kit (ASK) 混合字符串和数字提供输入?

Posted

技术标签:

【中文标题】如何向 Amazon Alexa Skills Kit (ASK) 混合字符串和数字提供输入?【英文标题】:How to give input to Amazon Alexa Skills Kit (ASK) mixed string with numbers? 【发布时间】:2016-07-03 20:22:14 【问题描述】:

我正在尝试创建一个 Amazon Alexa Skills Kit 来执行某种自动化,这需要接受由字符串和数字组成的语音输入 (a-test12fish)。

当我在 Alexa Skills Kit 中使用自定义插槽时,它不允许我输入带有数字的字符串。当我尝试输入 ask alexa, dangerZone find a-test12fish 时,我收到以下错误:

错误:文本输入无效。文本应以字母开头,并且只能包含字母、空格、句点或撇号

我该如何克服这个错误?

【问题讨论】:

你好 Sathish,你找到这个了吗? 【参考方案1】:

这里有一个解决方案。

您可能不想在意图架构中完成此操作。相反,请尝试使用 Node.js 创建自定义模式,将字母、数字和符号编译为单个响应。这是我对字母数字输入模式的演绎。请注意:我只是为了回答您的问题而写的,并没有在更大的技能上对其进行测试。话虽如此,我在MODES 方面取得了巨大成功,当我有机会时,我一定会用我自己的技能来实现这一点。

此代码背后的想法是您将用户推入一个单独的模式,该模式忽略除NumberIntentLetterIntentSymbolIntent 和一些帮助功能之外的所有意图。用户快速输入他们的字母数字值并在完成后激活 CompletedIntent。然后可以在您技能的其他地方使用该字母数字值。如果您没有使用过Modes,请注意在完成或退出时,您将被重定向回LOBBYMODE,您可以继续访问您技能中的其他意图。

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);
    
);

【讨论】:

【参考方案2】:

您没有说明您希望用户如何说出该值。例如,“a dash test 十二条鱼”或“a dash t e s t one two f i s h”。在任何情况下,识别系统都是为识别单词而设计的,而该数据不是有效的单词。

至于解决问题,您可以尝试通过创建具有所有有效字符值的自定义槽类型和支持有效长度的示例话语来创建拼写解决方案(后一个输入)。

您需要做一些工作来重新组合消息,但它不应该太复杂。可能的挑战仍然来自识别器。虽然我没有在 Alexa 下测试过这个场景,但我使用过的大多数在可变长度、字母数字字符串方面都做得很差。声音太相似了,有几个值很容易被误认为是停顿和背景噪音。典型的解决方法是使用phonetic alphabet。

【讨论】:

感谢您的输入,我想说它是“连字符测试一条两条鱼”,同时我尝试按照建议使用拼音字母【参考方案3】:

在系统的限制范围内将采用不同的方法。您可以使用不同的名称来引用它。

用“say 1 for a-test12fish”等提示用户。并在内部将其映射到您的特定值。

【讨论】:

【参考方案4】:

使用 SSML,您可以在其中设计自己的发音风格。请检查。

【讨论】:

以上是关于如何向 Amazon Alexa Skills Kit (ASK) 混合字符串和数字提供输入?的主要内容,如果未能解决你的问题,请参考以下文章

Alexa Skills Kit 示例技能不会上传到 Amazon Lambda - 引发错误

Alexa Skills Kit:如何使用 JS 将图像添加到标准卡片

AWS - Alexa 指令定义

Alexa Skills Set SDK - 增加技能超时

仅从 Alexa Skills Kit 获取单个单词参数

如何为 Alexa Skills Kit 和 API.AI 使用单个 AWS Lambda?