【问题标题】:Alexa Skill: Playing Audio results in "Sorry don't know that"Alexa Skill:播放音频导致“抱歉不知道”
【发布时间】:2018-12-27 15:28:49
【问题描述】:

我正在编写我的第一个 Alexa 技能,我非常兴奋!我正在尝试制作一项技能,以便当我说“ramranch”时,alexa 将扮演 Sunil Syal。我使用空间事实选择器蓝图开始了这项技能。我已删除该代码并放入我自己的代码。 aws 已连接并且正在工作,但是当我在测试控制台中说“ramranch”时,Alexa 会回复“抱歉,我不知道”。它们没有调试或错误消息。

/* eslint-disable  func-names */
/* eslint-disable  no-console */

const Alexa = require('ask-sdk');

const RamRanch = {
  canHandle(handlerInput) {
    const request = handlerInput.requestEnvelope.request;
    return request.type === 'LaunchRequest'
    || (request.type === 'IntentRequest'
      && request.intent.name === 'handle');
  },
  handle(handlerInput) {
    this.emit(':tell', "Let's enjoy a world's most beautiful composition, composed by the great, Sunil Syal, <audio src='https://my-apis.000webhostapp.com/audio/Romantic%20Solitude-Instrumental%20(Flute).mp3'/> Wow, That is amazing. Click the link on top right corner to listen to full song.");
  }
}
const HelpHandler = {
  canHandle(handlerInput) {
    const request = handlerInput.requestEnvelope.request;
    return request.type === 'IntentRequest'
      && request.intent.name === 'AMAZON.HelpIntent';
  },
  handle(handlerInput) {
    return handlerInput.responseBuilder
      .speak(HELP_MESSAGE)
      .reprompt(HELP_REPROMPT)
      .getResponse();
  },
};

const ExitHandler = {
  canHandle(handlerInput) {
    const request = handlerInput.requestEnvelope.request;
    return request.type === 'IntentRequest'
      && (request.intent.name === 'AMAZON.CancelIntent'
        || request.intent.name === 'AMAZON.StopIntent');

【问题讨论】:

  • 也许它不认为你在说 ramranch
  • 嗯,你看到你在构建/测试技能时实际上在控制台中输入了单词。

标签: json amazon-web-services alexa


【解决方案1】:

很有可能在您修改蓝图技能时删除了节点模块。这是您的 index.js 代码的略微修改版本。开始一个节点项目 npm init。接下来 npm 安装 ask-sdk。您的项目文件夹现在将包含 node_modules、package-lock.json 和 package.json 添加此 index.js 文件。

const Alexa = require('ask-sdk-core');

const LaunchRequestHandler = {
  canHandle(handlerInput) {
    return handlerInput.requestEnvelope.request.type === 'LaunchRequest';
  },
  handle(handlerInput) {
    const speechText = 'Welcome to the Alexa Skills Kit, you can say what about ramranch';

    return handlerInput.responseBuilder
      .speak(speechText)
      .reprompt(speechText)
      .withSimpleCard('Ramranch', speechText)
      .getResponse();
  }
};
const RamranchIntentHandler = {
  canHandle(handlerInput) {
    return handlerInput.requestEnvelope.request.type === 'IntentRequest'
      && handlerInput.requestEnvelope.request.intent.name === 'ramranchIntent';
  },
  handle(handlerInput) {
    const speechText = 'Lets enjoy a worlds most beautiful composition, composed by the great, Sunil Syal, <audio src="https://my-apis.000webhostapp.com/audio/Romantic%20Solitude-Instrumental%20(Flute).mp3"/> Wow, That is amazing. Click the link on top right corner to listen to full song.';

    return handlerInput.responseBuilder
      .speak(speechText)
      .withSimpleCard('Ramranch', speechText)
      .getResponse();

  }
};
const HelpIntentHandler = {
  canHandle(handlerInput) {
    return handlerInput.requestEnvelope.request.type === 'IntentRequest'
      && handlerInput.requestEnvelope.request.intent.name === 'AMAZON.HelpIntent';
  },
  handle(handlerInput) {
    const speechText = 'You can say what about Ramranch!';

    return handlerInput.responseBuilder
      .speak(speechText)
      .reprompt(speechText)
      .withSimpleCard('Ramranch', speechText)
      .getResponse();
  }
};
const CancelAndStopIntentHandler = {
  canHandle(handlerInput) {
    return handlerInput.requestEnvelope.request.type === 'IntentRequest'
      && (handlerInput.requestEnvelope.request.intent.name === 'AMAZON.CancelIntent'
        || handlerInput.requestEnvelope.request.intent.name === 'AMAZON.StopIntent');
  },
  handle(handlerInput) {
    const speechText = 'Goodbye!';

    return handlerInput.responseBuilder
      .speak(speechText)
      .withSimpleCard('Ramranch', speechText)
      .getResponse();
  }
};
const SessionEndedRequestHandler = {
  canHandle(handlerInput) {
    return handlerInput.requestEnvelope.request.type === 'SessionEndedRequest';
  },
  handle(handlerInput) {
    //any cleanup logic goes here
    return handlerInput.responseBuilder.getResponse();
  }
};
const ErrorHandler = {
  canHandle() {
    return true;
  },
  handle(handlerInput, error) {
    console.log(`Error handled: ${error.message}`);

    return handlerInput.responseBuilder
      .speak('Sorry, I can\'t understand the command. Please say again.')
      .reprompt('Sorry, I can\'t understand the command. Please say again.')
      .getResponse();
  },
};

exports.handler = Alexa.SkillBuilders.custom()
  .addRequestHandlers(
    LaunchRequestHandler,
    RamranchIntentHandler,
    HelpIntentHandler,
    CancelAndStopIntentHandler,
    SessionEndedRequestHandler)
  .addErrorHandlers(ErrorHandler)
  .lambda();

请务必修改您的 Alexa 技能开发人员模型以包含 ramranchIntent,因为我没有像您的代码中那样结合启动和主要意图。最后,将它与前面提到的其他文件一起压缩到 AWS 中的 lambda 函数中,并添加一些用于触发 Ramranch 的意图短语,在我的测试中,我使用了这个技能 JSON

{
    "interactionModel": {
        "languageModel": {
            "invocationName": "ramranch player",
            "intents": [
                {
                    "name": "AMAZON.FallbackIntent",
                    "samples": []
                },
                {
                    "name": "AMAZON.CancelIntent",
                    "samples": []
                },
                {
                    "name": "AMAZON.HelpIntent",
                    "samples": []
                },
                {
                    "name": "AMAZON.StopIntent",
                    "samples": []
                },
                {
                    "name": "AMAZON.NavigateHomeIntent",
                    "samples": []
                },
                {
                    "name": "ramranchIntent",
                    "slots": [],
                    "samples": [
                        "what about ramranch",
                        "lets hear ramranch"
                    ]
                }
            ],
            "types": []
        }
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多