Is it possible to play audio file or stream using actions-on-google-nodejs library?
Asked
Active
Viewed 6,425 times
2 Answers
6
Using SSML you can return an audio clip up to 120s.
<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>
Edit
If you want to play audio the mp3 file (over 120s), you need to use 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',
}),
}));

Huy Tower
- 7,769
- 16
- 61
- 86

Nick Felker
- 11,536
- 1
- 21
- 35
-
1Not higher than that? I was thinking in play a full podcast. – DONSA Jan 25 '18 at 23:11
-
Unfortunately full podcast playback isn't supported, at least not in this way. You can read [this doc](https://developers.google.com/actions/content-actions/podcasts) for podcast actions. – Nick Felker Jan 25 '18 at 23:19
-
SSML is not enough long to me to play. This is not the answer I looking for. – Johnny Apr 02 '18 at 01:13
-
What about live content? – ColorCodin Jun 26 '18 at 13:26
-
Live streams of media are not supported in the platform – Nick Felker Jun 26 '18 at 17:30
-
how can i achieve this using php? – Tara Aug 29 '19 at 09:17
-
When you look at the MediaResponse documentation, you can see the JSON equivalent. – Nick Felker Aug 30 '19 at 13:44
5
To add one more point to Nick's answer, you can also build a Media Response which will allow you to play a long audio file (I'm currently playing 50 mins album in my app). You can find it on Google's doc here.
A short example in Node.js could be:
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"]);
And then you can just do
app.ask(richResponse)
UPDATE:
As per a comment request, here is the JSON response sent by my app for a mediaResponse:
{
"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\":{}}"
}

Rémi C.
- 339
- 2
- 12
-
I tried that it seems only can play mp3. I want to play m3u8 streaming in my context. – Johnny Apr 02 '18 at 01:13
-
Can you please post a REST(Json) response format here too. I am looking for streaming audio in Google Home but I may not be using the nodejs sdk that they provide. – Vikram May 17 '18 at 18:29
-
@Vikram Sure, I'll update my answer with the RESPONSE tab obtained with the Actions On Google simulator. – Rémi C. May 18 '18 at 07:26