Create your own Alexa Radio Skill with your favourite streaming stations. Once deployed, you can say Alexa, open radio
and Alexa will start streaming a radio station. You can stream a particular genre by saying Alexa, ask radio to play Jazz music
. You can, of course, add or delete the stations, so you can have a completely personalised music playing experience. Getting up and running is super simple.
If you haven’t checked out Code on Standard Library, do that right now. Sign up and get an account. It’s free.
Next, click on Open and this will open up a panel with some featured templates you can use.
Click on the Community API Sources
tab and search for alexa-radio-skill
. Click on Create API to use it as a template for your own service. Once it’s created, proceed to the next step.
In the main.js
file, at the top is astations
object. This holds all the stream information.
const stations = {meditate: {name: "Meditation Radio",url: ["https://yp.shoutcast.com/sbin/tunein-station.m3u?id=716503","https://yp.shoutcast.com/sbin/tunein-station.m3u?id=672521"]}}
If you want to add your own stations, the simplest way is to go to shoutcast and search for your favourite stations. To get the URL of the the station, click on the download icon and right-click and copy the Any player (.m3u) value.
You can also add any streaming link, as long as it starts with https://
.
Now, navigate to the env.json
file and populate the environments with your Standard Library Token.
The code will not work without the token.
To retrieve your Standard Library Token, place the cursor in between the yellow quotes and right click. Select your Standard Library Token from the drop-down menu and the variable should automatically populate.
Click on the green Run button to deploy the service. Once deployed, note the URL of your endpoint. It should look something like this:https://[username].lib.id/alexa-radio-skill@dev/
The skill will give you a message when it’s run directly because it’s expecting a request
event from Alexa. You can ignore this message.
Go to developer.amazon.com to create a new Alexa Skill. If you haven’t signed up for an Amazon Developer account yet, do so now. Once logged in, you should see Create Skill button.
Here you can give your skill a name and choose your default language. Choose Custom for model to add to your skill.
On the next screen, choose Start from scratch.
Once you create the Alexa Skill, create the Interaction Model. Click on JSON Editor at the bottom left.
Next head back to Code on Standard Library and navigate to AlexaInteractionModel.json
file.
Copy it’s contents and paste it into the right-hand pane of the JSON Editor on the Alexa developer portal.
The invocation name is set as radio
. If you want to change it, do so before you paste. To change the name, just change the invocationName
value in the JSON file.
Make sure you select Save Model on the JSON Editor to save your model.
Click on Endpoint in the sidebar to update the endpoint URL.
Now paste the URL endpoint here. Make sure you choose My development endpoint is a sub-domain of a domain
option from the drop down menu.
Click on Interfaces and turn on the Audio Player interface. The skill will not work without this being enabled.
That’s all the setup you need to do. In the Alexa Development portal, click on Build Model. This might take a couple of minutes.
Once you get the pop-up saying that the Build Succeeded, click on the Test tab next to Build on the Alexa Developer console.
This will open the test console.
Enable the skill if it’s not. Then enter open radio
in the chat text box.
If you have setup everything correctly, you should get a reply. If it works, then you can directly test it on your Alexa device.
**Notes**- All streaming URLs should be https
.- The test simulator on Alexa Developer portal does not play any audio.
If you get stuck anywhere, or if you have any feedback, write to me.