Search code examples
actions-on-googledialogflow-esgoogle-home

Is it possible to play audio file or stream?


Is it possible to play audio file or stream using actions-on-google-nodejs library?


Solution

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