/>

In this instructable, I’ll show you:

  • how to connect the pi to the intercom
  • how to set up the pi
  • how to install the voicecontrole software
  • how to add a speech script that will return the output of your own scripts as speech
  Step 1: What do you need for this project?
For this project we need:

  • A Raspberry pi model B with Raspian Wheezy installed.
  • A USB WIFI adaptor: I used a Delock Nano Stick 150MB/s. It cost about $18
  • A USB soundcard: it cost $3.21 at Deal Extreme.
  • A small 5V amplifier: I used a PAM8403 board. It cost $5.64 at Deal Extreme.
  • A 5V power supply: at least 2A.
  • A 5V DPDT relais: DPDT means Double Pole Double Throw. The relais is able to switch two different signals between two different outputs.
  • A tiny piece of vero board
  • Some wires
  • A USB keyboad and mouse + a tv with HDMI or video in connection for installing everything on the Pi

Step 2: Installing the Wifi.

Picture of installing the Wifi.
wificonfig2.jpg
wificonfig3.jpg
wificonfig4.jpg
wificonfig5.jpg
In this step , I’ll show you how to connect to the internet via the raspberry desktop. But before you do anything, update your raspberry. Make sure that your Pi is connected to the internet via a cable.

To update, start-up the raspberry and on the desktop, open the terminal. Enter the following commands in the terminal.

sudo apt-get update

sudo apt-get upgrade

Once this is done shut down the raspberry:
sudo poweroff
Now insert the USB WIFI adaptor and turn on the power again.

On the desktop, double click the Wifi Config Icon. A window will open.

Click the scan-button which will again open a new window.

In that window, select your SSID by double-clicking it.

A window appears and you should add the password where it says PSK. Then click Add.

You will be back in the first window. There you can see the status of the connection at the IP.

You should now have a Wifi connection.

You can shut the Pi down for now.

Step 3: Setting up the hardware.

Picture of Setting up the hardware.
2014-01-21 21.17.34 HDR.jpg
2014-01-21 21.17.52 HDR.jpg
2014-01-21 21.52.43 HDR.jpg
2014-01-21 21.52.48 HDR.jpg
DSCF9367.JPG

2014-01-21 21.15.35 HDR.jpg
DSCF9368.JPG
2014-01-23 21.20.08 HDR.jpg
2014-01-23 21.28.01 HDR.jpg
DSCF9369.JPG
2014-01-25 15.21.06 HDR.jpg
DSCF9366.JPG
Inside the intercom, there is not enough space to hide everything, when the whole setup is done with jacks to connect the audio. So to address this problem, I opened the plastic case of the USB sound card and desoldered the connectors. Then I soldered wires to the spots where the connectors were. The connection of these wires will be discussed later in this step.

Most intercoms use the speaker as microphone. So this means that we have to devise a method to connect the same speaker to the output and the microphone input of the USB sound card. There is a push button in the front that was used originally to switch between listen and speak, so that can be of use to us.

It has to be said that I didn’t want to change anything on the outside of the intercom because it’s such a nice thing in great condition. Drilling holes in it was no option. Otherwise I could simply have added a DPDT switch to switch between input and output. So I had to find the next simplest method.

This is where the 5V DPDT relais comes in. We can use the push button of the intercom to switch it. To do this, we connect 5V to the push button and the second wire of the button goes to one side of the relay coil. The other side of the coil goes directly to ground. So when you press the button, the coil is activated and the relay switches. It is good practice to add a diode in the opposite direction over the 2 pins of the coil.

The center-pins of the DPDT relays are connected to the + and – of the speaker. The NO (Normally Open) pins are connected to the microphone input of the USB soundcard. The NC (Normally Closed) pins need to be connected to the output of the sound-card. But the signal of that output is not loud enough for the speaker so we need to put an amplifier between them.

The Amplifier I used, is quite simple to hook up. Everything is clearly marked on the PCB. Connect the 5V pin to 5V and the GND pin to GND and you have power. Then connect the output and GND from the soundcard to Rin and GND and connect R+ and R- to the NC pins of the relay.

When this is done, everything can be placed into the case. Connect the sound-card to the pi.

It is not a very good idea to try to power everything from the raspberry pi. So I found a 5V 3A wall adaptor to power this project. I did cut of the connector and connected everything inside to it. To do so I had to cut a USB cord. That allowed me to connect to the pi without having to desolder the onboard USB connector.

When everything is hooked up this way, your hardware is set up and the case can be closed.

Step 4: Setting up the USB sound card.

