首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何向Amazon技能工具包(询问)输入数字混合字符串?

如何向Amazon技能工具包(询问)输入数字混合字符串?
EN

Stack Overflow用户
提问于 2016-03-17 13:03:05
回答 4查看 3.4K关注 0票数 5

我正在尝试创建一个Amazon技能工具包,以实现某种自动化,这将需要使用由字符串和数字(a-test12fish)组成的语音输入。

当我在Alexa技能工具包中使用自定义插槽时,它不允许我用数字输入字符串。当我试图输入ask alexa, dangerZone find a-test12fish时,会得到以下错误:

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

我如何克服这个错误?

EN

回答 4

Stack Overflow用户

发布于 2017-08-04 21:14:34

这里有个解决办法。

您可能不希望在意图模式中完成此操作。相反,尝试使用Node.js创建一个自定义模式,将字母、数字和符号编译成单个响应。这是我的阿尔法数字输入模式的再现。请注意:我写这个只是为了回答你的问题,还没有用更大的技巧来测试它。话虽如此,我在MODES方面已经取得了很大的成功,当我有机会的时候,我一定会用我自己的技能来实现这一点。

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

代码语言:javascript
复制
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);
    }
});
票数 5
EN

Stack Overflow用户

发布于 2016-03-18 13:05:51

您没有指明用户是如何表示值的。例如,“一条短跑测试十二条鱼”或“一条短跑不是一二fs h”。无论如何,识别系统都是为了识别单词而设计的,而数据不是一个有效的单词。

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

您将需要一些工作来重新组装消息,但它不应该太复杂。可能的挑战仍将来自识别器。虽然我还没有在Alexa下测试过这个场景,但我使用的大多数情况对于可变长度的alpha数字字符串来说做得相当糟糕。声音太相似了,有几个值很容易被误认为是停顿和背景噪音。典型的工作是使用语音字母表

票数 1
EN

Stack Overflow用户

发布于 2016-11-23 09:02:13

另一种办法是在系统的限制范围内发挥作用。你可以用不同的名字来指它。

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36061358

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档