Alexa for Developers in 150 lines of Python

Steve Froehlich
5 min readOct 21, 2020

A week or so ago I was working on a software project. I got into a good flow and was making progress. Then I started getting DM’d by numerous people, some urgent emails came in, I ran into a technical issue in the code I needed to solve. It got a bit overwhelming and my productivity plummeted. I know the logical answer is, just tune out and ignore the DMs and emails, they can wait. After all, nothing will get done if I allow myself to be constantly interrupted. However I thought to myself, what if I can effectively handle all of it? If I could figure out how, would it make me a more productive developer? I concluded it might, and that chance was worth the time to explore it.

At the time described above I was coding in my IDE and didn’t want to change the screen or leave what I was doing in any way. Most multi-tasking is not really multitasking, its just context switching. That type of multitasking makes you look and feel productive, but in reality slows you down. There is another more effective type, when you are doing manual labor (for example mowing the lawn, doing dishes, laundry, etc) and listening to a podcast, you are actually multitasking. You complete the tasks with the same level of quality whether you do them separately or concurrently. Manual labor is low cognitive load and listening to technical podcasts, like I do, I consider moderate to high cognitive load. The hypothesis is if I combine a high cognitive task with low cognitive tasks I should be able to effectively multitask, as long as I don’t need my hands to do both. For example a high cognitive task could be coding or designing. A low cognitive task could be a simple DM/email response or information lookup. I attempted to create this type of multitasking by combining voice commands with bash aliasing.

What is a voice alias? The experiment.

The solution I decided to explore is built on the idea of bash alias. Bash aliases make my life a lot easier and my development more productive. So I thought, what if I could use voice commands to activate my bash alias instead of having to type in a terminal? I could create aliases or scripts for the tasks I wanted to automate, then trigger them via voice commands while I’m doing other tasks. Based on my hypothesis above I want to try automating my low cognitive tasks. When I looked at which tasks I do the most, I found like many Alexa users, they were checking the weather and playing music. So those are the tasks I added to the proof of concept application. For simplicity I’ll refer to the proof of concept application as Devbot. I see Devbot as sort of a robot butler, doing the tasks I don’t want to spend time on.

Devbot is a python application that you start like any other python script (python devbot.py). It will then run in the background and listen for the wake word. The default wake world is “Alfred” but it can be easily changed (steps described in Readme). I have two aliases I use a lot to check the current weather and the hourly forecast. They are:

alias wx='open https://weather.com/weather/today/l/f892433d7660da170347398eb8e3d722d8d362fe7dd15af16ce88324e1b96e70'alias wxh='open https://weather.com/weather/hourbyhour/l/f892433d7660da170347398eb8e3d722d8d362fe7dd15af16ce88324e1b96e70'

(Note my aliases use the open program that is default on mac laptops. So if you are not on a mac you may need to update the alias to work with your OS)

Now to add a voice alias just update the CSV file with the voice command you want. The format is

my voice command, myAlias

For example the voice aliases for wx and wxh are:

whats the weather,wx
whats the hourly weather,wxh

The actual CSV file can be found here Once installed you can, start Devbot and then say “whats the weather” (assuming you added the above alias already) and the weather forecast should open up in your default browser.

I also added the ability to add plugins or other python scripts. The logic to play music via voice is implemented as a plugin. I saved a YouTube video of classical music I often listen to in a text file named classical.txt. I can play the audio for this with the voice command: “Alfred play classical music”. Different parts of that phrase are mapped to different parts of the program. For example “Alfred”, is obviously is the wake word. “Play” is the command that maps to the YouTube playing plugin. “Classical” will tell Devbot to look for a file named classical.txt under the actions/youtube_playlists/ folder and play the video in that file. “Music” is thrown out. I say it because that is how I would normally tell someone to perform that task. I just prefer the interactions to sound more conversational, but “Alfred play classical” would do the same thing. The main piece of technology that makes Devbot possible is the speech to text engine. The one that I’m currently using is the Google Speech Recognition engine. Its job is to take the audio input and convert it into text that Devbot can parse and understand. It’s worth mentioning that the responsiveness of Devbot in its current form is below that of Alexa or other smart home devices. Hopefully I can improve it with time, but I do get annoyed every once in a while by having to repeat myself or wait a bit for processing. So user beware, this is not production ready software…yet.

So far Devbot has made programming and web browsing on my mac more enjoyable. I didn’t realize how much I like to be able to use voice commands to do dev tasks. That was an unexpected benefit. I have seen a mild productivity increase. However this is just the first iteration. To really test my hypothesis I will have to add more functionality for sending DMs/emails, maybe running test suites and kicking off deployments. Checking the details of test failures for known issues could be another enhancement. As long as the task can be automated and takes relatively low cognitive effort its a candidate for a voice alias.

--

--

Steve Froehlich

I like to speculate about the future and help engineering teams build great software in e-commerce and digital finance.