Equipping Alexa with self-programmed skills

More than a Word

Article from Issue 199/2017

Asking Alexa only for built-in functions like the weather report gets old quickly, and add-on skills from the skills store only go so far. With a few lines of code, Mike teaches this digital pet some new tricks.

Okay, I admit, I don't like getting up from the sofa to check out something on the Internet if my phone is out of reach. But who does? In the household of the future, a device like Amazon's Echo will be around to help you with things like this in the form of a tin can in the living room. The Amazon Echo Dot, which looks much like a hockey puck (Figure 1), is the successor to the tin-can-like Echo device and offers the same voice interface at a lower price point.

Figure 1: The Echo Dot Bluetooth speaker.

Amazon's dream, of course, might be that customers at home will just shout "Alexa, order toilet paper," to send the language assistant scurrying off to place the order with the Internet discounter, who then quickly dispatches a drone to deliver the much-needed household item to the anxiously waiting consumer.

Supposedly Safe

While the device constantly listens in the room, waiting to respond to the spoken word, it is in a kind of twilight state most of the time and does not forward incidental noise picked up by the microphone to the Amazon Cloud for analysis, according to the provider. Instead, the voice assistant waits for the user to speak what is known as the wake word, usually "Alexa," before activating the speech recognition-enabling connection to the Amazon Cloud. Instead of "Alexa," "Amazon," or "Echo," Star Trek fans can switch the wake word to "Computer" (Figure 2) and then talk to the assistant just as Captain Jean-Luc Picard spoke to the on-board computer on the bridge of the starship Enterprise.

Figure 2: Star Trek fans can now wake up Alexa by saying "Computer."

Teaching Alexa New Tricks

Out the box, Alexa can answer simple questions. Skills [1], which are free thus far (but might well switch to the app payment model sometime in the future) are available from the Skills Store [2] (Figure 3). Skills are basically software packages programmed and published by third parties, much like apps in the App Store. From reading current share prices in a customized stock portfolio ("Motley Fool") through playing a game of Jeopardy, to controlling lamps in your smart home, you have a lot to choose from.

Figure 3: The most popular skills in the Alexa Skills Store on Amazon.

To teach Alexa a skill, you activate one in the Alexa smartphone app or simply speak into the microphone (e.g., "Alexa, enable The Fool"). A short time later, Alexa is familiar with the stock market via the Motley Fool skill and answers questions like "Ask The Fool how is the market doing today" or "Ask The Fool to add Microsoft to my watchlist."

If your fingers are itching at the thought of teaching Alexa to dance to your own tune, you can visit Amazon Developer Services [3] to set up an Alexa account, which is separate from Amazon's AWS business, designed for the development of Android apps (Figure 4). After approving the agonizingly long terms of service, click on the Alexa tab and then on Alexa Skills Kit [1] to view a list of home-grown skills programmed thus far (Figure 5), along with a button that reads Create New Skill.

Figure 4: Developing new Alexa skills on developers.amazon.com.
Figure 5: User-developed Alexa skills.

Snapshot Output On-Call

As a practical example, I want Alexa to report on demand the title and date of the latest edition of the Snapshot programming column. To do so, Alexa reads a JSON file articles-en.json from my site at Perlmeister.com behind the scenes. The file lists all the issues in reverse chronological order (Figure 6), picks up the first entry from the long list, extracts the month and year, and passes the two values back to the language processor, which in turn announces them to the user via the Echo Dot.

Figure 6: The Snapshot articles in JSON format as a data source for Alexa.

If I say, "Alexa, ask Latest Snapshot for issue," then Alexa forwards the question to the Latest Snapshot skill, which then retrieves and processes the data and returns an answer such as 04 2017, Home Run into the Cloud (if the April issue happens to be the latest published Linux Magazine).

The developer defines the name of the newly taught skill to which Alexa delegates requests below invocation name in the web flow for new skills. Several words are allowed, but they must not contain keywords used elsewhere (e.g., "Alexa").

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • Mycroft

    Voice-activated assistants like Mycroft bring online, hands-free help to users, but with more transparency and less spying.

  • Programming Snapshot – Multilingual Programming

    We show you how to whip up a script that pulls an HTTP document off the web and how to find out which language offers the easiest approach.

  • Edge Computing

    After the cloud came the Edge. We take a look at the Edge computing phenomenon and attempt to assess what all the fuss is about.

  • FOSSPicks

    Graham tears himself away from updating Arch Linux to search for the best new free software.

  • Welcome

    Is the whole high-tech scene imploding? If so, it won't be the first time, but every time it implodes, it comes back a little different, so even temporary implosions are relevant.

comments powered by Disqus
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters

Support Our Work

Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.

Learn More