Pi voice....................................
Bend your Raspberry Pi to your will by issuing vocal commands.
Nate Drake hates germs bigly style, so he’s created a voice controlled Pi so his tiny hands don’t have to touch the filthy thing ever again.
There’s a scene in StarTrekIV:TheVoyageHome, where Scotty and Dr McCoy are offered the opportunity to use a computer and are somewhat bemused when it fails to respond to voice commands. The film was made over 30 years ago and voice recognition has taken huge leaps forward since then. The Raspberry Pi has not been left out, and with the help of an inexpensive USB microphone and some suitable software, you too can have your Pi search YouTube, open web pages, launch applications and respond to questions, simply by speaking.
The Raspberry Pi has no built-in soundcard or audio jack, so you need a USB microphone or a webcam with built-in microphone for this project. We tested the software using a Microsoft HD-3000 webcam, but any compatible device will do. Visit http://elinux.org/RPi_USB_Webcams for a full list of Pi-compatible webcams if you don’t already have one, but be sure that whatever device you choose has an integrated microphone.
If you only have a microphone with an audio jack, try searching Amazon or eBay for an inexpensive USB sound card, which plugs into the USB port at one end and has an output for earphones and a microphone at the other.
There’s a number of speech recognition programs for the Pi. For this project, we’re using Steven Hickson’s PiAUISuite, because we’ve found it to be powerful as well as extremely easy to set up and configure.
Once you follow the steps in the tutorial, you will be able to start the installer. The PiAUISuite gives you a choice of a number of programs to install. The first question you are asked is whether it should install the dependencies. These, quite simply, are the files the Raspberry Pi needs to download for voice commands to work, so select y and press Return to agree to this.
Getting started
Next, you are asked if you want to install the PlayVideo program, which enables you to use voice commands to launch and play video files. If you choose y, you’re asked to specify the path to your media files, for example, /home/ pi/Videos. Note that upper-case letters are important here. If the path is invalid, the program warns you.
You’re then asked if you want to install the Downloader program, which searches for and automatically downloads files from the internet for you. If you choose y here, you’re asked to provide settings for host, port, username and password. If you aren’t sure of these, press Return for now to choose the default options in each case.
The next program is GoogleTexttoSpeechService, which you may wish to install if you want the Pi to read out the contents of text files. In order to use this service, the Pi needs to be connected to the internet, because it connects to Google’s servers to ‘translate’ the text into speech and then plays an audio file with the Pi’s media player.
If you decide to install this, you will need a Google account. The installer asks you to enter your username. Do so, then press Return. You’re then prompted for your Google password. Enter this and press Return again.
The installer also offers you the chance to install Google VoiceCommands. This uses Google’s own speech recognition service. Again, you’re asked to provide your
Google username and password to continue. Whether or not you choose the Google-specific software, the program also asks you whether you want to install the YouTube scripts. These tools enable you to speak a phrase such as ‘YouTube fluffy kittens’, which will trigger a search and see YouTube play a relevant video from the results. Finally, the program gives you the option to install Voicecommand, which contains some of the more useful scripts, such as being able to launch your web browser by saying the word ‘internet’.
The program asks you if you want to let Voicecommand set itself up automatically. If you experience an error at this stage, follow Step 3 of the walkthrough (seethelastpage).
Pi’s master’s voice
Once the Voicecommand program is installed, you may wish to make a few basic changes to the setup before fine-tuning your configuration. To do this, open Terminal on your Pi or connect via SSH and run the command sudo voicecommand -s
You are asked a series of yes/no questions next. The first question asks whether you want to permanently set the continuous flag. In plain English, the Voicecommand program is asking whether, each time you run it, you want it to continuously listen for your voice commands. Select y for now.
Next, you are asked if you want the Voicecommand program to permanently set the verify flag. Selecting y here means the program expects you to say your keyword (by default, the word ‘Pi’) before responding to commands. This can be useful if you want to set the Pi to listen continuously and don’t want it to act on everything you say.
The following prompt asks if you want to permanently set the ignore flag. This means that if Voicecommand hears a command that’s not specifically listed in your configuration file, it tries to look for a program in your installed applications and run it. For instance, if you say the word ‘leafpad’, which is a notepad application, Voicecommand searches for and runs this even if not specifically told to.
We don’t recommend you enable this feature. Because you’re running Voicecommand as a SuperUser, there’s too much risk that you could inadvertently tell the Pi a command that could harm your system. If you want to set up extra applications to work with Voicecommand, you can edit the configuration file in each specific case. (SeeVoice CommandTweaks,overthepage.)Voicecommand then asks you whether you wish to permanently set the quiet flag, so it doesn’t give a verbal response when you speak. Choose y or n as you see fit.
Next, you’re asked if you want to change the default duration for speech recognition. You should only change this if you’re finding the Pi is having trouble hearing your commands. If you choose y, you’re asked to type in a number—this is the number of seconds that the Pi listens for a voice command and the default is 3.
The program then gives you a chance to set up the textto-speech options. Be sure to turn up your volume before doing this. The program attempts to say something and asks whether you have heard it.
The default response of the system when responding to your keyword is ‘Yes, sir?’ Choose y on the next prompt to change this, then type in your desired response, such as ‘Yes, Mr Stark?’ Press Return when you’re done. The system plays back the response for you to confirm whether you’re happy with the result.
The procedure is the same for the default message for when the system receives an unknown command. The default response is ‘Received improper command’, but you can change this to something less robotic if you prefer by typing y, then your chosen response – for example, ‘I’m sorry, Dave, I’m afraid I can’t do that.’
You are now offered the chance to set up the speech recognition options. This automatically checks whether you have a compatible microphone installed. Voicecommand next asks you if you want the Pi to check your audio threshold for you. Make sure there is no background noise, press y, then Return.
Next, you’ll be asked to speak a command to enable Voicecommand to check that it has the right audio device selected. The program automatically determines the right audio threshold for you, so type y to choose this.
Finally, the Pi asks you if you want to change the default keyword (‘Pi’) to activate voice commands. Type y, then enter your preferred keyword. Press Return when done.
You are then asked to speak your keyword to acclimatise the Pi to your speaking voice. If this seems correct, type y to complete the setup. Follow Step 6 of the tutorial walkthrough (see right) to run the Voicecommand software. Try to start out with a few simple commands. (SeeBasic VoiceCommands,onthepreviouspage,fordetails). Once you’re comfortable with these, run the command sudo killall voicecommand to shut down the program and edit your configuration file if you wish.
Vexing voices
Voice recognition software is a work in progress and the Pi may not recognise everything you say. To improve your chances, be sure to stay near the USB microphone and speak slowly and clearly.
If you’re still having trouble being understood, open Terminal on your Pi or connect via SSH and run the command alsamixer to open your sound settings. Press F4 to choose audio input, then press F6. Use the arrow keys to
select your USB device, then press Return. This controls the volume of your USB microphone. Use the up arrow to push it to maximum (100).
If your device isn’t being detected at all, it may need more power than the Pi’s USB ports can provide on their own. The best solution for this is to use a powered USB hub. The Pi Hut website sells a seven-port powered hub for just £11 ( https://thepihut.com/products/7-port-usb-hub-for-theraspberry-pi). This can also be useful if you want to use an external hard drive with your Pi.
Once the Download program is installed, if you experience an error connecting, bear in mind that access to the PirateBay website may be restricted where you are. In order to download files, you also need a BitTorrent client for the Pi, such as the program Transmission. You can install this by opening Terminal or connecting to your Pi over SSH and running the command sudo apt-get install transmission . Help with getting started and how to use the client is available from the Transmission website at https://forum.
transmissionbt.com. Needless to say, you should only download files with the permission of the copyright holder. If you choose to use GoogleVoiceCommands or Google TTS(TexttoSpeech), bear in mind that anything you say and any text files you submit are sent to Google’s servers for translation. Google claims not to retain any of this data, but even if it is to be believed, any data transmitted over the internet can potentially be intercepted by a third party. Google does encrypt your connection to reduce the chance of this happening, however.
If you find you’re happy with the voice command feature, you might prefer the software to start automatically each time you boot the Pi. If so, open Terminal on your Pi or connect via SSH and run the following command: sudo nano /etc/rc.local This opens the file that determines which processes start up when your Pi boots. By default, this script does nothing. Use your arrow keys to scroll to the bottom of the file and, just above the line reading exit 0 , type the following: sudo voicecommand -c Press Ctrl+X, then Y, then Return to save your changes. Feel free to reboot the Pi at this stage to make sure it works. If you’re unsure whether Voicecommand is running, open Terminal and run the command ps -a to show a list of running processes.