Sunday, January 29, 2017

Amazon Echo - Alexa skills for ham radio

Demo video showing a proof of concept Alexa DX Cluster skill with remote control of Elecraft KX3 radio. 



Introduction

According to a Wikipedia article Amazon Echo is a smart speaker developed by Amazon. The device consists of a 9.25-inch (23.5 cm) tall cylinder speaker with a seven-piece microphone array. The device connects to the voice-controlled intelligent personal assistant service Alexa, which responds to the name "Alexa".  The device is capable of voice interaction, music playback, making to-do lists, setting alarms, streaming podcasts, playing audiobooks, and providing weather, traffic and other real time information. It can also control several smart devices using itself as a home automation hub.

Echo also has access to skills built with the Alexa Skills Kit. These are 3rd-party developed voice experiences that add to the capabilities of any Alexa-enabled device (such as the Echo). Examples of skills include the ability to play music, answer general questions, set an alarm, order a pizza, get an Uber, and more. Skills are continuously being added to increase the capabilities available to the user.

The Alexa Skills Kit is a collection of self-service APIs, tools, documentation and code samples that make it fast and easy for any developer to add skills to Alexa. Developers can also use the "Smart Home Skill API", a new addition to the Alexa Skills Kit, to easily teach Alexa how to control cloud-controlled lighting and thermostat devices. A developer can follow tutorials to learn how to quickly build voice experiences for their new and existing applications.

Ham Radio Use Cases 

For ham radio purposes Amazon Echo and Alexa service creates a whole new set of opportunities to automate your station and build new audio experiences.

Here is a list of ideas what you could use Amazon echo for:

- listen ARRL Podcasts
- practice Morse code or ham radio examination
- check space weather and radio propagation forecasts
- memorize  Q codes  (QSL, QTH, etc.)
- check call sign details from QRZ.com
- use APRS to locate a mobile ham radio station


I started experimenting with Alexa Skills APIs using mostly Python to create programs.  One of the ideas I had was to get Alexa to control my Elecraft KX3 radio remotely.  To make the skill more useful I build some software to pull latest list of spots from DX Cluster and use those to set the radio on the spotted frequency to listen some new station or country on my bucket list.


Alexa Skill Description

Imagine if you could use and listen your radio station anywhere just by saying the magic words "Alexa, ask DX Cluster to list spots."



Alexa would then go to a DX Cluster, find the latest spots on SSB  (or CW) and allows you to select the spot you want to follow.  By just saying "Select seven"  Alexa would set your radio to that frequency and start playing the audio.

Figure 2.  Alexa DX Cluster Skill output 





















System Architecture 


Figure 3. below shows all the main components of this solution.  I have a Thinkpad X301 laptop connected to Elecraft KX3 radio with KXUSB serial port and using built-in audio interface.  X301 is running several processes: one for recording the audio into MP3 files,  hamlib rigctld to control the the radio and a web server that allows Alexa skill to control the frequency and retrieve the recorded MP3 files.

I implemented the Alexa Skill "DX Cluster" using Amazon Web Services Cloud.  Main services are AWS Gateway and AWS Lambda.

The simplified sequence of events is shown in the figure below:

1.  User says  "Alexa, ask DX Cluster to list spots".  Amazon Echo device sends the voice file to Amazon Alexa service that does the voice recognition.

2. Amazon Alexa determines that the skill is "DX Cluster" and sends JSON formatted request to configured endpoint in AWS Gateway.

3.  AWS Gateway sends the request to AWS Lambda that loads my Python software.

4.  My  "DX Cluster" software parses the JSON request, calls  "ListIntent" handler.  If not already loaded, it will make a web API request to pull the latest DX cluster data from ham.qth.com. The software will the convert the text to SSML format for speech output and returns the list of spots  to Amazon Echo device.

5.   If user says  "Select One"  (the top one on the list), then the frequency of the selected spot is sent to the webserver running on X301 laptop.  It will change the radio frequency using rigctl command and then return the URL to the latest MP3 that is recorded. This URL is passed to Amazon Echo device to start the playback.

6. Amazon Echo device will retrieve the MP3 file from the X301 web server and starts playing.


Figure 3.  System Architecture



























Software 

As this is just a proof of concept the software is still very fragile and not ready for publishing.  The software is written in Python language and is heavily using open source components, such as 

  • hamblib   - for controlling the Elecraft KX3 radio
  • rotter       - for recording MP3 files from the radio 
  • Flask       - Python web framework 
  • Boto3      - AWS Python libraries
  • Zappa      - serverless Python services

Once the software is a bit more mature I could post it on Github if there is any interest from the ham radio community for this.  


73
Mauri AG1LE