How can I tell Actions on Google to stream audio?

走远了吗. 提交于 2019-11-27 02:14:39

问题


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?

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.

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#.

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


回答1:


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',
  }),
}));

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

I posted an answer over here.

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

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



回答2:


According to the documentation you can embed elements in SSML. https://developers.google.com/actions/reference/ssml includes the following example:

<speak>
  Here are <say-as interpet-as="characters">SSML</say-as> samples.
  I can pause <break time="3s"/>.
  I can play a sound
  <audio src="https://www.example.com/MY_MP3_FILE.mp3">didn't get your MP3 audio file</audio>.
  I can speak in cardinals. Your number is <say-as interpret-as="cardinal">10</say-as>.
  Or I can speak in ordinals. You are <say-as interpret-as="ordinal">10</say-as> in line.
  Or I can even speak in digits. The digits for ten are <say-as interpret-as="characters">10</say-as>.
  I can also substitute phrases, like the <sub alias="World Wide Web Consortium">W3C</sub>.
  Finally, I can speak a paragraph with two sentences.
  <p><s>This is sentence one.</s><s>This is sentence two.</s></p>
</speak>

EDIT

p/s : SSML in Documents has these limitations :

  • Single channel is preferred, but stereo is acceptable.
  • 120 seconds maximum duration. If you want to play audio with a longer duration, consider implementing a media response. 5 megabyte file size limit.

  • Source URL must use HTTPS protocol.

  • Our UserAgent when fetching the audio is "Google-Speech-Actions".


来源:https://stackoverflow.com/questions/42048385/how-can-i-tell-actions-on-google-to-stream-audio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!