【问题标题】:Is it possible to play audio file or stream?是否可以播放音频文件或流?
【发布时间】:2018-07-05 07:03:48
【问题描述】:

是否可以使用actions-on-google-nodejs 库播放音频文件或流?

【问题讨论】:

    标签: actions-on-google dialogflow-es google-home


    【解决方案1】:

    使用SSML,您可以返回长达 120 秒的音频剪辑。

    <speak>
      <audio src="https://actions.google.com/sounds/v1/animals/cat_purr_close.ogg">
        <desc>a cat purring</desc>
        PURR (sound didn't load)
      </audio>
    </speak>
    

    编辑

    如果你想播放mp3文件的音频(超过120s),你需要使用Media Responses

    if (!conv.surface.capabilities.has('actions.capability.MEDIA_RESPONSE_AUDIO')) {
          conv.ask('Sorry, this device does not support audio playback.');
          return;
        }
        conv.ask(new MediaObject({
          name: 'Jazz in Paris',
          url: 'https://storage.googleapis.com/automotive-media/Jazz_In_Paris.mp3',
          description: 'A funky Jazz tune',
          icon: new Image({
            url: 'https://storage.googleapis.com/automotive-media/album_art.jpg',
            alt: 'Ocean view',
          }),
        }));
    

    【讨论】:

    • 不高于这个?我正在考虑播放完整的播客。
    • 不幸的是,不支持完整的播客播放,至少不支持这种方式。您可以阅读 this doc 了解播客操作。
    • SSML 的播放时间不够长。这不是我要寻找的答案。
    • 直播内容怎么样?
    • 平台不支持直播媒体流
    【解决方案2】:

    要为尼克的回答再添一分,您还可以构建一个媒体响应,允许您播放长音频文件(我目前在我的应用中播放 50 分钟专辑)。 您可以在 Google 的文档 here 上找到它。

    Node.js 中的一个简短示例可能是:

    const richResponse = app.buildRichResponse()
     .addSimpleResponse("Here's song one.")
      .addMediaResponse(app.buildMediaResponse()
      .addMediaObjects([
        app.buildMediaObject("Song One", "https://....mp3")
          .setDescription("Song One with description and large image.") // Optional
          .setImage("https://....jpg", app.Media.ImageType.LARGE)
            // Optional. Use app.Media.ImageType.ICON if displaying icon.
      ])
    )
    .addSuggestions(["other songs"]);
    

    然后你就可以做

    app.ask(richResponse)
    

    更新:

    根据评论请求,这是我的应用为 mediaResponse 发送的 JSON 响应:

    {
      "conversationToken": "[\"_actions_on_google\"]",
      "expectUserResponse": true,
      "expectedInputs": [
        {
          "inputPrompt": {
            "richInitialPrompt": {
              "items": [
                {
                  "simpleResponse": {
                    "textToSpeech": "Here is my favorite album."
                  }
                },
                {
                  "mediaResponse": {
                    "mediaType": "AUDIO",
                    "mediaObjects": [
                      {
                        "name": my_name,
                        "description": my_descr,
                        "largeImage": {
                          "url": my_url
                        },
                        "contentUrl": my_contentURL
                      }
                    ]
                  }
                }
              ],
              "suggestions": [
                {
                  "title": my_suggestion
                }
              ]
            }
          },
          "possibleIntents": [
            {
              "intent": "assistant.intent.action.TEXT"
            }
          ]
        }
      ],
      "responseMetadata": {
        "status": {
          "message": "Success (200)"
        },
        "queryMatchInfo": {
          "queryMatched": true,
          "intent": "0a3c14f8-87ca-47e7-a211-4e0a8968e3c5",
          "parameterNames": [
            my_param_name
          ]
        }
      },
      "userStorage": "{\"data\":{}}"
    }
    

    【讨论】:

    • 我试过了,好像只能播放mp3。 ? 我想在我的上下文中播放 m3u8 流。
    • 能否请您也在这里发布一个 REST(Json) 响应格式。我正在 Google Home 中寻找流式音频,但我可能没有使用他们提供的 nodejs sdk。
    • @Vikram 当然,我将使用 Actions On Google 模拟器获得的 RESPONSE 选项卡更新我的答案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多