Alexa, amazon’s voice-based virtual assistance like Siri for the iPhone, and Cortana for Microsoft Windows, is a cloud-based service. When first introduced, it was in the form of ‘Amazon Echo.’ Fast forward and this voice assistant is now part of multiple devices including: music devices, robots, mobile phones, vacuum cleaners, among other things. Its skills are voice-driven and the interface between users and Alexa is called ‘Skills.’
Creating Alexa skills
Alexa skills are built by two different components:
- The voice controls or actions
- The functionality
In this article we’ll evaluate how to set up both, starting with the functionality.
The functionality is simply some code that will be executed when Alexa is tasked with our custom actions (or skill). This code for our purposes will run on AWS Lambda, a service matching perfectly with Alexa, it’s cost-efficient and super easy to set up.
Here are all the steps we need to take into account when building an Alexa skill:
- Set Up AWS (Amazon Web Services) Lambda
- Create a free Alexa Developer Account
- Create a sample of Alexa Skill
- Test the newly created Alexa skill
So let’s start with the first step:
Setting up an AWS (Amazon Web Services) Lambda
- Go to the Amazon Web Services management console and create a new account if you don’t have one already. Click on the “Complete Sign Up” button.
- After adding the appropriate data in all the required fields, login to the AWS management console. Keep in mind that AWS is a paid service, though they offer a trial period of 1 year with certain limitations, but it’s more than enough for what we want to do.
- After the successful login, the AWS management console dashboard will be displayed to you.
- Different web based services are available of AWS portal. From the find services list, search for the “Lambda” service. Select the “Lambda” service.
- Lambda service only works in the US East (N. Virginia), EU (Ireland), US West (Oregon), and Asia Pacific (Tokyo). Make sure to choose one of the given regions before creating the Lambda service.
- After choosing the “Lambda” service you will be redirected to the Functions screen. Choose the “Create function” option.
- Click on the “Use a blueprint” option and search for the “Alexa-skills-kit-color-expert-python”.
It’s worth noting we’ll use a blueprint for sample, a blueprint is an already developed sample which can be easily added to your AWS lambda account. If you want to build your own skills, you can either program the lambda yourself, or use the blueprint and update it to your needs.
There are blueprints for Python, NodeJS and other programming languages, in our case we will use one based off Python, though we will ignore the code for this tutorial and focus more on the Alexa side of things.
- If the results are not displayed under the “Use a blueprint” section, then select the third option “Browse serverless app repository” and search for the “Alexa-skills-kit-color-expert-python.”
- Now enter the “TopicNameParameter” and click on the “Deploy” button.
- Now click on the “Logical ID” text.
- The function code will be displayed to you. Copy the “ARN” code displayed to you on the “top right corner”.
Creating your free Alexa Developer Account
Now we have to create an Alexa Developer Account. Go to the Amazon developer portal and create an account if you don’t have an account already. While creating the new account, add the appropriate data in all required fields.
Just sign in to the Amazon developer portal if you have signed up already.
Create a sample of Alexa Skill
Here is where we build the actual Alexa interface, that is how we’re going to talk to Alexa to solve our problems and communicate with our Lambda function.
Follow all these steps carefully:
- Now choose the “Alexa” option from the dashboard and select “Alexa Skills Kit.” You will be redirected to the “Alexa developer console.”
- Click on the “Create Skill” button.
- Enter the skill name, choose the language, and click on the “Create Skill” option.
The skill name can be anything you want, keep it meaningful to what you are trying to achieve. But don’t confuse the name with the phrase you will use to invoke Alexa to perform the task. The name is only for your reference.
- Enter the skill invocation name. This is what you will have to say to Alexa when communicating with your skill.
- On the Alexa skill dashboard, you will the list of your created skills. Click on “MyBookSkill.”
- Take a look at the sample intents to understand how you can create your own intents.
With the invocation name you told Alexa to “talk” to your program, now intents, will tell your program exactly what procedure to execute. They can be anything your program can perform, like “find a book”, or “read Live Code Stream.”
- For creating your own intent, click on the “Add Intent ” button.
- Enter the name of intent and then enter the utterances.
- Now choose the slots type from the left menu and click on “Add slot type.”
Slots allow you to create lists of possible values, IDs and synonyms. Often times they’re generated by code, but for now we’ll set them up manually.
- Enter the name of the slot type. I have entered here “BOOK_TYPE”, and after that enter the values.
- Enter all the values and then click on the “Build model.”
- Now click on the endpoint section from the left menu and enter the Lamba ARN value.
- After entering the ARN value, click on the “Save endpoints” option.
Alexa skill is now successfully created.
Test the newly created Alexa skill
After the implementation of the Alexa skill, we have to test it. The testing verifies the either we’re achieving our desired results or not?
We can test the Alexa skill in many ways:
- We can deploy the Alexa skill on Amazon devices i.e. Amazon Echo Dot, Amazon Echo, or on any other device which supports the deployment of Alexa.
- We can test the Alexa skill by using the simulator. Just say the skill invocation name that you have written while creating the Alexa skill.
This is the fun part, so enjoy it.
Alexa, and voice assistants in general are here to stay, and the success of your product or services may be limited by the integration that these systems will present in the future.
So grab yourself some time and take a look into the endless possibilities these assistants give to users and developers alike.
This article was originally published on Live Code Stream by Juan Cruz Martinez (twitter: @bajcmartinez), founder and publisher of Live Code Stream, entrepreneur, developer, author, speaker, and doer of things.
Live Code Stream is also available as a free weekly newsletter. Sign up for updates on everything related to programming, AI, and computer science in general.