Skip to content

Commit

Permalink
Merge pull request #1 from sebsto/Github
Browse files Browse the repository at this point in the history
Add single stream sample code
  • Loading branch information
akersh-s committed Oct 10, 2017
2 parents 1ab6a7e + a205198 commit 6991ead
Show file tree
Hide file tree
Showing 37 changed files with 1,815 additions and 85 deletions.
2 changes: 1 addition & 1 deletion .gitignore
@@ -1 +1 @@
node_modules
node_modules
88 changes: 4 additions & 84 deletions README.md
@@ -1,87 +1,7 @@
# Audio Player Sample Project
# Skill Sample NodeJS Audio Player

Alexa Skills Kit now allows 3P-developers to build skills supporting Audio Player Interfaces. This sample project will showcase how developers can use long form audio in Alexa Skills.
This project demonstartes the use of Alexa Audio Player for skills.

## How to Get Started
- Multiple-streams folder contains an example skill to play multiple, re-recorded audio streams, such as a basic podcast skill.

Setup AWS and the Amazon Developer Console.

You can change the name of these resources to whatever you like later, but for now, setup the following items:

1. Create or login to an [AWS account](https://aws.amazon.com/). In the AWS Console:
1. Create an AWS Role in IAM with access to Lambda and DynamoDB.
![create_role_1](https://cloud.githubusercontent.com/assets/7671574/17451098/09f64f40-5b19-11e6-82ee-b82c98387052.png "AWS Create Role Screenshot 1")
![create_role_2](https://cloud.githubusercontent.com/assets/7671574/17451100/0c3ef928-5b19-11e6-9aca-8cd353106396.png "AWS Create Role Screenshot 2")
![create_role_3](https://cloud.githubusercontent.com/assets/7671574/17451101/0e3c5ff4-5b19-11e6-90f6-0210dae6f9dc.png "AWS Create Role Screenshot 3")

2. Create an AWS Lambda function named AudioPlayerLambdaFunction being sure to select the role created above and configuring "Alexa Skills Kit" as the "Trigger".
![alt text](https://s3.amazonaws.com/lantern-public-assets/audio-player-assets/aws-lambda-role.PNG "AWS Lambda Role")

![alt text](https://s3.amazonaws.com/lantern-public-assets/audio-player-assets/aws-lambda-ask-trigger.PNG "AWS Lambda Trigger")
3. Zip the contents in `src/js` and upload in "Lambda function code".
4. Review and create the Lambda function.
5. After creation, take note of the ARN on the upper right, which you'll configure in the Developer Console below.

2. Create or login to an [Amazon Developer account](https://developer.amazon.com). In the Developer Console:
**TODO Change to Prod Account Screenshots**
1. [Create an Alexa Skill](https://developer.amazon.com/public/solutions/alexa/alexa-skills-kit/docs/developing-an-alexa-skill-as-a-lambda-function) named MySkill and using the invocation name "my skill" and select 'Yes' for Audio Player support.
![alt text](https://s3.amazonaws.com/lantern-public-assets/audio-player-assets/developer-portal-skill-information.PNG "Developer Portal Skill Information")

2. Copy the contents of `src/InteractionModel` into the Interaction Model tab.
![alt text](https://s3.amazonaws.com/lantern-public-assets/audio-player-assets/developer-portal-interaction-model.PNG "Developer Portal Interaction Model")

3. Copy the Lambda ARN from above in the Configuration tab.
![alt text](https://s3.amazonaws.com/lantern-public-assets/audio-player-assets/developer-portal-configuration.PNG "Developer Portal Configuration")

4. You can start testing the skill on your device or on the simulator now, but you can go ahead and fill in the Publishing Information and accept the Privacy & Compliance information to submit the skill for certification.


## How it Works

Alexa Skills Kit introduced the 'AudioPlayer' interface which provides directives and requests for streaming audio and monitoring playback progression. You can include AudioPlayer directives within your response to start and stop the playback. Alexa also sends "PlaybackController" requests in response to hardware buttons such as on a remote control. Below you can see how to create these directives.

With the Node JS Alexa-SDK, one can add an AudioPlayer directive by adding :
```javascript
this.response.audioPlayerPlay(playBehavior, url, token, expectedPreviousToken, offsetInMilliseconds);
this.response.audioPlayerStop();
this.response.audioPlayerClearQueue(clearBehavior);
```
##### AudioPlayer Play Directive :

```json
{
"type": "AudioPlayer.Play",
"playBehavior": "string - REPLACE_ALL || ENQUEUE || REPLACE_ENQUEUED",
"audioItem": {
"stream": {
"url": " string - HTTPS Stream Required",
"token": "string",
"expectedPreviousToken": "string",
"offsetInMilliseconds": 0
}
}
}
```

##### AudioPlayer Stop Directive :

```json
{
"type": "AudioPlayer.Stop"
}
```

##### AudioPlayer ClearQueue Directive :
```json
{
"type": "AudioPlayer.ClearQueue",
"clearBehavior" : "string - CLEAR_ENQUEUED || CLEAR_ALL"
}
```


In response to AudioPlayer directives, you receive **AudioPlayer Requests**. You can learn more about the [AudioPlayer Interface here](https://drive.corp.amazon.com/view/DevComm/ask-docs/custom-audioplayer-interface-reference.html). (**TODO Change hyperlink**)

## Audio Assets

Configure `src/js/audioAssets.js` to add your audio assets and enjoy building your own customized audio player skill.
- Single-stream folder contains an example skill to play a single stream, such as a live radio skill.
File renamed without changes.
87 changes: 87 additions & 0 deletions multiple-streams/README.md
@@ -0,0 +1,87 @@
# Audio Player Sample Project

Alexa Skills Kit now allows 3P-developers to build skills supporting Audio Player Interfaces. This sample project will showcase how developers can use long form audio in Alexa Skills.

## How to Get Started

Setup AWS and the Amazon Developer Console.

You can change the name of these resources to whatever you like later, but for now, setup the following items:

1. Create or login to an [AWS account](https://aws.amazon.com/). In the AWS Console:
1. Create an AWS Role in IAM with access to Lambda and DynamoDB.
![create_role_1](https://cloud.githubusercontent.com/assets/7671574/17451098/09f64f40-5b19-11e6-82ee-b82c98387052.png "AWS Create Role Screenshot 1")
![create_role_2](https://cloud.githubusercontent.com/assets/7671574/17451100/0c3ef928-5b19-11e6-9aca-8cd353106396.png "AWS Create Role Screenshot 2")
![create_role_3](https://cloud.githubusercontent.com/assets/7671574/17451101/0e3c5ff4-5b19-11e6-90f6-0210dae6f9dc.png "AWS Create Role Screenshot 3")

2. Create an AWS Lambda function named AudioPlayerLambdaFunction being sure to select the role created above and configuring "Alexa Skills Kit" as the "Trigger".
![alt text](https://s3.amazonaws.com/lantern-public-assets/audio-player-assets/aws-lambda-role.PNG "AWS Lambda Role")

![alt text](https://s3.amazonaws.com/lantern-public-assets/audio-player-assets/aws-lambda-ask-trigger.PNG "AWS Lambda Trigger")
3. Zip the contents in `src/js` and upload in "Lambda function code".
4. Review and create the Lambda function.
5. After creation, take note of the ARN on the upper right, which you'll configure in the Developer Console below.

2. Create or login to an [Amazon Developer account](https://developer.amazon.com). In the Developer Console:
**TODO Change to Prod Account Screenshots**
1. [Create an Alexa Skill](https://developer.amazon.com/public/solutions/alexa/alexa-skills-kit/docs/developing-an-alexa-skill-as-a-lambda-function) named MySkill and using the invocation name "my skill" and select 'Yes' for Audio Player support.
![alt text](https://s3.amazonaws.com/lantern-public-assets/audio-player-assets/developer-portal-skill-information.PNG "Developer Portal Skill Information")

2. Copy the contents of `src/InteractionModel` into the Interaction Model tab.
![alt text](https://s3.amazonaws.com/lantern-public-assets/audio-player-assets/developer-portal-interaction-model.PNG "Developer Portal Interaction Model")

3. Copy the Lambda ARN from above in the Configuration tab.
![alt text](https://s3.amazonaws.com/lantern-public-assets/audio-player-assets/developer-portal-configuration.PNG "Developer Portal Configuration")

4. You can start testing the skill on your device or on the simulator now, but you can go ahead and fill in the Publishing Information and accept the Privacy & Compliance information to submit the skill for certification.


## How it Works

Alexa Skills Kit introduced the 'AudioPlayer' interface which provides directives and requests for streaming audio and monitoring playback progression. You can include AudioPlayer directives within your response to start and stop the playback. Alexa also sends "PlaybackController" requests in response to hardware buttons such as on a remote control. Below you can see how to create these directives.

With the Node JS Alexa-SDK, one can add an AudioPlayer directive by adding :
```javascript
this.response.audioPlayerPlay(playBehavior, url, token, expectedPreviousToken, offsetInMilliseconds);
this.response.audioPlayerStop();
this.response.audioPlayerClearQueue(clearBehavior);
```
##### AudioPlayer Play Directive :

```json
{
"type": "AudioPlayer.Play",
"playBehavior": "string - REPLACE_ALL || ENQUEUE || REPLACE_ENQUEUED",
"audioItem": {
"stream": {
"url": " string - HTTPS Stream Required",
"token": "string",
"expectedPreviousToken": "string",
"offsetInMilliseconds": 0
}
}
}
```

##### AudioPlayer Stop Directive :

```json
{
"type": "AudioPlayer.Stop"
}
```

##### AudioPlayer ClearQueue Directive :
```json
{
"type": "AudioPlayer.ClearQueue",
"clearBehavior" : "string - CLEAR_ENQUEUED || CLEAR_ALL"
}
```


In response to AudioPlayer directives, you receive **AudioPlayer Requests**. You can learn more about the [AudioPlayer Interface here](https://drive.corp.amazon.com/view/DevComm/ask-docs/custom-audioplayer-interface-reference.html). (**TODO Change hyperlink**)

## Audio Assets

Configure `src/js/audioAssets.js` to add your audio assets and enjoy building your own customized audio player skill.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
19 changes: 19 additions & 0 deletions single-stream/.ask/config
@@ -0,0 +1,19 @@
{
"deploy_settings": {
"default": {
"skill_id": "",
"was_cloned": false,
"merge": {
"skillManifest": {
"apis": {
"custom": {
"endpoint": {
"uri": "ask-custom-myradio-default"
}
}
}
}
}
}
}
}
160 changes: 160 additions & 0 deletions single-stream/README.md
@@ -0,0 +1,160 @@
# Single Stream Audio Skill (My Radio)

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.

## Usage

```text
Alexa, play my radio
Alexa, stop
```

## Installation

You will need to change a few configuration files before to create the skill and upload the lambda code.

### Pre-requisites

This is a NodeJS Lambda function and skill defintion to be used by [ASK CLI](https://developer.amazon.com/docs/smapi/quick-start-alexa-skills-kit-command-line-interface.html).

You need to initialize ASK CLI with

```bash
$ ask init
```

You need an [AWS account](https://aws.amazon.com) and an [Amazon developer account](https://developer.amazon.com) to create an Alexa Skill.

You need to download NodeJS dependencies :

```bash
$ (cd lambda && npm instal)
$ (cd lambda/src && npm install)
```

### Required changes before to deploy

1. ```./skill.json```

Change the skill name, example phrase, icons, testing instructions etc ...

Remember than many information are 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.

2. ```./lambda/src/audioAssets.js```

Modify each value in the audioAssets.js file to provide your skill at runtime the correct value : your radio name, decsription, icon and, obviosuly, URL of your stream (https only).

To learn more about Alexa App cards, see https://developer.amazon.com/docs/custom-skills/include-a-card-in-your-skills-response.html

```javascript
var audioData = {
title: "<The title of the card for the Alexa App>",
subtitle: "<The subtitle of the card for the Alexa App>",
cardContent: "<The contect of the card for the Alexa App>",
url: "<your stream HTTPS URL>",
image: {
largeImageUrl: "<the HTTPS URL of your large icon for the Alexa App>",
smallImageUrl: "<the HTTPS URL of your small icon for the Alexa App>"
}
};
```

3. ```./models/*.json```

Change the model defintion to replace the invocation name (it defaults to "my radio") and the sample phrase for each intent.

Repeat the operation for each locale you are planning to support.


### Local Tests

This code is using [Mocha](https://mochajs.org/) and [Chai](http://chaijs.com/) to test the responses returned by your skill. Before to deploy, be sure to have no test failures.

Execute your test by typing

```bash
$ (cd lambda && npm test)
```

### Deployment

ASK will create the skill and the lambda function for you.

Lambda function will be creadted in ```us-east-1``` (Northern Virginia) by default.

You deploy the skill and the lambda function in one step :

```bash
$ ask deploy
```

You can test your deployment by FIRST ENABLING the TEST switch on your skill in the Alexa Developer Console.

Then

```bash
$ ask simulate -l en-GB -t "alexa, play my 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.

#### Change the skillid in lambda code. (Optional but recommended)

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 :

```bash
$ ask api list-skills
```
```json
{
"skills": [
{
"lastUpdated": "2017-10-08T08:06:34.835Z",
"nameByLocale": {
"en-GB": "My Radio",
"en-US": "My Radio"
},
"skillId": "amzn1.ask.skill.123",
"stage": "development"
}
]
}
```

Then copy/paste the skill id to ```lambda/src/constants.js```

```javascript
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

});
```

## On Device Tests

To be able to invoke the skill on your device, you need to login to 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 :

```text
Alexa, open my radio.
```

0 comments on commit 6991ead

Please sign in to comment.