Using voice-controlled interfaces via Amazon Alexa
Skills in Detail
To understand more exactly how an Alexa skill is composed, it is worth taking a look at its individual components. The skill describes an interaction model that summarizes all behaviors and components. The interaction model itself consists of a number of components.
The invocation is the name of the Alexa skill and serves as a keyword for its activation. You'll need to follow some rules when assigning names – the Alexa website explains them in detail.
An intent describes an action that the user wants to perform within the skill. The individual intents require at least one defined keyword (sample utterance), which starts the action. If required, several sample utterances can be stored for each intent – for example, the variants "affirmative," "exactly," and "yeah" for the simple "yes." The more meaningful the utterances for an intent, the more reliable the skill becomes.
The slot types are self-defined data types that are used within the skills. The idea behind the slot types is similar to the enumeration data types known from almost all programming languages. For example, when asking for a car brand, the slot type could be car brand and contain values such as BMW, Audi, or Ford.
With the JSON editor, a simple text editor, the user edits the individual components of the skill directly in the interface. Although this task requires appropriate know-how, it makes it easier to keep track of complex skills.
In the Interfaces section, the user integrates multimedia content directly into an Alexa skill. Currently you will find three interfaces: Audio Stream, Video Stream, and Display Interface.
The endpoints determine which services the Alexa skill should communicate with on the Internet. In the present case, Raspberry Pi, which is linked to the skill via the Ngrok service, acts as the endpoint.
The sample skill needs to control three devices: a TV set, the light, and a socket outlet. To implement this, you create an intent for each of the three devices. Each intent supports the commands that name the corresponding device and transmit its status. The House command acts as the keyword. Define it below Invocation and then press the Save Model button (Figure 6). From experience, I can only advise readers to save more often than you might think necessary, rather than wondering later on why the skill does not work as it should.
Slots and Intents
A slot type named GPIO transmits the status of the individual devices. GPIO can assume one of two values: on and off. The slot type can already be created at this point. Press Add to the right of the Slot Types entry in the sidebar.
When you get there, select a custom slot type and assign the name of GPIO (Figure 7). Then, on the following page, assign the on and off values. To save the values, remember to press Save Model at the top.
On top of this, you now create the intents. You could do this manually by clicking your way through the individual dialog boxes. However, to reach this goal far faster, simply copy the content from Listing 4 to the interaction model using the JSON editor.
Listing 4
Intents
Make sure that the intents in the interaction model use the same names as in the Python program, otherwise you can expect trouble later on when you try to execute the skill.
In addition, the skill must be saved after each change to the interaction model and then rebuilt by clicking on Build Model. If you forget this step, nothing happens and you keep the old model.
Now only the communication between the skill and the Python program is missing. Click on Endpoint and select the HTTPS option. In the Default Region field, enter the URL currently used by Ngrok. In the drop-down box below, also enable the option labeled My development endpoint is a subdomain of a domain that has a wildcard certificate from a certificate authority (Figure 8). A click on Save Endpoints in the dialog header saves the changes.
After all configuration work has been completed, you need to build the skill for the first time. The Build Model switch appears on all pages where the model can be changed. Click on Invocation and then on Build Model.
For an initial test, change to the tab labeled with the name of the skill. Test mode can be enabled using the slider below the tab bar. Then enter the activation keyword, House, in the text box. The skill should then immediately welcome you in Australian. The connected devices can then be switched. The LEDs on the Raspberry Pi's GPIO prove that the skill works.
Controlling this with Amazon Echo should work the same way: The Start house voice command loads the skill, then the TV on command switches on the TV set.
Conclusion
Alexa provides an easy path for adding voice activation to your Raspberry Pi automations, but you'll need to set up a tunnel and do a little basic programming. This article offers a simple example for how to get Alexa talking to your RaspPi. Once you have established a communication channel, the possibilities for your voice-activated Raspberry Pi are endless.
« Previous 1 2 3
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
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.
News
-
Linux Kernel Reducing Long-Term Support
LTS support for the Linux kernel is about to undergo some serious changes that will have a considerable impact on the future.
-
Fedora 39 Beta is Now Available for Testing
For fans and users of Fedora Linux, the first beta of release 39 is now available, which is a minor upgrade but does include GNOME 45.
-
Fedora Linux 40 to Drop X11 for KDE Plasma
When Fedora 40 arrives in 2024, there will be a few big changes coming, especially for the KDE Plasma option.
-
Real-Time Ubuntu Available in AWS Marketplace
Anyone looking for a Linux distribution for real-time processing could do a whole lot worse than Real-Time Ubuntu.
-
KSMBD Finally Reaches a Stable State
For those who've been looking forward to the first release of KSMBD, after two years it's no longer considered experimental.
-
Nitrux 3.0.0 Has Been Released
The latest version of Nitrux brings plenty of innovation and fresh apps to the table.
-
Linux From Scratch 12.0 Now Available
If you're looking to roll your own Linux distribution, the latest version of Linux From Scratch is now available with plenty of updates.
-
Linux Kernel 6.5 Has Been Released
The newest Linux kernel, version 6.5, now includes initial support for two very exciting features.
-
UbuntuDDE 23.04 Now Available
A new version of the UbuntuDDE remix has finally arrived with all the updates from the Deepin desktop and everything that comes with the Ubuntu 23.04 base.
-
Star Labs Reveals a New Surface-Like Linux Tablet
If you've ever wanted a tablet that rivals the MS Surface, you're in luck as Star Labs has created such a device.