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.
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:
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.
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.
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
1000will start your audio file at
- Call the
playfunction and pass in the URL as well as a token which will discuss later on.
tellto 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
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.
That was easy, wasn’t it?
Let’s do the same for our Google Action.
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
isGoogleAction helpfer methods:
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.
After that press the
LAUNCH button and we should hear the song playing.
Alright, we're now able to play a simple audio file on both Amazon Alexa and the Google Assistant.
In the next step, we will learn how to keep streaming additional audio files after the first song finished.