Introduction

Have you ever wanted to ask Alexa to play the audio of a YouTube video? Just say “Alexa, Ask Hey Tube to play Whitesnake” and listen to a great Whitesnake track from YouTube.

In this article, I will show how to build a Custom Alexa Skill to connect your Amazon Echo device to YouTube.

Note: Keep in mind this skill will not be published in Amazon Store production, and can only be used in development mode. This is not an Amazon approved Skill and should only be used for educational purposes.


Alexa Custom Skill

The Alexa custom skill is a combination of two main components:

Image for post

https://github.com/bignerdranch/developing-alexa-skills-solutions/blob/master/coursebook/coursebook.pdf

The skill interface defines how your skill will behave:

  • A set of “intents” that represent actions that users can do with your skill.
  • A set of “sample utterances” that specify the words and phrases users can say to invoke those intents. You map these utterances to your intents — this mapping forms the “interaction model” for the skill.
  • An “invocation name_”_ that identifies the skill. The user includes this name when initiating a conversation with your skill.

The skill service contains your code logic to handle the intents and perform actions. The service is deployed as a backend resource. For this exercise — JavaScript deployed in AWS Lambda


Skill Flow

This is the custom skill flow to be developed:

Image for post

  • The flow starts with a welcome message and expects a video query name.
  • When asked to play a certain video, Alexa Interface calls the service using the query as the parameter.
  • The service calls YouTube API to search for a video, then returns the URL to Alexa.
  • Alexa starts playing the audio from the video URL.
  • At any time the user can ask Alexa to stop playing. Alexa will stop the audio track and say “Goodbye”.

Let’s Start

The easiest way to create a new Alexa Skill is by using ASK CLI**.**

Before starting, make sure you have an Amazon Developers Account, Node installed, AWS Account, AWS CLI, and ASK CLI installed.

For a complete detailed guide setup of your environment check out my previous article Quickly Build an Alexa Skill Using ASK CLI.

Let’s start by creating the new skill structure: $ ask new:

Image for post

ask new

Select:

  • NodeJS as the programming language
  • AWS Lambda as the backend resource
  • Hello world as the starter template
  • Choose a skill name: alexa-skill-heytube
  • Choose a folder name: alexa-skill-heytube

Change to your new directory:$ cd alexa-skill-heytube/lambda

Install your packages: $ npm install

#alexa #javascript #programming #lambda #amazon-echo

How to Play YouTube Audio From Your Alexa
4.60 GEEK