APC Australia

Control your Raspberry Pi with your voice

Nate Drake warms up his vocal cords.

-

WHAT YOU NEED

If you only have a microphone with an audio jack, try searching Amazon or eBay for an inexpensiv­e USB soundcard [Image B], 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 available for the Raspberry Pi. For this project, we’re using Steven Hickson’s Pi AUI Suite, because it’s powerful, as well as extremely easy to set up and configure.

GETTING STARTED

Once you follow the steps in the walkthroug­h (see page 99), you’ll be able to start the installer. The Pi AUI Suite 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. Next, you are asked if you want to install the Play Video 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 following program is Google Text to Speech Service, which you may wish to install if you want the Pi to read out the content of text files. In order to use this service, the Raspberry 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 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.

MORE SOFTWARE OPTIONS

The installer also offers you the chance to install Google Voice Commands. 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 whether you want to install the YouTube scripts. These tools enable you to speak a phrase such as “YouTube fluffy kittens”, which then causes a relevant video clip to be played. Finally, the program gives you the option to install Voice command, 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 Voice command to set itself up automatica­lly. If you experience an error at this stage, follow Step 3 of the walkthroug­h on page 99.

TWEAK THE SETUP

Once the Voice command program is installed, you may wish to make a few basic changes to the setup before fine-tuning your configurat­ion. Open Terminal on your Pi or connect via SSH and run the command sudo voice command -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 Voice command 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 whether you want the Voice command 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 your commands. This can be useful if you want to set the Raspberry Pi to listen continuous­ly, and don’t want it to act on everything you say out loud. The following prompt asks if you want to permanentl­y set the ignore flag. This means that if Voice command 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 “leaf pad”, which is a notepad applicatio­n, Voice command searches for and runs this even if not specifical­ly told to. We do not recommend you enable this feature. Because you’re running Voice command as a Super User, there’s too much risk that you could inadverten­tly tell the Pi a command that could harm your files. If you want to set up extra apps to work

with Voice command, you can edit the configurat­ion file in each specific case. (See ‘Voice Command Tweaks’, over the page, for more informatio­n.) Voice command 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.

MAKE YOUR PI TALK

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 text-to-speech options. 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, ma’am?” [Image C]. 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, “Unknown command”.

TALK AWAY!

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 in your Raspberry Pi. Voice command next asks you whether you want the Pi to check your audio threshold for you. Make sure there is no background noise, press ‘Y’, then hit Return. It then asks you to speak a command to check that it has the correct 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 new 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 over the page to run the Voice command software. Try to start out with a few simple commands. (See Basic Voice Commands below, for more informatio­n.) Once you’re comfortabl­e with these, run the command sudo kill all voice command 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 max (100) [Image D]. If your USB microphone isn’t being detected, it might need more power than the Raspberry Pi’s USB ports can provide on their own. The best solution to get round this is to use a powered USB hub. The Pi Supply website sells a seven-port powered hub for just US$13 ( bit.ly/2c8H10y). A powered USB hub can also be useful if you want to use an external hard drive with your Raspberry Pi.

TROUBLESHO­OTING TIPS

Once the Download program is installed, if you experience an error connecting, bear in mind that access ≠ to the Pirate Bay website may be restricted where you are. In order to download files, you also need a Bit Torrent 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 forum.transmissi­onbt.com. Needless to say, you should only download files with the permission ≠ of the copyright holder. If you choose to use Google Voice Commands or Google TTS (Text to Speech), 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: nsudo nano /etc/rc.local This opens the file that determines which processes start up when your Raspberry 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 voice command -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 Voice command is running, open Terminal and run the command≠

ps -a to show a list of running processes.

 ??  ?? C
C
 ??  ?? B
B
 ??  ?? A
A
 ??  ?? D
D

Newspapers in English

Newspapers from Australia