Step 1: Streaming an Audio File

by Kaan Kilic on Feb 13, 2019

As a first step towards building our own podcast player Alexa Skill and Google Action, we will create a new Jovo project and make it stream a single audio file for both Alexa and Google Assistant.

Creating the Project

You can find the full code example on GitHub.

To start off we have to create a new Jovo project. Therefore if you haven't already, install the Jovo CLI:

Create a new project:

This will create a new Jovo project into the folder PodcastPlayer. You can go into the folder like this:

Playing an Audio File

The heart of our project is located in the app.js file inside the src folder. That's the place where we build the logic of our project.

Open up the file and we will see that there are already three intents defined in the setHandler() function. We delete everything besides the LAUNCH intent since we won't need the other intents at this point:

Streaming an audio file works differently on both platforms, so we will go over the Alexa part first and add the Google Action implementation after that.

On Amazon Alexa

Learn more about the Alexa AudioPlayer interface.

To play a long-form audio file with Alexa, we will use the Alexa AudioPlayer interface. This needs to be enabled either by using the Jovo CLI, or in the Alexa Developer Console. We will do this in Step 3: Preparing the Development Environment, where we set up the voice platform projects. For now, let's get started with the code first and use the Jovo Debugger for testing.

First, we store the URL, where the audio file is hosted at (has to be an HTTPS endpoint). Let's use the popular Voicebot Podcast by Bret Kinsella as an example and play a recent episode:

Next, we use the this.$alexaSkill.$audioPlayer object to do 3 things:

  • Set the offset, which defines the timestamp at which Alexa will start playing the file (in milliseconds). For example, an offset of 1000 will start your audio file at 0:01.
  • Call the play function and pass in the URL as well as a token which will discuss later on.
  • Use tell to attach a speech output that will be said by Alexa before playing the audio file.

We place that snippet inside your LAUNCH intent, so it gets triggered every time our app is launched:

The most convenient way to test our application is to run the local Jovo Webhook using the CLI.

The Webhook URL we receive can be used for local development as an HTTPS endpoint, so we don't have to upload our code to AWS Lambda or any other cloud service.

The Webhook URL is also the gateway to the Jovo Debugger. You can simply copy and paste the URL into your browser (or use the . key):

Jovo Debugger

The Jovo debugger improves your developing experience by showing you the most important data (incoming requests, responses, database, etc.) at one place as well as allowing you to test right on the spot.

For now, press the launch button right at the middle of the page to send a sample request to your Webhook. Your app should respond by playing the audio file. Ignore the errors for now, we will discuss and fix these further down the road.

Jovo Debugger playing audio

That was easy, wasn’t it?

Let’s do the same for our Google Action.

On Google Assistant

Learn more abou the Google Action Media Response interface.

Google Actions offer a similar interface, the Media Response API, to play audio files. Again, we will take care of the setup process in Step 3: Preparing the Development Environment, and focus on the implementation for now.

To get started, we can add a similar method call this.$googleAction.$mediaResponse.play(song, 'song one'); to our existing code:

As you can see there’s a slight difference between the Alexa function and the Google one. We don’t have to specify the offset or a token, but a title. I will explain the reason for that later on.

But, there's still a small issue. We don't want to use both interfaces with every request, because that would cause an error, so we have to first check from which platform the request is being sent. For this. we can use the isAlexaSkill or isGoogleAction helper methods:

So our LAUNCH intent should look like this now:

Let’s test the Google Action implementation. First, we have to change the device that the Jovo Debugger simulates, which is set to the Alexa Echo Dot by default, to the Google Assistant Phone so our application receives the right requests. You can find the option on the bottom of the Debugger.

Jovo Debugger Device

After that press the LAUNCH button and we should hear the song playing.

Jovo Debugger Playing Audio Google

Alright, we're now able to play a simple audio file on both Amazon Alexa and the Google Assistant.

Next Step

In the next step, we will learn how to keep streaming additional audio files after the first song finished.

Step 2: Streaming Multiple Files in a Row


Kaan Kilic

Technical Content Marketing Associate at Jovo

Comments and Questions

Any specific questions? Just drop them below or join the Jovo Community Forum.

Join Our Newsletter

Be the first to get our free tutorials, courses, and other resources for voice app developers.