Daily Archives

One Article

Posted by on

Sammy the Boblebot Part 12: Look Who’s Talking!

What fun is a robot if it can’t communicate? I want Sammy to be able to talk back to me and my kids and tell us what he’s doing. That means a text-to-speech engine, and specifically Flite, the lightweight version of Festival. I’ve played around a little bit with this in the past but only to the extent of making computers say things in funny sci-fi voices. Now I want to put it to use.

My initial idea is that Sammy should speak the status messages I introduced throughout the Arduino code to tell me what was going on. That means pulling messages off the serial connection from Arduino to Raspberry Pi and having something then feed that serial data into Flite.

Python is the obvious language for doing this sort of work. It’s the most popular programming language for RPi and there’s loads of example code out there. Which is good, because I’ve never done anything in Python before in my life.

So first thing’s first, off I went to CodeAcademy to learn the basics. Then I started hunting around for snippets I could weld together to do what I wanted.

I found this, from the father of home hacking in the UK, Simon Monk, which told me how to pull data off the serial output from the Arduino and do something with it in Python. And I found this, which told me how to pass text out to Flite (or actually eSpeak, a Flite alternative*, but it was easily adapted).

Now this is very simple, and arguably pretty ugly — neither the most efficient nor the most secure way of doing things. I’m sure real coders would have something to say about me passing commands from Python to the command line, especially when I know there are wrappers for Flite inside Python (the bit I haven’t covered here is all the stuff I couldn’t get to work, including these). But, it works for now and it’s a starting point on which to build, so I’ve posted my Python file here, along with a little video. The video shows Sammy responding to inputs from his ultrasonic range sensor. When something gets within 30cm it triggers his proximity alarm and he reports how far away it is (if you’re too young for the reference, ‘Danger Will Robinson’ is from Lost in Space).

You’ll notice the little amplified speaker: this is an early car hands free kit I’ve been hanging on to for ages because I thought it might come in handy for things like this. I hacked the mic off (it was that primitive it had a mic over your phone’s speaker) and added a 3.5mm jack. And I stripped off the 12v plug — for now replaced with a taped on 9v battery but ultimately this will run off Sammy’s new 12v power supply in the new chassis. The PC is in shot simply because my portable power supply was exhausted so this was powering the RPi.

Next, and finally before I start focusing on the new chassis, I want to get serial commands going the other way so that I can control Sammy over Wi-Fi…

*Why did I choose Flite over eSpeak? No good reason at all — I’d just started down that route already.

Tom Cheesewright