Sheep In Wolf’s Clothing

Image from the Far Side, by Gary Larson
Image from the Far Side, by Gary Larson

We’ve all heard the term “Wolf in Sheep’s Clothing” before.  It represents some malicious entity masquerading as something benign, hoping to gain some advantage.  The other day, I came across something quite the opposite when working on HAPP.  I was stuck on a problem for a long time, but I ended up with a solution born out of that dilemma.  I found a “Sheep in Wolf’s Clothing”.

A lesson I learned a long time ago in software architecture is the idea that sometimes a deferred architecture is the best.  Whenever you are faced with indecision in an architecture, it typically is a place where you should encode a customization point, because if you aren’t sure of it now, you can bet you will want to change it later.

The same thing comes up with roadblocks and problems.  It takes some mindset shifting, but you have to treat these as opportunities in disguise.  I was working on HAPP, trying to get voice commands to work on my new Linux Laptop.  However, for those of you who have debugged audio on linux, it requires years of arcane black magic to make heads or tails of what you need.  I spent a few days trying to get things to work, using pulseaudio, midi controllers, jack, and so on and so forth to no avail.  I want to be able to run HAPP on my linux computer, but now I was finding I couldn’t.

The opportunity here is that maybe my input was too constrained.  Yes, the whole point of HAPP is to voice-automate my house, but maybe I needed to expand.  I allowed input to be handled in a separate thread from the console.  I now had a way to inject commands, test them out, and see the results all though my console.

This opens up a whole new world of ideas.  Rather than just making voice commands, I abstracted out the code to allow multiple input methods.  Now, I could consider unit testing commands, without needing voice.  I could distribute the voice recognition to other processing devices in my house ( like a phone, or what a great idea to start learning about something like a Raspberry Pi).  Eventually I would like to have a distributed voice recognition network, so this was a great first step.  This also provided a catalyst for me to create a config file to indicate which input methods are valid, which I will need for other things.

So next time you come across a problem, think about what opportunities it presents.  Find a way to be creative and let that evolve your program.  Don’t skimp requirements (I still have my main voice server working on Windows), but let the pain points guide you in what could be flexible.  You may just find your own “”Sheep in Wolf’s Clothing”

Intro to HAPP

So I mentioned HAPP in my last post, but didn’t get into too much detail about what I’m working on.  As I said last time, I have always wanted something to do with home automation, and I needed a project for Hack Huntsville.

So my first idea was that I wanted to voice control Pandora.  When I’m across the room and I want to change a song, I’m too lazy to get up and change the song.  (Pathetic, I know).  So I started a project in Python.

At first, I wanted to find out SpeehRecognition.  I found a nice library, which of course needed some audio library as well (they suggested pyaudio, which I also downloaded.  I spent two hours trying to get my microphone to work (and went through a few different speech libraries in the meantime).  It must have been comical at the Hack-a-thon, because here I am shouting at my computer in a crowded room, or walking around trying to find a quiet place.  The looks I got were pretty good.

However, I started digging into the API (always look into the API further when you are stuck, a lesson I learn again and again.)  I found that you could tweak some microphone settings, and it turned out that my settings were not so ideal for a crowded room.  After playing with energy thresholds, I was able to finally see the text “HELLO” appear on my screen (I had it printing out any words it could decipher).

After a quick burst of elation, I knew that I could figure out quite a bit from there.  I was trying to decide what to call my project at this point.  Iron man has JARVIS, Eureka had S.A.R.A.H, and I wanted some cool name to go with mine.  I started off by keying off the words “Hey, Listen”, but did not want to go with Navi.  I wanted a name, just like KITT or HAL from media past.  I’m a sucker for acronyms, and eventually I thought of HAPP, or Home Automation Personal Project.  As a bonus, the python script is, which is how I was feeling while I was working on the Hacka-thon project.

So I was able to enter in my first command and needed to know what to do next.  I had quite a bit of familiarity with Selenium, so I decided to open up a Pandora Window in Selenium with a default station (Dave Matthews Band of course).  You can see that work here.   From there, coding up an exit, and a “next song” feature weren’t too bad.  Within about three hours total, I went from nothing to being able to start/stop/skip songs on Pandora.

I decided to take things a little bit further and added a new voice command “tornado warning” to pull up weather.  Then, as a spur of moment idea, I wanted the computer to talk back.  At a recent PyHSV talk, I showed what GhostDriver can do with Python.  It pretty much opens up a headless web browser, and lets me control it through Python.  Knowing this tool, I settled on wanting to get the temperature from the computer when I ask it.  After quick download of python text to speech (pyttsx), I was in the business.

Ended up being a piece of cake, and I was ready to call it quits on the night.  I had already worked a full day and had no intention of staying through the night.

All in all, I got a handful of voice commands to work, had the computer speaking back to me, and was on the road to automating the things that I want for my house.  Its a long way to light switches and thermostats, but if I can control my computer with voice commands, I think that’s a pretty good start.

My next step is to clean up the code a bit ( make it a little less hacky).  This involves config files, Python 3 conversions, and making it work on linux.

Maybe by next post, I can share some of the technical fun that I got to explore.

Obligatory First Blog Post

We all know the drill by now. Everyone has to get their first blog post written, explaining why they are blogging, why people should read the blogs, and so on and so forth.

Well, I’m not feeling creative enough to stray from that template.  I’m mainly writing this blog for my own purposes.  I like writing, and I want a way to talk about what I’m doing, but in no way do I expect a large readership following.

This probably will be a very technical blog.  I might talk about any projects I am working on, books I’m reading (mostly software), and topics that interest me.

I’d first like to write down some notes on my first Hack-a-thon project.  At least, my first public one.  I’ve participated in 6 Hack-a-thons at ADTRAN, where I work, but just recently participated in Hack Huntsville (the very first one).  It wasn’t a formal Hack-a-thon; it was more of a chance for people to work on cool side projects.

I’ve always wanted to automate our house, but don’t feel like our technology is there just yet.  There are plenty of projects out on GitHub, and in honesty, they are superior to my ideas, but I wanted to see what I can build.

Thus, the birth of HAPP.  You can find my code here:  As of today, this was what I got done in about 4 hours in Hack-a-thon.  I see Hack-a-thons as a way to learn something new, so I wanted to learn python speech recognition and text to speech.  Couple this with automation, and I had a project.

Now, this code is far from feature complete, it is just hack-a-thon code.  But I plan to flesh it out – more tweaks, config files, better speech recognition.  I hope to document the journey along the way.