Raspberry Pi Tracked Robot – streaming video and text to speech

with 6 comments

For phase two of my Raspberry Pi based robot (now christened ‘Roger’) I decided to add a camera for remote video based control and a speaker so that it can talk. The camera is a Logitech C200 plugged into one of the Pi’s usb ports and the speaker is the excellent  X-Mi X Mini 2 plugged into the Pi’s audio output.

Robot with camera and speaker

Text to Speech

Easily handled by the Pi. I came across this article with a few methods of achieving text to speech on the Pi and went with the Festival option. At the moment I’m happy with it sounding very robot like! I’m calling it from Python with something like the following: os.system(‘echo “‘ + text + ‘” | festival –tts’) where text is a variable containing the words to speak.

I also added the ability to play a wav file as a way to add solme fun sound effects (like a lorry start up noise when the robot starts up  and a siren for waking people up). This is done with aplay – full instructions here. Again called from python with something like: os.system(‘aplay /home/pi/robot/diesel_lorry.wav &’).

Streaming Video

For streaming video I’m using Motion – here are some quick setup instructions for the Pi. The Logitech C200 works well out of the box with the Pi. I did try a C310 first but there was significantly more delay on the video stream (presumably because of the higher source resolution). If choosing a webcam (or any other peripheral) to get for your Pi check out this list of verified peripherals first. Obviously there is tons more I can do with Motion like detecting and responding to actual motion but for a first cut of streaming video to a browser for remote control robot operation this setup works well.


To control the robot via web browser I’m using Webiopi. I have a Python script defining my Webiopi ‘macros’ and a custom HTML page using their Javascript API to create a page with buttons and a text box for entering speech. Complete code listings for these at the end of the post.

Demo of the robots capabilities so far

Code Listings

import webiopi
import time
import sys
import os
import urllib
from raspirobotboard import *

robot = RaspiRobot()

def setup():
    os.system('amixer cset numid=3 1')
    os.system('aplay /home/pi/robot/diesel_lorry.wav &')

def destroy():

def speak(text):
    # decode url encoded parameters
    text = urllib.parse.unquote(text)
    webiopi.debug("Speaking: %s" % (text))
    os.system('echo "' + text + '" | festival --tts')

def forward():

def reverse():

def stop():

def left():
	# turning in small increments, helps with slightly delayed response on a mobile

def right():

def lights_on():

def lights_off():

def flash_lights():

<!-- robot.html -->
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <meta name="viewport" content = "height = device-height, width = 420, user-scalable = no" />
        <title>Roger Robot</title>
        <script type="text/javascript" src="/webiopi.js"></script>
        <script type="text/javascript">
        webiopi().ready(function() {
                var content, button;
                content = $("#content");

                button = webiopi().createMacroButton("lights", "Lights On", "lights_on");

                button = webiopi().createMacroButton("lights", "Lights Off", "lights_off");

                button = webiopi().createMacroButton("forward", "Forward", "forward");

                button = webiopi().createMacroButton("reverse", "Reverse", "reverse");

                button = webiopi().createMacroButton("stop", "Stop", "stop");

                button = webiopi().createMacroButton("left", "Left", "left");

                button = webiopi().createMacroButton("right", "Right", "right");

                button = webiopi().createButton("speak", "Speak", speakText);

        function speakText() {
                var text = $('textarea#talk').val();
                webiopi().callMacro("speak", text);

    <div id="content" align="center">
        <textarea rows="5" cols="50" id="talk">Hello. My name is Roger. Nice to meet you.</textarea>


Written by Tim Corrigan

May 20th, 2013 at 12:41 pm

Posted in Technical

Tagged with ,

6 Responses to 'Raspberry Pi Tracked Robot – streaming video and text to speech'

Subscribe to comments with RSS or TrackBack to 'Raspberry Pi Tracked Robot – streaming video and text to speech'.

  1. Hello. At first, i am sorry for my bad english. I am from Czechia and i am fifteen years old.

    Your robot is amazing! I want to build it too. But how are you powering raspberry pi? Which cabel you are using for powering? MicroUSB? And which version of raspberry do you have? Model A or B?


    28 Apr 14 at 11:24 am

  2. Hi Jan,

    Glad you like the Robot! I’ve actually done quite a bit to it since this post and will try and post an update this week.

    But in the mean time to quickly answer your questions:
    It’s a Model B
    It’s powered by a 6 AA rechargeable battery pack which sits in the bottom of the chassis. This feeds 7.2V to the Raspirobot board which has a regulator that steps it down to the 5V needed by the Pi. More about the board in my first post here: http://timcorrigan.com/raspberry-pi-tracked-robot-phase-1/

    If you have any other questions feel free to ask and I wish you all the best with your own Robot project!

    Tim Corrigan

    28 Apr 14 at 12:09 pm

  3. Hi there,

    I just had a question regarding the webiopi software, specifically how were you able to make the python script run on start up. any help would be greatly appreciated.

    Kind Regards, Ehtisham.


    15 Apr 15 at 1:11 pm

  4. Hi there Ehtisham,

    Webiopi can be run as a background service which can be set to start on boot:
    sudo update-rc.d webiopi defaults

    See: https://code.google.com/p/webiopi/wiki/INSTALL

    Good luck with it!

    Tim Corrigan

    25 Apr 15 at 11:16 am

  5. Hi!
    Have you used only one power source ( 6 AA batteries ) or several ones(one for pi, another for motors)? I’ve faced a problem that when I turn my motors on, my pi reboots(probably battery power was low) :(


    26 Apr 15 at 4:36 pm

  6. Hi Denis,

    Yes – just one power source of 6 AA batteries. These feed the Raspirobot board which has a built in regulator and powers both the Raspberry PI AND the motors. I did find the regulator got very hot though and experienced similar problems to you. So you can try adding a heatsink to the regulator on the raspberry PI robot board or even better upgrading it with a better regulator. See comments on https://www.sparkfun.com/products/11561 for more info. As suggested in those comments, I replaced mine with a Texas instruments UCC383T-5 which I got for free via their sample program and have had no power/heat problems since.

    Tim Corrigan

    26 May 15 at 9:40 am

Leave a Reply