I’m really starting to love my Arduino lately; having gone through the basic tutorials and even made an LED cube, I was ready to tackle something far more complex. Fortunately, speech controlling an Arduino project really isn’t as complex as I’d thought – so here are 3 distinctly different approaches you can take.
Using OSX Automator and Speakable Items
One way we can do this is utilizing the existing speech command utilities built into OSX; setting up custom commands to trigger Automator actions is simple. (If you’re unfamiliar with Automator, download our free PDF guide to automating your Mac!)
On the Arduino code side, we’re making use of a String buffer detailed on this Arduino forum thread – this enabled us to search for exact words in the serial communication – without this, I found the type conversions between numbers, bytes, and strings to be problematic. Here’s the full Arduino code for listening to serial commands, though you’ll need to add your own commands and hardware for actually controlling the devices, as that’s out of the scope of this Arduino project tutorial. If you’re using relays, remember they need to be able to handle 120-240vAC. Also, if you’re new to all of this, make sure to check out our beginner’s Arduino guide first.
Next, download this Arduino-serial utility which enables us to communicate directly with the Arduino from the command line or shell script. Place this in the root of your user directory, then open up a Terminal session and type:
to compile the package for your system.
Usage of this utility is fairly simple, but for our purposes, begin by typing
to figure out which port your Arduino is on (the USB one). Then to send a command, use:
./arduino-serial -b 9600 -p /dev/tty.usbmodemfd13411 -s lightsOn
Replace /dev/tty.usb~ with the exact name you found for your USB port connected to the Arduino. Refer to the original page for more usage examples including getting a return value, but this will do for now.
One thing I did find is that I had to “kickstart” the Arduino by sending a command using the Arduino Serial Monitor first, then everything worked fine. If anyone knows why this is the case, I’d love to hear.
Next up, open Automator and create a new Application. Find the Run a Shell Script action, add it, and paste in the serial command to turn the lights on.
Save that to the library/speech/Speakable Items folder with the words you’d like to trigger the action – in my case “lights on”.
Then, enable speakable commands from the Accessibility preferences panel.
This tutorial from 2009 is still relevant, but basically you want to enable the Global Speakable Items.
Here’s a demo of it all working.
Easy VR Shield (Hardware)
EasyVR is an add-on hardware shield that first encodes your pre-recorded speech samples then uses a hardware based solution for pattern-matching them. The setup is a little complicated, and each command only responds to a single voice imprint, but this is the most comprehensive choice if you want the project to be computer independant. The EasyVR Shield costs £35 from CoolComponents in the UK, or $50 from SparkFun in the US. Here’s a demo of the shield in action along with the encoding process:
SiriProxy Via Ruby
If you have a Siri capable iPhone that’s been jailbroken, Siri Proxy is a great way to harness the voice recognition capabilities of your phone. SiriProxy is a Ruby app that listens in on the commands being recognized and sent to Apple’s servers; add in a way to communicate with Arduino, and you have . The only downside is that you need to upload a special sketch to the Arduino that implements a Ruby API, so you’ll either need to adjust that, or code everything in Ruby on the computer side.
There you have it – 3 unique ways to control any Arduino project with your voice alone. Will you try voice controlling your lights? Do you think you could make use of these ideas in another project? Let us know in the comments!