Picture of Setting up the USB sound card.
The raspberry pi needs a little bit of preparation to use a USB sound-card. There is a very good adafruit tutorial for this.

I’ll give you the short version here. My sound-card was a CM109 version so the only thing I had to do was to open the alsa config file:

sudo nano /etc/modprobe.d/alsa-base.conf

And change:

options snd-usb-audio index=-2

into:

options snd-usb-audio index=0

And then reboot the pi:

sudo reboot

Step 5: Setting up the voicecommand software.

I used Steven Hicksons voice command software. If you are looking for voice command software for your pi, stop looking and use this one. It is by far the easiest to setup and to use. It is also very well documented and it is quite reliable.
You can download it from his website and there are also some videos there that show you how you can set it up.

The voice-command software comes as a part of a whole suite of media related applications for the pi. I only installed the voice-command software, but if you like to use more of them for your project, then feel free to install them.

When the software is installed, you can enter the following command:

voicecommand -s

It will start an automatic setup process that guides you step-by-step through the setup of your device.
When this is done, you can enter:

voicecommand -e

This will open the config file and allow you to set the commando’s and the related actions.
It has to be entered in the following format:

command==action

The command system is pretty simple. When you set the command to play, it will only react when you say nothing else but ‘play’. When you set it to play music it will only react to ‘play music’ and not to ‘play’ or ‘play chess’. But when you set it to ~play it will react to any sentence that contains ‘play’.

The action can be any executable command.

When you are done editing the config file, save it and everything is ready.

To run the software just enter:

voicecommand -c

and enjoy your personal assistant. The good lady will now listen to your commands and perform the appropriate task. When she doesn’t find a matching task to a command you gave, she will look it up on Google and she will try to give you a satisfying answer. You can finish the project now but in the next steps I will show you how to get more out of it.

Step 6: Make it run on startup.

Picture of Make it run on startup.
It is ofcourse nice if the voice-command starts to work on start up. To do this we need to add a little script.

In the home directory (home/pi), open the .config directory

cd .config
then create a new directory:
mkdir autostart
go into that directory:
cd autostart
and in that directory open a new file in nano:
sudo nano voicecommand.desktop
Write the following code in the file:
[Desktop Entry]
Type=Application
Name=Voicecommand
Exec=voicecommand -c
StartupNotify=false
Save the file and reboot the Pi.

Step 7: Give your own apps a voice.

Picture of Give your own apps a voice.
It’s all very nice that the device is able to start programs and return info from the internet, but sometimes you want to receive very specific data in a certain way. For instance the weather forecast for your area. One thing you can do(as I did) is to write your own python script that gets the data from the internet, filters out the data you want and returns it in a way that makes sense. The only problem is that those scripts return that data as written text and not as speech. So we need an extra script to do that for us.

I found a very nice script on Oscar Liang’s blog. Just like voicecommand, it uses Google speech service to ‘translate’ the text into speech.

The first one you need is the text2speech.sh script. (I’ll copy it here but all credits go to Oscar Liang)

copy it into nano or the text editor on the graphic desktop

#!/bin/bash

INPUT=$*
STRINGNUM=0
ary=($INPUT)
for key in “${!ary[@]}”
do
SHORTTMP[$STRINGNUM]=”${SHORTTMP[$STRINGNUM]} ${ary[$key]}”
LENGTH=$(echo ${#SHORTTMP[$STRINGNUM]})

if [[ “$LENGTH” -lt “100” ]]; then

SHORT[$STRINGNUM]=${SHORTTMP[$STRINGNUM]}
else
STRINGNUM=$(($STRINGNUM+1))
SHORTTMP[$STRINGNUM]=”${ary[$key]}”
SHORT[$STRINGNUM]=”${ary[$key]}”
fi
done
for key in “${!SHORT[@]}”
do
say() { local IFS=+;/usr/bin/mplayer -ao alsa -really-quiet -noconsolecontrols “http://translate.google.com/translate_tts?tl=en&q=${SHORT[$key]}”; }
say $*
done

Once you have saved this script, make it executable with:

chmod +x text2speech.sh
This script will be reusable for all applications that need conversion to speech.

The only thing we need now are scripts that run the python script and pump the output into thetext2speech script. We’ll need one of these scripts for each python script.

#!/bin/bash

ANSWER=$(python yourpythonscriptname.py)

./text2speech.sh $ANSWER

Save this as whatever-you-like.sh and make it executable.

now you can enter this script into the config file of voicecommand and it will return speech whenever the right command is entered.