alexa skill that can play pepper radio (https://pepper966.gr)
from https://github.com/alexa/skill-sample-nodejs-audio-player
This skill demonstrates how to create a single stream audio skill. Single stream skills are typically used by radio stations to provide a convenient and quick access to their live stream.
User interface is limited to Play and Stop use cases.
Alexa, play pepper radio
Alexa, stop
You will need to comply to the prerequisites below and to change a few configuration files before creating the skill and upload the lambda code.
This is a NodeJS Lambda function and skill definition to be used by ASK CLI.
You need an AWS account and an Amazon developer account to create an Alexa Skill.
You need to install and configure the AWS CLI
You need to inistall and to initialize ASK CLI with
$ ask init
$ (cd lambda && npm install)
$ (cd lambda/src && npm install)
./skill.json
Change the skill name, example phrase, icons, testing instructions etc ...
Remember than most information is locale-specific and must be changed for each locale (en-GB and en-US)
Please refer to https://developer.amazon.com/docs/smapi/skill-manifest.html for details about manifest values.
./lambda/src/audioAssets.js
Modify each value in the audioAssets.js file to provide your skill with the correct runtime values for values : your radio name, description, icon and, obviously, URL of your stream (https only).
startJingle
is an optional property defining a Jingle to be played before the live stream.
To learn more about Alexa App cards, see https://developer.amazon.com/docs/custom-skills/include-a-card-in-your-skills-response.html
var audioData = {
card : {
title: 'Pepper Radio',
subtitle: 'Less bla bla, more la la',
cardContent: "Visit our web site https://www.myradio.com",
image: {
largeImageUrl: 'https://s3-eu-west-1.amazonaws.com/alexa.maxi80.com/assets/alexa-artwork-1200.png',
smallImageUrl: 'https://s3-eu-west-1.amazonaws.com/alexa.maxi80.com/assets/alexa-artwork-720.png'
}
},
url: 'https://audio1.maxi80.com',
startJingle : 'https://s3.amazonaws.com/alexademo.ninja/maxi80/jingle.m4a',
};
./models/*.json
Change the model defintion to replace the invocation name (it defaults to "pepper radio") and the sample phrases for each intent.
Repeat the operation for each locale you are planning to support.
./lambda/src/constants.js
module.exports = Object.freeze({
//App-ID. TODO: set to your own Skill App ID from the developer portal.
//appId : 'amzn1.ask.skill.123',
// when true, the skill logs additional detail, including the full request received from Alexa
debug : true,
// when defined, it tries to read / write DynamoDB to save the last time Jingle was played for that user
// this allows to avoid to repeat the jingle at each invocation
jingle : {
// the name of the dynamoDB table
databaseTable : "my_radio",
// the elasped time between two jingles for a customer (in seconds)
playOnceEvery : 1 * 60 * 60 * 24 // 24 hours
}
});
When playing a jingle before your stream, you can choose the name of the database table where the "last played" information will be stored. If the table does not exist, the persistence code will silently fail and play the jingle at each invocation of the skill.
You can create the DynamoDB table with the following command:
aws dynamodb create-table --table-name my_radio --attribute-definitions AttributeName=userId,AttributeType=S --key-schema AttributeName=userId,KeyType=HASH --provisioned-throughput ReadCapacityUnits=5,WriteCapacityUnits=5
To minimize latency, we recommend to create the DynamDB table in the same region as the Lambda function.
When using DynamoDB, you also must ensure your Lambda function execution role will have permissions to read and write to the DynamoDB table. Be sure to add the following policy to the Lambda function execution role:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "sid123",
"Effect": "Allow",
"Action": [
"dynamodb:PutItem",
"dynamodb:GetItem",
"dynamodb:UpdateItem"
],
"Resource": "arn:aws:dynamodb:us-east-1:YOUR_ACCOUNT_ID:table/my_radio"
}
]
}
This code uses Mocha and Chai to test the responses returned by your skill. Be sure you have no test failures before deploying.
Execute your test by typing
$ (cd lambda && npm test)
ASK will create the skill and the lambda function for you.
Lambda function will be created in us-east-1
(Northern Virginia) by default.
You deploy the skill and the lambda function in one step :
$ ask deploy
You can test your deployment by FIRST ENABLING the TEST switch on your skill in the Alexa Developer Console.
Then
$ ask simulate -l en-GB -t "alexa, play pepper radio"
Simulation created for simulation id: 4a7a9ed8-94b2-40c0-b3bd-fb63d9887fa7
Waiting for simulation response{
"status": "SUCCESSFUL",
...
You should see the code of the skill's response after the SUCCESSFUL line.
Once the skill and lambda function is deployed, do not forget to add the skill id to lambda/src/constants.js
to ensure your code is executed only for your skill.
Uncomment the AppId
line and change it with your new skill id. You can find the skill id by typing :
$ ask api list-skills
{
"skills": [
{
"lastUpdated": "2017-10-08T08:06:34.835Z",
"nameByLocale": {
"en-GB": "Pepper radio",
"en-US": "Pepper radio"
},
"skillId": "amzn1.ask.skill.123",
"stage": "development"
}
]
}
Then copy/paste the skill id to lambda/src/constants.js
module.exports = Object.freeze({
//App-ID. TODO: set to your own Skill App ID from the developer portal.
appId : "amzn1.ask.skill.123",
// when true, the skill logs additional detail, including the full request received from Alexa
debug : false
});
To invoke the skill from your device, you need to login to the Alexa Developer Console, and enable the "Test" switch on your skill.
See https://developer.amazon.com/docs/smapi/quick-start-alexa-skills-kit-command-line-interface.html#step-4-test-your-skill for more testing instructions.
Then, just say :
Alexa, open pepper radio.