【问题标题】:MP3 audio not playing in Alexa/Echo with addAudioPlayerPlayDirective使用 addAudioPlayerPlayDirective 在 Alexa/Echo 中无法播放 MP3 音频
【发布时间】:2018-12-08 02:17:41
【问题描述】:

我正在尝试实现 Alexa 的播放功能来播放我从 API 调用获得的 mp3 文件。我得到的数据很好,speak 指令确实包含来自 API 响应的数据,所以我知道调用有效,但文件本身永远不会播放。

我正在使用物理回声设备进行测试。

Cloudwatch 日志不是很有帮助(有没有更好的地方可以让我看到整个堆栈跟踪?),但我确实看到了以下错误:

Unable to find a suitable request handler.

随后与undefined 的会话结束。

这是我的实现代码:

API 调用:

const getEpisode = uri => new Promise(
  (resolve, reject) => {
    httpRequest({
      method: 'GET',
      uri,
      json: true,
      headers: {
        'X-API-KEY': key,
      },
    }).then(data => {
      console.log(data);
      return resolve(data);
    })
      .catch(err => reject(new Error(err)));
  }
);

播放意图:

const PlayIntentHandler = {
  canHandle(handlerInput) {
    return handlerInput.requestEnvelope.request.type === 'LaunchRequest' ||
        (handlerInput.requestEnvelope.request.type === 'IntentRequest'
        && handlerInput.requestEnvelope.request.intent.name === 'PlayIntent') ||
        (handlerInput.requestEnvelope.request.type === 'IntentRequest'
        && handlerInput.requestEnvelope.request.intent.name === 'AMAZON.ResumeIntent');
  },
  async handle(handlerInput) {
    const uri = `${endpoint}/most_recent/amazon`;
    console.log(uri);
    const data = await getEpisode(uri);
    console.log("before setting response");
    return handlerInput.responseBuilder
      .speak(`Playing episode ${data.episode_title}`)
      .addAudioPlayerPlayDirective('REPLACE_ALL', data.episode_url, data.episode_title, 0, null, null)
      .withShouldEndSession(true)
      .getResponse()
  },
};

知道我哪里出错了吗?

【问题讨论】:

  • 更新 - 由于某种原因,此代码似乎适用于 Echo Show,但不适用于 Echo Dot。

标签: audio mp3 alexa-skills-kit alexa-skill alexa-voice-service


【解决方案1】:

addAudioPlayerPlayDirective 有 5 个参数:

playBehavior - 'REPLACE_ALL'

url - data.episode_url

enqueueToken - data.episode_title

offsetInMilliseconds - `0`

expectedPreviousToken - `null`

.addAudioPlayerPlayDirective('REPLACE_ALL', data.episode_url, data.episode_title, 0, null, null)

如您所见,您有一个额外的参数null 被传递。删除它。

【讨论】:

  • 实际上,根据thisaddAudioPlayerPlayDirective 的完整签名是:addAudioPlayerPlayDirective(playBehavior: interfaces.audioplayer.PlayBehavior, url: string, token: string, offsetInMilliseconds: number, expectedPreviousToken?: string, audioItemMetadata? : AudioItemMetadata); 无论哪种方式,如我在上面的评论中所述,它似乎确实适用于 Echo Show(以及亚马逊的某人)在 Dot 上对其进行了测试,它也适用于他们),所以我的 Dot 可能有问题。
  • 哦,好的。我有一个自定义无线电技能,我没有使用最后一个参数,它工作得很好。
猜你喜欢
  • 2019-04-03
  • 1970-01-01
  • 2012-04-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多