LoginSignup
6
2

More than 3 years have passed since last update.

APL(Alexa Presentation Language)のSpeakItemでmp3を鳴らす

Last updated at Posted at 2019-05-27

こんにちは

APLのSpeakItemの中でaudioタグを書いてもmp3が鳴らない仕様があり永らく悩んでいたのですが、APLでmp3を鳴らす方法を見つけたのでざっくり共有します。

追記(2019/6)

echo show5やFireTV一部の機種において、通常のspeakとAPLのSpeakItemを併用するとフリーズする症状を確認しています。通常のspeakを使わずに全てSpeakItemのみで鳴らす事で回避可能です。

例えば

hoge.mp3をAPLで鳴らすAPLを送るとします。
解説の都合上、datasourcesとExecuteCommandsから先に。

datasources-1
"datasources": {
  "pagerAnimationData": {
    "properties": {
      "topicSsml": [
        "<speak><audio src=\"https://s3-ap-.../hoge.mp3\" /></speak>"
      ],
    },
    "transformers": [
      {
        "inputPath": "topicSsml",
        "outputName": "topicSpeech",
        "transformer": "ssmlToSpeech"
      },
      {
        "inputPath": "topicSsml",
        "outputName": "topicText",
        "transformer": "ssmlToText"
      }
    ]
  }
}
ExecuteCommands(抜粋)
{
  "type": "SpeakItem",
  "componentId": "talk_0"
}

鳴らない

さて、以下のようにDocumentを書いておいても鳴りません。

document-1(抜粋)
{
  "type": "Text",
  "id": "talk_0",
  "text": "(音声再生中)",
  "speech": "${payload.pagerAnimationData.properties.topicSpeech[0]}",
  "position": "absolute",
  "width": 0,
  "height": 0
}

以下でもダメでした。

document-1a(差分)
  "speech": "${payload.pagerAnimationData.properties.topicSsml[0]}",

鳴る

下記のように、speechに直接URLを指定すると鳴らす事が出来ます。

datasources-2
"datasources": {
  "pagerAnimationData": {
    "properties": {
      "topicSsml": [
        "(ここにはSSML書かない)"
      ],
      "topicSound": [
        "https://s3-ap-.../hoge.mp3"
      ]
    },
    "transformers": [
      {
        "inputPath": "topicSsml",
        "outputName": "topicSpeech",
        "transformer": "ssmlToSpeech"
      },
      {
        "inputPath": "topicSsml",
        "outputName": "topicText",
        "transformer": "ssmlToText"
      }
    ]
  }
}
document-2
{
  "type": "Text",
  "id": "talk_0",
  "text": "(音声再生中)",
  "speech": "${payload.pagerAnimationData.properties.topicSound[0]}",
  "position": "absolute",
  "width": 0,
  "height": 0
}

気をつける点

開発コンソールのシミュレータでは鳴らない(動作が止まる)のでご注意ください。
・念のためtransformersの影響を受けない場所に置いたほうがいいかも。(未検証)

参考

Alexa Command SpeakItem coupled with self provided mp3 ? - Forums

6
2
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
2