Stupid Sound Tricks for Your Robot

Robots that play sound provide an enhanced level of human interaction. Be on the lookout for for ways to make your robot sound off. Here are some ideas to get you started.

Producing Sound on a PC-Based Robot

If your robot uses a PC or laptop, you can turn to software-only solutions to generate sound. On Windows-based PCs, playing sound files is straightforward, especially when using the Microsoft .NET Framework languages such as C# and Visual Basic. For example, you can use the System.Media.SoundPlayer class to play any WAV file. You need .NET Framework 2.0 or later.

Here’s sample code in Visual Basic .NET that plays a WAVE file named myrobot.wav:

Dim Sound As New System.Media.SoundPlayer()
Sound.SoundLocation = "c:\myrobot.wav"
Sound.Load()
Sound.Play()

PC-Based Sound Generation Software

You can use your personal computer to edit and modify your sound files. Need to play the Star Trek theme when your robot enters the room? No problem? Get a recording of the song, and convert it to the format needed for the sound playback electronics on your robot.

Several sites provide free or nearly free WAV recording/editing utilities and prerecorded sounds that you can use in your robot creations. For example, the Sound Effects Generator software from Sean O’Connor’s Windows Games lets you generate sounds by setting various controls.

There’s also a bevy of free recorded sounds, in MP3 file format, at www.therecordist.com. Most are short effects intended for things like games, but they are equally adaptable for robotics. The selection is from a larger library of effects.

You can also create your own sound effects from the many sound effects CDs that are for sale—my favorite is Cartoon Sound Efx, a collection of sound cues from the Hanna-Barbera cartoon collection of the 1960s through ’80s. Zoinks!

Though copyrighted, you are generally free to use the sound effects for your own personal and noncommercial use. Check the license agreement that comes with the CD to be sure.

Using Recorded Synthesized Speech

If you plan to use prerecorded sound with your robot, you may want to consider any of the several text-to-speech Internet sites, such as the AT&T Labs Natural Voices TTS (text-to-speech) project. Do a Web search to find their site (it regularly changes). At the site, you type in the text you want to synthesize, select a voice and language, and a WAV audio sound file is created for you. Save the file and use it to produce a sound sample for use with your playback module.

You can use a similar technique in Windows or Macintosh OS X to record the synthesized voice provided by the text-to-speech programs built into these operating systems. The clarity of the voice doesn’t match the one available from the AT&T site, but it’s more convenient.

Creating Robotic Voice Effects

You can record your own speech for the voice of your robot, but it won’t sound much like a robot. That is, unless you add a bit of digital processing to alter the sound. One of the premier sound-processing instruments is the vocoder, an electronic device that was originally created to cram voice data down the limited bandwidth of old-style copper telephone lines.

The vocoder has since become popular in radio, movies, and television as a way to produce eerie-sounding voices. The vocoder alters the parameters of sound (pitch, modulation, noise), and when the sound is intentionally “maladjusted” you get some strange sci-fi sound effects—monotones, warbles, vibratos, and more.

Vocoder-like effects were used in the movie Colossus: The Forbin Project to create the sinister voice of the all-commanding computer that takes over the world, in the 1970s TV series Battlestar Galactica, for Darth Vader’s voice and background voice effects in Star Wars, and in many others. (In several of these movies the actual electronic device that created the sound effects was a Marshall Time Modulator, which combined mechanical time delays with modulated vocoder-type effects.)

Vocoders are available today in both hardware and software form. Rock bands have long used analog vocoders to create the “singing guitar” effect. You’ll find vocoders of all sizes, shapes, and prices at most any well-stocked music store. All-software vocoders are available for use with Windows, Macintosh, and Linux, usually as plug-ins for popular synthesizer programs.

Using a Voltage Comparator to Listen for Sound

Connect the output of the amplified sound to a voltage comparator, which in turn connects to a digital input of the microcontroller. Adjust the setting of the potentiometer on the comparator to set the trigger point. This has the effect of altering the sensitivity of the sound circuit.

A low reference voltage makes the circuit sensitive to low sounds; a higher voltage makes it less sensitive. The comparator output will change when sound is detected.

Speech Recognition

Robots that listen to your voice commands and obey? Don’t laugh; not only is the technology available, it’s relatively inexpensive. Several companies, such as Images Company, Parallax, and SparkFun, offer full-featured speech recognition systems for under $100. Both require you to “train” the system to recognize your voice patterns. Once it’s trained, you simply repeat the command, and the system sets one or more of its outputs accordingly.

Keep the following in mind when using a voice recognition system:

Features differ by product, but most support both preprogrammed and user-defined voice commands. The Parallax Say It module, for example, follows 23 built-in preprogrammed or up to 32 user-defined commands. Software for the BASIC Stamp 2 provides an interface for producing speech “templates”; these are used to match your voice with command words you’ve previously stored.

Hacking Recording Sound Modules

You can find hackable sound recording modules in many low-cost toys, electronic picture frames, and do-it-yourself products. These units contain a digital sound recording chip, microphone, amplifier, and speaker (and sometimes sound effects generator). To use them, you press the Record button and speak into the microphone. Then, stop recording and press the Play button, and the sound will play back until you make a new recording.

Most sound modules are mechanically activated; to operate the module electronically you need to disassemble and hack it by soldering wires directly to the circuit board. The wires, which connect to a microcontroller or computer, are in lieu of pressing buttons on the toy to record and play back sounds.

Suppose you have a sound module connected to I/O pin 1 on a BASIC Stamp 2. And also assume that on this particular module it is activated by bringing the button input HIGH to trigger the previously recorded sound snip. The control program is as simple as this:

high 1
pause 10
low 1

The program starts by bringing the button input (the input of the toy connected to pin 1 of the Basic Stamp) HIGH. The pause statement waits 10 milliseconds and then places the button LOW again.

The built-in amplifier of these sound recorder/playback toys isn’t very powerful. You may wish to connect the output of the toy to an audio output amplifier.

Controlling Sound Outputs

Unless you have all of the sound-making circuits in your robot hooked up to separate amplifiers and speakers (not a good idea), you’ll need a way to select among the sounds.

The circuit in Figure 1 uses a 4051 CMOS analog switch—technically an 8 × 1 analog multiplexer/demultiplexer. The chip lets you choose from among eight different analog signal sources. You select input by providing a 3-bit binary word to the select lines. You can load the selection via your microcontroller by connecting the A, B, and C inputs of the chip to I/O lines. Table 46-1 shows the truth table for selecting any of the eight inputs.


[Figure 1]

CD4051 Truth Table

C

B

A

Selected Output

Pin

0

0

0

0

13

0

0

1

1

14

0

1

0

2

15

0

1

1

3

12

1

0

0

4

1

1

0

1

5

5

1

1

0

6

2

1

1

1

7

4

You can route just about any of your sound projects through this chip, just as long as the outlet level doesn’t exceed a few milliwatts. Do not pass amplified sound through the chip. Besides in all likelihood destroying the chip, it’ll cause excessive crosstalk between the channels.

It’s also important that each input signal not have a voltage swing that exceeds the supply voltage to the 4051.