Using voice-controlled interfaces via Amazon Alexa
Control Program
Since the running Ngrok server is now blocking the current terminal, it makes sense to open a second terminal window. In it, create a text file named house.py
with the contents from Listing 2. This Python program calls the Alexa skill later on. The program provides a server that controls three devices: a TV set, a lamp, and a socket outlet.
Listing 2
house.py
For each of the three devices, the program has what is known as an intent, which controls exactly this one function. The corresponding decorators @ask.intent()
define the functions that the intent then executes as an action when called.
Say Hello!
The @ask.launch()
decorator displays a friendly greeting text. In this example, the Australian "Gooday" is used, a greeting that would be appropriate at any time of day.
In the functions, the commands necessary for controlling the GPIOs are executed. The Flask framework abstracts the complexity behind a skill very well. Further data can be found in the templates.yaml
resource file. The file must reside in the same directory as the Python program that communicates with the skill. This file contains texts that the skill will use. This makes it easier to adjust the speech output if necessary, for example to change the greeting or to enter other devices. The quite compact resource file for the example from this article is shown in Listing 3.
Listing 3
templates.yaml
§§number 01 greeting: Gooday 02 TV: TV is {{status}} 03 light: Light is {{status}} 04 socket: Socket is {{status}}
The shell python house.py
command starts the Python server. Ngrok and the Python program simply keep running after that. Of course, you cannot close any of the terminal windows afterwards. You need to make sure that Ngrok is running when the Python server enters the scene, otherwise the connection between the Echo skill and the server program cannot be established.
Setting up an Alexa Skill
For the next step when programming an Alexa skill, the Echo device you use must be activated. You first need an Amazon Web Services (AWS) account, which can be obtained free of charge on the AWS homepage. All you need is a credit card and a mobile phone connection.
You can now create a new Alexa skill via the AWS account. The easiest way to get there is via the list of current Alexa skills, which is empty for a new user account (Figure 4). There the user clicks on the Create Skill button to create a new skill.
The skill should then be given a descriptive name and a desired language. A mouse click on the Next button takes you directly to the next step of choosing the Custom model: it offers the highest degree of flexibility.
Another click on the button Create Skill closes the wizard. Now the homepage belonging to the new skill appears (Figure 5). Here you can set further parameters of the skill. The video under "How to get started" at the top of the page helps you to get started with the subtleties of skill creation.
« Previous 1 2 3 Next »
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
-
NVIDIA Released Driver for Upcoming NVIDIA 560 GPU for Linux
Not only has NVIDIA released the driver for its upcoming CPU series, it's the first release that defaults to using open-source GPU kernel modules.
-
OpenMandriva Lx 24.07 Released
If you’re into rolling release Linux distributions, OpenMandriva ROME has a new snapshot with a new kernel.
-
Kernel 6.10 Available for General Usage
Linus Torvalds has released the 6.10 kernel and it includes significant performance increases for Intel Core hybrid systems and more.
-
TUXEDO Computers Releases InfinityBook Pro 14 Gen9 Laptop
Sporting either AMD or Intel CPUs, the TUXEDO InfinityBook Pro 14 is an extremely compact, lightweight, sturdy powerhouse.
-
Google Extends Support for Linux Kernels Used for Android
Because the LTS Linux kernel releases are so important to Android, Google has decided to extend the support period beyond that offered by the kernel development team.
-
Linux Mint 22 Stable Delayed
If you're anxious about getting your hands on the stable release of Linux Mint 22, it looks as if you're going to have to wait a bit longer.
-
Nitrux 3.5.1 Available for Install
The latest version of the immutable, systemd-free distribution includes an updated kernel and NVIDIA driver.
-
Debian 12.6 Released with Plenty of Bug Fixes and Updates
The sixth update to Debian "Bookworm" is all about security mitigations and making adjustments for some "serious problems."
-
Canonical Offers 12-Year LTS for Open Source Docker Images
Canonical is expanding its LTS offering to reach beyond the DEB packages with a new distro-less Docker image.
-
Plasma Desktop 6.1 Released with Several Enhancements
If you're a fan of Plasma Desktop, you should be excited about this new point release.