A small, easy-to-deploy Alexa skill that can stream YouTube videos. Inspired from jukebox.
- Play audio (and video if supported) from YouTube videos.
- Player-like behavior that allows you to skip forward/backward.
- Very easy to deploy, just run index.js:handle()
For incredibly easy deployment, I recommend the usage of AWS Lambda, which perfectly integrates with your Alexa Skill. You will need to set up AWS Lambda, and then integrate it with your Alexa Skill.
npm install # Or yarn install if you prefer
tsc
From there you will have an out directory with the compiled JavaScript files. With your favorite zipping utility you will have to zip the files contained in the out directory, as well as the node_modules directory. Be sure to not include the out directory itself, as you will have to change the handler in the runtime configuration if you do. I have also included a ytunes.zip file that you can use as a reference. You will need to upload this zip file to AWS Lambda.
- Create an AWS account if you don't have one already.
- Once created, go to the AWS Lambda console.
- From there, click on the "Create Function" button.
- Make sure the runtime is set to Node.js X.x, it should be the default. You can name the function whatever you want.
- Once created, you will be taken to the function's page. Click on the "Code" tab.
- From there, click on the "Upload from" dropdown and select "Upload a .zip file".
- Upload the zip file you created in the previous step, or the one included in this repository.
- Once uploaded, click on the "Configuration" tab. Under "Environment variables", add a new variable called "API_KEY" and set it to your YouTube API key. You can get one here.
3. Alexa Skill Setup: from jukebox
- Go to the Alexa Console (https://developer.amazon.com/alexa/console/ask).
- If you have not registered as an Amazon Developer then you will need to do so. Fill in your details and ensure you answer "NO" for "Do you plan to monetize apps by charging for apps or selling in-app items" and "Do you plan to monetize apps by displaying ads from the Amazon Mobile Ad Network or Mobile Associates?"
- Once you are logged into your account click "Create Skill" on the right-hand side.
- Give your skill any name, eg "My YouTube Skill".
- Important Set the language to whatever your Echo device is set to. If you are not sure, go to the Alexa app, go to Settings, Device Settings, then click on your Echo device, and look under Language. If your Echo is set to English (UK), then the skill must be English (UK), other types of English will not work!
- Choose "Custom" as your model, and "Provision Your Own" as your method, then click "Create Skill". On the template page, choose "Start from scratch".
- On the left hand side, click "JSON Editor".
- Delete everything in the text box, and copy in the text from https://raw.githubusercontent.com/ndg63276/alexa-youtube/master/InteractionModel_en.json, (or use InteractionModel_fr.json, InteractionModel_it.json, InteractionModel_de.json, InteractionModel_es.json for French, Italian, German or Spanish)
- Click "Save Model" at the top.
- Click "Interfaces" in the menu on the left, and enable "Audio Player" and "Video App". Click "Save Interfaces".
- Click "Endpoint" in the menu on the left, and select "AWS Lambda ARN". Under "Default Region", put the ARN of your Lambda function. You can find this by going to the Lambda console, clicking on your function, and copying the ARN from the top right. It should look something like this:
arn:aws:lambda:us-east-1:123456789012:function:myFunctionName
- Click "Save Endpoints".
- Copy your Skill ID which is in the same place as where you copied the ARN. It should look something like this:
amzn1.ask.skill.12345678-1234-1234-1234-123456789012
. You will need this later. - Click "Custom" in the menu on the left.
- Click "Invocation" in the menu on the left.
- If you want to call the skill anything other than "youtube", change it here. Click "Save Model" if you change anything.
- Click "Build Model". This will take a minute, be patient. It should tell you if it succeeded.
- Important: At the top, click "Test". Where it says "Test is disabled for this skill", change the dropdown from "Off" to "Development".
- Go back to your lambda function, and click on the "Add trigger" button. You will select Alexa Skills Kit as the trigger.
- Paste your Skill ID in the Skill ID field.
- Click "Add" at the bottom.
Like all Alexa skills, use the invocation name "youtube" or whatever you want to set it to. For example:
- In English, say "Alexa, launch YouTube".
- In German, say "Alexa, öffne YouTube".
- In Italian, say "Alexa, avvia YouTube".
- In Spanish, say "Alexa, abrir YouTube".
- jukebox - This project was inspired by the jukebox project, which is a similar project that allows you to stream music from YouTube, written in Python, which is a fork of a project called alexa-youtube, a paid project.