如何让 Actions on Google 流式传输音频? [英] How can I tell Actions on Google to stream audio?

查看:31
本文介绍了如何让 Actions on Google 流式传输音频?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个与 Google Actions 配合使用的应用.唯一令人遗憾的是,我找不到任何有关如何形成响应的信息,以便 Google 可以从给定的 URL 流式传输音频.Google 是否还支持此功能?

I am writing an app to work with Google Actions. The only bummer is that I can't find any information about how to form my response so that Google will stream audio from a given URL. Does Google even support this yet?

我已经在 Alexa 上编写了相同的应用程序,在 Alexa 上您只需返回一个音频项目(令牌、URL、播放命令),Alexa 就会开始流式传输它.

I have written the same app on Alexa already, and on Alexa all you have to do is Return an audio item (token, URL, play command) and Alexa will start streaming it.

我应该提到我没有使用 API.AI,而只是使用 Actions SDK 并使用 C# 在 Asure 上托管我的网络服务.

I should mention that I am NOT using API.AI, but am simply using the Actions SDK and am hosting my web service on Asure using C#.

所以,最重要的是...如何通过 Actions SDK 格式化响应以将 MP3 文件流式传输到 Google Home?

So, bottom line... How can I format a response via the Actions SDK to stream an MP3 file to Google Home?

推荐答案

更新: 第一个答案仅适用于 Dialogflow V1.对于 V2,您可以通过这种方式创建 mediaResponse(来自 Google 的文档):

UPDATE: The first answer works only with the V1 of Dialogflow. As for the V2, you can create the mediaResponse this way (from Google's doc):

conv.ask(new MediaObject({
  name: 'Jazz in Paris',
  url: 'http://storage.googleapis.com/automotive-media/Jazz_In_Paris.mp3',
  description: 'A funky Jazz tune',
  icon: new Image({
    url: 'http://storage.googleapis.com/automotive-media/album_art.jpg',
    alt: 'Media icon',
  }),
}));

========================================================================

========================================================================

我在在这里发布了一个答案.

基本上,您可以创建一个 mediaResponse 对象来播放您的音频文件.我可以播放 50 分钟的音频文件就好了.

Basically you can create a mediaResponse object that will play your audio file. I can play a 50 mins audio file just fine.

Node.js 中的代码示例可以是(使用当前文档):

A code example in Node.js could be (with the current documentation):

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"]);

这篇关于如何让 Actions on Google 流式传输音频?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