【问题标题】:Alexa Skill NodeJS - Combine speak and addAudioPlayerPlayDirectiveAlexa Skill NodeJS - 结合说话和 addAudioPlayerPlayDirective
【发布时间】:2019-01-11 15:31:56
【问题描述】:

我希望能够做到以下几点:

  1. 让 alexa 说点什么
  2. 播放音频文件
  3. 让 alexa 说点别的

我尝试了以下代码,但不起作用:

const IntentHandler = {
  canHandle(handlerInput) {
    return handlerInput.requestEnvelope.request.type === "IntentRequest" &&
      handlerInput.requestEnvelope.request.intent.name === "MyIntent";
  },
  handle(handlerInput) {
    return handlerInput.responseBuilder
      .speak("Say something")
      .addAudioPlayerPlayDirective('REPLACE_ALL', audioFile, 'token', 0)
      .speak("Say something else")
      .getResponse();
  }
}

上面代码的结果是这样的:

  1. “说点别的”
  2. audioFile 播放

我怎样才能做到这一点?

【问题讨论】:

  • 尝试将您的第二次发言放入自己的请求信封中。
  • @RobertHarvey 你有代码示例吗?
  • 这和你的一样,只是你有两个意图而不是一个。

标签: node.js alexa-skills-kit alexa-sdk-nodejs


【解决方案1】:

我通过使用 ssml-builder 包创建一个 SSML 字符串并修改使用该字符串发回的响应来解决这个问题。

const AmazonSpeech = require('ssml-builder/amazon_speech');
const speech = new AmazonSpeech();
speech.say('Start of the story')
  .audio(audioFile)
  .say('Finish the story');
const ssml = speech.ssml();
const response = handlerInput.responseBuilder.getResponse();
response.outputSpeech = {
  type: 'SSML',
  ssml: ssml
};
return response;

【讨论】:

    猜你喜欢
    • 2019-01-03
    • 2020-10-15
    • 2018-05-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多