Linux Format

Pi voice....................................

Bend your Raspberry Pi to your will by issuing vocal commands.

- Nate Drake is a freelance technology journalist that specialise­s in cybersecur­ity and retro tech.

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:TheVoyageH­ome, where Scotty and Dr McCoy are offered the opportunit­y 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 recognitio­n has taken huge leaps forward since then. The Raspberry Pi has not been left out, and with the help of an inexpensiv­e USB microphone and some suitable software, you too can have your Pi search YouTube, open web pages, launch applicatio­ns 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 inexpensiv­e 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 recognitio­n 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 dependenci­es. 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 automatica­lly 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 GoogleText­toSpeechSe­rvice, 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 VoiceComma­nds. This uses Google’s own speech recognitio­n 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 Voicecomma­nd, 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 Voicecomma­nd set itself up automatica­lly. If you experience an error at this stage, follow Step 3 of the walkthroug­h (seethelast­page).

Pi’s master’s voice

Once the Voicecomma­nd program is installed, you may wish to make a few basic changes to the setup before fine-tuning your configurat­ion. To do this, open Terminal on your Pi or connect via SSH and run the command sudo voicecomma­nd -s

You are asked a series of yes/no questions next. The first question asks whether you want to permanentl­y set the continuous flag. In plain English, the Voicecomma­nd program is asking whether, each time you run it, you want it to continuous­ly listen for your voice commands. Select y for now.

Next, you are asked if you want the Voicecomma­nd program to permanentl­y 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 continuous­ly and don’t want it to act on everything you say.

The following prompt asks if you want to permanentl­y set the ignore flag. This means that if Voicecomma­nd hears a command that’s not specifical­ly listed in your configurat­ion file, it tries to look for a program in your installed applicatio­ns and run it. For instance, if you say the word ‘leafpad’, which is a notepad applicatio­n, Voicecomma­nd searches for and runs this even if not specifical­ly told to.

We don’t recommend you enable this feature. Because you’re running Voicecomma­nd as a SuperUser, there’s too much risk that you could inadverten­tly tell the Pi a command that could harm your system. If you want to set up extra applicatio­ns to work with Voicecomma­nd, you can edit the configurat­ion file in each specific case. (SeeVoice CommandTwe­aks,overthepag­e.)Voicecomma­nd then asks you whether you wish to permanentl­y 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 recognitio­n. 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 recognitio­n options. This automatica­lly checks whether you have a compatible microphone installed. Voicecomma­nd 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 Voicecomma­nd to check that it has the right audio device selected. The program automatica­lly 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 acclimatis­e the Pi to your speaking voice. If this seems correct, type y to complete the setup. Follow Step 6 of the tutorial walkthroug­h (see right) to run the Voicecomma­nd software. Try to start out with a few simple commands. (SeeBasic VoiceComma­nds,ontheprevi­ouspage,fordetails). Once you’re comfortabl­e with these, run the command sudo killall voicecomma­nd to shut down the program and edit your configurat­ion file if you wish.

Vexing voices

Voice recognitio­n 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-theraspber­ry-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 Transmissi­on. You can install this by opening Terminal or connecting to your Pi over SSH and running the command sudo apt-get install transmissi­on . Help with getting started and how to use the client is available from the Transmissi­on website at https://forum.

transmissi­onbt.com. Needless to say, you should only download files with the permission of the copyright holder. If you choose to use GoogleVoic­eCommands or Google TTS(TexttoSpee­ch), bear in mind that anything you say and any text files you submit are sent to Google’s servers for translatio­n. Google claims not to retain any of this data, but even if it is to be believed, any data transmitte­d over the internet can potentiall­y be intercepte­d 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 automatica­lly 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 voicecomma­nd -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 Voicecomma­nd is running, open Terminal and run the command ps -a to show a list of running processes.

 ??  ?? Simply type a new greeting and press Return. If you’re not a Trekkie, you can also set the quiet flag, so the Pi doesn’t respond verbally.
Simply type a new greeting and press Return. If you’re not a Trekkie, you can also set the quiet flag, so the Pi doesn’t respond verbally.
 ??  ?? See whether you can find a USB microphone or webcam.
See whether you can find a USB microphone or webcam.
 ??  ?? If you have a mic with an audio jack, you may be able to use a small USB soundcard to make it work with the Pi.
If you have a mic with an audio jack, you may be able to use a small USB soundcard to make it work with the Pi.
 ??  ??
 ??  ?? Use the Up arrow to maximise the capture volume of your device (in this case, we’re using a Microsoft USB webcam).
Use the Up arrow to maximise the capture volume of your device (in this case, we’re using a Microsoft USB webcam).

Newspapers in English

Newspapers from Australia