# Wave Shield Voice Changer

## Overview

The [Wave Shield for Arduino](http://adafruit.com/products/94) is one of Adafruit's earliest shield kits and remains a perennial favorite.&nbsp;And for good reason — it's among the easiest and most flexible means of adding quality sound effects to an Arduino project!  
  
Like a fine wine, open source projects improve with age. We've taught this classic shield a new trick: a _realtime voice changer!_ Speak like everyone's favorite baritone Sith lord or&nbsp;sing along with the Lollipop Guild.&nbsp;The Wave Shield has long been a staple among makers' Halloween projects. This latest addition really cinches it!

http://youtu.be/eRdSi4gJz98

# Core Parts List

There are three central components to this project:

- [Adafruit Metro 328 or Arduino Uno](https://www.adafruit.com/product/2488) (an older Arduino Duemilanove or “328” Diecimila can be used as well…but <u>not</u>&nbsp;an Arduino Mega nor Leonardo, sorry).
- [Adafruit Wave Shield](https://www.adafruit.com/products/94 "Link: https://www.adafruit.com/products/94")&nbsp;(also available as part of the [Music & sound add-on pack for Arduino](https://www.adafruit.com/product/175)).&nbsp;
- [Adafruit Microphone Amplifier Breakout.](http://www.adafruit.com/products/1063)

You’ll also need basic soldering tools, wire and&nbsp;bits & bobs.

![](https://cdn-learn.adafruit.com/assets/assets/000/002/197/medium800/projects_coreparts.jpg?1396780354)

# Additional Parts
This is an “open ended” project&nbsp;and the exact components for completion will depend on where you want to take it.&nbsp;<u>Read through the full tutorial</u> for ideas and recommendations on specific parts.  

- For sound output you’ll want headphones, portable MP3 player speakers or&nbsp;our&nbsp;[Class D Audio Amplifier](https://www.adafruit.com/products/987 "Link: https://www.adafruit.com/products/987").  
- The example sketch uses a [12-button keypad](http://adafruit.com/products/419 "Link: http://adafruit.com/products/419") for triggering pre-recorded sounds. But your application might need just a few simple [buttons](http://adafruit.com/products/476 "Link: http://adafruit.com/products/476")…or none at all, if you’re only using the voice effect.
- If adding pre-recorded sounds, you’ll also need an [SD card](http://adafruit.com/products/102) containing WAV files.
- A [10K potentiometer](http://adafruit.com/products/562 "Link: http://adafruit.com/products/562") is used for setting the voice pitch…or you can simply rig the code for a permanent setting.
- If you want to noodle around with wiring, [an extra prototyping shield](http://www.adafruit.com/products/51 "Link: http://www.adafruit.com/products/51") and [stacking headers can come in very handy](http://www.adafruit.com/products/85) - solder the wave shield with stacking headers and put the proto shield on top  
- For portable use (such as costumes and props), add batteries, [battery holders](http://adafruit.com/products/771 "Link: http://adafruit.com/products/771"), etc.

![](https://cdn-learn.adafruit.com/assets/assets/000/002/198/medium800/projects_otherparts.jpg?1396780364)

To reiterate, it’s a very good idea to read through the full tutorial and firm up your own project concept before making a shopping list. We’ll demonstrate a couple of examples, but these aren’t the last word. That’s really the essence of Arduino, isn’t it? Make it your own!

# First Things First…
We also <u>very strongly recommend</u>…no, make that <u>require</u>…that you work through the [original Wave Shield tutorial](http://learn.adafruit.com/adafruit-wave-shield-audio-shield-for-arduino "Link: http://learn.adafruit.com/adafruit-wave-shield-audio-shield-for-arduino") before commencing with this project. It’s a good way to verify the core pieces are working before adding extra layers of complexity. ### 

Afraid not. Realtime voice changing requires issuing data directly to the audio DAC bit-by-bit on the fly. MP3 and the decoder on the associated shield work with prerecorded audio (ditto for OGG format audio).

# Wave Shield Voice Changer

## Principles of Operation

Here we explain some of the geeky background theory stuff. If you just want to get into building the thing, you can skip ahead to the next page.

# Graaains…
Regardless whether you’re old enough to have played with Dad’s LP turntable, or have dabbled in digital audio programs on the newest&nbsp;modern PC, you’ve likely experienced some version of&nbsp;this&nbsp;phenomenon:&nbsp;take an audio recording that’s normally played back at one specific speed…and then change that speed, either compressing or expanding time…and the pitch of the audio changes along with it. Compress time and the pitch rises. Expand time and the pitch drops.&nbsp;_Frequency is inversely proportional to wavelength._

![](https://cdn-learn.adafruit.com/assets/assets/000/002/199/medium800/projects_pitch.png?1396780374)

That’s easy with recordings…but with live audio, we don’t really have that luxury. Realtime is _realtime_…we can’t compress or expand it…it’s happening as it happens. What’s a would-be voice-changer to do?

There’s a complex technique called a _Fourier transform_ that converts a function (or, say,&nbsp;a stream of audio samples) into its frequency spectrum. The resulting frequency values can be altered and an _inverse transform_ applied to turn this back into audio. This is all mathematically good and proper…but it’s a very demanding process and way beyond what our little Arduino can handle. A fairly potent CPU or DSP is usually required. We’ll need a shortcut or some hack…

In digital music circles, _granular synthesis_&nbsp;is a technique of joining and layering&nbsp;lots&nbsp;of very short audio samples (or&nbsp;“grains”) — on the order of one to a few milliseconds — to build up more complex sounds or instruments.&nbsp;Now picture just a single “grain,” 10 milliseconds or so…and we continually refresh this one grain from a live microphone. By time-compressing or -stretching this one tiny loop, repeating or dropping short segments to keep up with realtime, we have the basis for a realtime pitch shifter.&nbsp;It really seems like this shouldn’t work…but it does!&nbsp;Speech waveforms tend to repeat over the very short term, and we can drop or repeat some of those waves with only minor degradation in legibility.

![](https://cdn-learn.adafruit.com/assets/assets/000/002/200/medium800/projects_granular.png?1396780390)

This approach is totally suited to the Arduino’s limited processing power and RAM.&nbsp;The result isn’t going to be Hollywood quality, but it’s still vastly better than&nbsp;the majority of voice-changing toys and masks on store shelves. And you get to make it yourself…how cool is that?

# Sampling Audio
The frequency range of human voice covers about 300 Hz to 3,500 Hz (and harmonics may extend above this).&nbsp;The [Nyquist sampling theorem](http://en.wikipedia.org/wiki/Nyquist%E2%80%93Shannon_sampling_theorem) states that a minimum 2X sample rate is needed to faithfully reconstruct a signal. For human voice, that means 7 KHz sampling…but a little more wouldn’t hurt.

Repeatedly calling the Arduino’s standard analogRead() function in a loop is way, WAY too slow for this. We need to get deeper into the works of the Arduino’s analog-to-digital converter, fiddling directly with special registers and modes.&nbsp;A capability called&nbsp;_free-run mode_&nbsp;collects analog samples at a fast, fixed interval without repeated polling in our code. An interrupt handler is automatically called each time a new sample is ready, which happens like clockwork.&nbsp;Running full tilt, a 16 MHz Arduino can capture 9,615 10-bit samples per second. More than enough&nbsp;for sampling voice!

The audio samples are stored in a _circular buffer,_&nbsp;which is really just big fancy computer science words for “when you reach the end of the buffer, roll back around to the beginning and write over it.” But conceptually, it helps to think of it as a literal circle:

![](https://cdn-learn.adafruit.com/assets/assets/000/002/201/medium800/projects_circular.png?1396780404)

The frequency of recorded sound will seldom match the buffer length exactly, and audio samples are stored and read&nbsp;at different rates.&nbsp;This can produce a sharp discontinuity — a popping noise — each time the “in” and “out” points cross. A small extra buffer is used to store some of the&nbsp;prior audio samples, and the code cross-fades the audio over this boundary to reduce the “pop.”

Because our audio “grain” is relatively short (about 10 milliseconds), the RAM requirements should be fairly modest, a few hundred bytes.&nbsp;Problem is, we’d also like to continue doing&nbsp;those things that the Wave Shield was designed&nbsp;for — namely, playing back WAV files. That requires reading files from an SD card, and that in turn consumes <u>lots</u> of RAM.&nbsp;Fortunately the design of&nbsp;the WAV-playing code lets us gain access that library’s memory and recycle it for our own needs.

The technical details are all well-commented in the source code. So if you’re curious about the specifics of this implementation…use the source, Luke!

# Limitations
When introducing new users to Arduino, I often describe it as “just enough computer to do any <u>one</u> thing really well.” Walking while chewing gum is a challenge. And so it goes with this project as well. Keep the following limitations in mind:

- It can process the voice effect <u>or</u> play back WAVs (and can do both within the same sketch), but you <u>can’t</u>&nbsp;do both simultaneously.
- You <u>can’t</u> read other analog inputs when the voice effect is running (case in point,&nbsp;you can’t alter the pitch continually with&nbsp;a potentiometer). If using analog sensors as sound triggers (e.g. force-sensing resistor pads in shoes), consider work-arounds such as using a carefully-trimmed voltage divider to a digital input, or a second MCU to process analog inputs, forwarding triggers over a serial or I2C connection.
- Although this can change the _pitch_ of one’s voice, it can’t change _timbre._ It won’t, for instance, make things more metallic or robotic-sounding.

# Wave Shield Voice Changer

## Building It

# Phase 1:

## Follow the original Wave Shield tutorial
We can’t emphasize this one enough: work through the [original Wave Shield tutorial](http://learn.adafruit.com/adafruit-wave-shield-audio-shield-for-arduino "Link: http://learn.adafruit.com/adafruit-wave-shield-audio-shield-for-arduino") before moving on to the voice changer!  
  
This project has many separate parts, and a misstep with any one of them can stop the whole system from working. It would be tricky to debug the point of failure among all the possibilities. Invest a little time now to get the basic Wave Shield examples working — especially the “Pi speak” demo. This lets you know that the shield is properly assembled, the SD card properly formatted and so forth. _Then_ we’ll add the extra features.  
  
Start by [downloading the WaveHC library for Arduino](https://github.com/adafruit/WaveHC "https://github.com/adafruit/WaveHC")…not only for WAV playback, but the voice changer relies on this code too. [We have a tutorial explaining how Arduino libraries are installed](http://learn.adafruit.com/arduino-tips-tricks-and-techniques/arduino-libraries). Download [this ZIP file containing WAV files](http://learn.adafruit.com/system/assets/assets/000/010/145/original/piwav.zip) for the digits of pi. Then proceed through the tutorial until your Wave Shield is speaking them.

# Phase 2:

## Adding voice effects and a sound&nbsp;trigger keypad
With the basic Wave Shield working,&nbsp;now we can add the voice changer and a sound-triggering keypad. You can complete this phase on your workbench using a breadboard…we’ll make it portable later, after confirming that it works.

[Download the Adavoice sketch for Arduino](https://github.com/adafruit/Adafruit_Learning_System_Guides/tree/master/AdaVoice). And you should already have the [WaveHC](http://code.google.com/p/wavehc/) library installed from the prior phase.

[Download the project code and files in Zip](https://github.com/adafruit/Adafruit_Learning_System_Guides/tree/master/AdaVoice)
The GND and&nbsp;3.3V lines from the Arduino need to connect to several points, so you may want to a breadboard’s power rails for this. 3.3V from the Arduino&nbsp;should connect to the Electret&nbsp;Mic Amp VCC pin, one outside leg of a 10K potentiometer, and the Arduino’s AREF pin. GND from Arduino&nbsp;should connect to GND on the Mic Amp and the opposite outside leg of the potentiometer.

Danger: 

The Mic Amp output connects to analog pin 0, and the center leg of the potentiometer connects to analog pin 1.  
  
If you plan to use prerecorded sound effects (some examples are in the “wavs” folder included with the sketch), you’ll need a FAT-formatted SD card with the files placed in the root directory (similar to how the “Pi speak” sketch worked). A 12-button keypad connects to digital pins 6, 7, 8 (columns) and analog pins 2, 3, 4, 5 (rows). But with some changes to the sketch, this can be adapted to use just a few buttons or other triggers. (The keypad is great for haunted house sounds, but too cumbersome for a costume.)  
  
A small speaker can be connected directly to the Wave Shield’s amplifier output. For more volume, we recommend using amplified speakers such as the portable type for iPods and MP3 players, or our Class D Audio Amplifier breakout.

![](https://cdn-learn.adafruit.com/assets/assets/000/106/528/medium800/projects_circuit1.png?1637005925)

Upload the Adavoice sketch to the Arduino if you haven’t already done this.&nbsp;If everything is wired up and loaded correctly, you should head a startup chime when the sketch starts (if using an SD card with the sample WAVs). If there’s no sound, use the Arduino serial monitor and watch for diagnostic messages.

![](https://cdn-learn.adafruit.com/assets/assets/000/002/212/medium800/projects_built1.jpg?1396780544)

Once up and running, you can then talk into the microphone and should hear the altered result through the speaker or headphones (keep the mic away from the speaker to avoid feedback). Pressing any of the keypad buttons will stop the voice effect to play the corresponding sound, then resume afterward.  
  
Note that the pitch dial <u>does not work in real time</u>! This is normal and a limitation of the way we’re running the analog-to-digital converter at full speed.&nbsp;To get a new pitch reading, you need to either play back a sound or press the reset button.

# Phase 3:

## Making it battery-powered and portable
To simplify the wiring diagram, we’ll illustrate this next section without the keypad. But you can still include it if you want! The connections are the same as above.

Because breadboard circuits are too delicate for portable use, we’ll join components directly this time.  
  
The Wave Shield can drive a small speaker on its own, but this doesn’t provide a lot of “oomph.” Parties and comic conventions are loud, so you’ll probably want a boost! We’re using our Class D Audio amplifier here with a pair of 4 Ohm speakers. Alternately, there are a lot of ready-to-go battery-powered speakers designed for iPods and other MP3 players that can plug right into the Wave Shield headphone jack. Using our own amp and speakers lets us custom-tailor the placement of all the parts.  
  
It’s best&nbsp;to power the Arduino and audio amplifier separately. During particularly loud moments, the audio amp can draw a <u>lot</u> of current, resulting in a momentary voltage “sag” causing the Arduino to reset. Giving the Arduino it’s own separate power supply prevents this. We’re using a 9 Volt battery connected to the DC barrel jack, or a 6X AA battery pack will last considerably longer.&nbsp;In any case, the ground connection is common between the Arduino and audio power sections, as well as the 3.3V part of the circuit (for the mic amp and trim pot).

![](https://cdn-learn.adafruit.com/assets/assets/000/002/215/medium800/projects_circuit2.png?1396780576)

Here we’ve mounted all the parts on a sheet of acrylic using double-stick foam tape, then fastened this to a nylon strap so it can be worn over one’s chest. We chose tape for expediency only…give some thought to making your rig more durable, using mounting screws, zip ties, etc.

![](https://cdn-learn.adafruit.com/assets/assets/000/002/213/medium800/projects_finished.jpg?1396780547)

You can run the microphone connection&nbsp;a couple feet to reach inside a mask or helmet. A&nbsp;[servo extension cable](http://adafruit.com/products/973)&nbsp;provides a very handy 3-conductor separation point, so you can pop your head and set it down! Cut the servo cable in half, soldering one end to the mic amp board and the other side to the Arduino circuit.

![](https://cdn-learn.adafruit.com/assets/assets/000/002/216/medium800/projects_servo.jpg?1396780580)

# Wave Shield Voice Changer

## Tips for Use in Costumes

- Give your project a complete dry run well ahead of time…don’t dash right off to the party!&nbsp;Know how long batteries will last. Check that&nbsp;wires aren’t pulled and connections aren’t strained. Make sure no components get&nbsp;uncomfortably or dangerously hot.&nbsp;Fine-tune audio levels and reduce feedback.
- Build it extra rugged and&nbsp;motion-proof. Stranded wire flexes much better than solid-core wire. Use beefy, [NASA-style inline splices](http://blog.makezine.com/2012/02/28/how-to-splice-wire-to-nasa-standards/). Implement strain reliefs to avoid cracked solder connections. Breadboards are fine for prototyping, but [solder up&nbsp;your rig for deployment](http://adafruit.com/products/591 "Link: http://adafruit.com/products/591").
- Don’t shout — speak softly and let the amplifier boost your voice. You want people to hear the “bent” sound, not your natural voice.
- Point speakers away from the microphone to avoid feedback. Even a few degrees can make a big difference.
- Sweat is horribly corrosive stuff! It’s mostly salt water — and&nbsp;look what that does to ships at sea. Even worse, it’s <u>conductive</u>!&nbsp;Seal&nbsp;_everything._&nbsp;Heat-shrink all wire connections,&nbsp;and use plastic enclosures or epoxy&nbsp;for any electronics that are&nbsp;fully inside a costume. If using a microphone inside a mask (which may have both&nbsp;sweat&nbsp;_and_&nbsp;condensation from breath, ewww!), borrow an old audio pro trick and wrap the mic inside a balloon.  
- Pack spare batteries and, space permitting, a minimal repair kit of safety pins, a few zip ties and a length of duct tape.  
- Never let technical wizardry get in the way of a good performance! The example sketch uses a membrane keypad with many&nbsp;tiny buttons…that’s fine for a tabletop “sound board” instrument, but a poor choice&nbsp;for a&nbsp;Godzilla suit&nbsp;(who really should be continually thrashing about leveling Tokyo, not standing still to hunt around for a specific button). More isn’t always better…one or two buttons hidden in a glove may suffice. Practice until your performance is&nbsp;natural and your technology is&nbsp;discreet.


## Featured Products

### Stereo 3.7W Class D Audio Amplifier - MAX98306

[Stereo 3.7W Class D Audio Amplifier - MAX98306](https://www.adafruit.com/product/987)
This incredibly small stereo amplifier is surprisingly powerful - able to deliver 2 x 3.7W channels into 3 ohm impedance speakers. Inside the miniature chip is a class D controller, able to run from 2.7V-5.5VDC. Since the amp is a class D, its incredibly efficient (over 90% efficient when...

In Stock
[Buy Now](https://www.adafruit.com/product/987)
[Related Guides to the Product](https://learn.adafruit.com/products/987/guides)
### Electret Microphone Amplifier - MAX4466 with Adjustable Gain

[Electret Microphone Amplifier - MAX4466 with Adjustable Gain](https://www.adafruit.com/product/1063)
Add an ear to your project with this well-designed electret microphone amplifier. This fully assembled and tested board comes with a 20-20KHz electret microphone soldered on. For the amplification, we use the Maxim MAX4466, an op-amp specifically designed for this delicate task! The amplifier...

In Stock
[Buy Now](https://www.adafruit.com/product/1063)
[Related Guides to the Product](https://learn.adafruit.com/products/1063/guides)
### Adafruit Wave Shield for Arduino Kit

[Adafruit Wave Shield for Arduino Kit](https://www.adafruit.com/product/94)
Adding quality audio to an electronic project is surprisingly difficult. Here is a shield for Arduino 328's that solves this problem. It can play up to 22KHz 12bit uncompressed audio files of any length. It's low cost, available as an easy-to-make kit. It has an onboard DAC, filter and...

Out of Stock
[Buy Now](https://www.adafruit.com/product/94)
[Related Guides to the Product](https://learn.adafruit.com/products/94/guides)
### Music & sound add-on pack for Arduino

[Music & sound add-on pack for Arduino](https://www.adafruit.com/product/175)
Its a Wave shield party pack! Just add an Arduino to create your own iPod-killer, audio art, sound-effects box...

Comes with:

- Latest [Wave shield kit](http://www.adafruit.com/products/94), works with more SD cards and with older NG Arduinos! Unassembled
- 8 GB...

Out of Stock
[Buy Now](https://www.adafruit.com/product/175)
[Related Guides to the Product](https://learn.adafruit.com/products/175/guides)
### Adafruit Proto Shield for Arduino Kit

[Adafruit Proto Shield for Arduino Kit](https://www.adafruit.com/product/51)
Works with the Uno! This prototyping shield is the best out there (well, we think so, at least). It works with UNO, NG, Diecimila and Duemilanove Arduinos. You can use it with a Leonardo but it will not break out the hardware SPI pins (they're only on the ISP connector underneath) or the...

No Longer Stocked
[Buy Now](https://www.adafruit.com/product/51)
[Related Guides to the Product](https://learn.adafruit.com/products/51/guides)
### Adafruit METRO 328 Fully Assembled - Arduino IDE compatible

[Adafruit METRO 328 Fully Assembled - Arduino IDE compatible](https://www.adafruit.com/product/50)
We sure love the ATmega328 here at Adafruit, and we use them&nbsp;_a lot_&nbsp;for our own projects. The processor has plenty of GPIO, Analog inputs, hardware UART SPI and I2C, timers and PWM galore - just enough for most simple projects. When we need to go small, we use a <a...></a...>

Out of Stock
[Buy Now](https://www.adafruit.com/product/50)
[Related Guides to the Product](https://learn.adafruit.com/products/50/guides)
### Shield stacking headers for Arduino (R3 Compatible)

[Shield stacking headers for Arduino (R3 Compatible)](https://www.adafruit.com/product/85)
_“How could something so simple be so useful?”&nbsp;_

We heard once that&nbsp;in the 4th millennium B.C.&nbsp;some guy asked the person who invented the wheel that question.&nbsp; The person who invented the wheel’s answer, we were told, was...

In Stock
[Buy Now](https://www.adafruit.com/product/85)
[Related Guides to the Product](https://learn.adafruit.com/products/85/guides)
### 6 x AA battery holder with 5.5mm/2.1mm plug

[6 x AA battery holder with 5.5mm/2.1mm plug](https://www.adafruit.com/product/248)
Make a portable power brick with plenty of juice! Use Alkaline AA's for a 9V 3000-4000mAh power supply, or rechargeable NiMH for 2000mAh 7.5V supply. Either one is good for running electronics that have a 5V voltage regulator (thus requiring a 7V+ supply). Will last about 10 times longer...

In Stock
[Buy Now](https://www.adafruit.com/product/248)
[Related Guides to the Product](https://learn.adafruit.com/products/248/guides)

## Related Guides

- [Adafruit 2.8" TFT Touch Shield v2 - Capacitive or Resistive](https://learn.adafruit.com/adafruit-2-8-tft-touch-shield-v2.md)
- [Halloween Pumpkin](https://learn.adafruit.com/halloween-pumpkin.md)
- [NeoPixel Painter](https://learn.adafruit.com/neopixel-painter.md)
- [Arduino Lesson 6. Digital Inputs](https://learn.adafruit.com/adafruit-arduino-lesson-6-digital-inputs.md)
- [3D Printed Wireless MIDI Controller Guitar](https://learn.adafruit.com/ez-key-wireless-midi-controller-guitar.md)
- [Overwatch Prop Gun: Lucio's Blaster Pt. 3](https://learn.adafruit.com/overwatch-prop-gun-lucios-blaster-pt-3.md)
- [Ladyada's Bento Box](https://learn.adafruit.com/lady-adas-bento-box.md)
- [RGB LED Matrix Basics](https://learn.adafruit.com/32x16-32x32-rgb-led-matrix.md)
- [20mm LED Pixels](https://learn.adafruit.com/20mm-led-pixels.md)
- [Adafruit VS1053 MP3/AAC/Ogg/MIDI/WAV Codec Breakout Tutorial](https://learn.adafruit.com/adafruit-vs1053-mp3-aac-ogg-midi-wav-play-and-record-codec-tutorial.md)
- [Collin's Lab: MIDI](https://learn.adafruit.com/collins-lab-midi.md)
- [Raspberry Gear](https://learn.adafruit.com/raspberry-gear.md)
- [Gemma-Powered NeoPixel LED Sound Reactive Drums](https://learn.adafruit.com/gemma-powered-neopixel-led-sound-reactive-drums.md)
- [Echo 2-XL](https://learn.adafruit.com/echo-2-xl.md)
- [Adafruit Analog Accelerometer Breakouts](https://learn.adafruit.com/adafruit-analog-accelerometer-breakouts.md)
