Using a Raspberry Pi as a Realtime Voice Changer for Halloween

As most readers know, I’ve been working on my magic staff project for the last year and a half. I incorporated into the ‘Technomancer’ costume for Halloween and Arisia last year, and it was a big hit. I’m continuing to expand the costume, and one thing I’ve always wanted was a voice changer that would let me have a nice sepulchral voice to go with the creepy visage. My own voice from behind the mask is extremely muted, so it’s hard to carry on conversations or even talk to someone, so some external hookup was needed.

My 'bench' test run of the Pi with external USB sound board.
My ‘bench’ test run of the Pi with external USB sound board.

What surprised me was… no one had done this. I searched all over the web for realtime voice processing setups using a Raspberry Pi or Arduino, and while some folks had come close, no one (that I found) had put all the pieces together. So, it was time to do it!

The first component is naturally a Raspberry Pi. I used the pretty awesome CanaKit, which included lots of goodies (most importantly a good, solid case for the board, as well as a microSD card and other accessories). $69 was a great price.

Next, the Pi has onboard audio, but… well, it sucks. I needed separate mic input and outputs, and off-CPU sound processing. Fortunately, there’s huge numbers of these USB sound adapters going for less than $10 a pop. I got 2 just to be careful.

Pyle Audio portable PA
Pyle Audio portable PA

Next, I needed an amplifier. Something portable, loud, and with a remote microphone. This is one just for my setup. Obviously whatever you choose for your own project, pick whatever audio options you’d like. THe sound adapter has standard 1/8th” jacks for mic in and audio out, so just plug right in (I had a small problem with my Mic connection, in that the mic cable I used needed to be ‘out’ a quarter inch to connect properly. I used a small O-ring to keep the spacing proper). The amp I used is Pyle Pro PWMA50B ‘portable PA system’. At $29, it’s well worth it. Comes with a mic, built in rechargeable batteries, a belt mount, and, most importantly, an Auxiliary input.

Now comes the hard part. Getting the audio set up so it could handle recording and playing back in realtime required installing the ‘sox’, toolset, as well as all the alsa tools (most of ALSA comes with the Pi, but make sure they’re there). First, make sure you can play audio through the USB card to the PA. I used ‘aplay’ for this (this ALSA simple player), and a small WAV file I had lying around.

I also recommend running ‘alsamixer’ beforehand, to make sure you can see all the devices, and they’re not muted. ‘aplay -l’ and ‘arecord -l’ are handy in making sure you’re seeing everything you need.

Assuming you have working audio, now comes the fun part. Set up a sox pipe to read from the default audio device and write to the default audio device. Like this:

play "|rec -d"

If all goes well, you should be able to speak into the microphone, and have it come out the speaker. There will almost certainly be a delay of anywhere from a tenth to a half a second. There’s ways to mitigate that, but we’ll get to that in a minute.

If you have that path working, you’re 90% of the way done!

For my costume, I needed a deep voice, so I added -pitch -300 like this

play "|rec -d pitch -300"

I also had a problem with a very high pitched whine coming through the speakers, so I added a band filter to remove that (this syntax means “Remove sound centered on 1.2khz, with a bandwidth of 1.5khz on either side”) :

play "|rec -d pitch -300 band 1.2k 1.5k"

Only a little more tweaking, adding some echos, and I had the voice I wanted. The –buffer command shortens how much data is buffered for processing. This helped cut down the delay a bit, but runs the risk of buffer overruns if you talk a lot.

play "|rec --buffer 2048 -d pitch -300 echos 0.8 0.88 100 0.6 150 .5 band 1.2k 1.5k"

Here’s a sound sample of what it sounded like. Note this is before I added in the band filter, so you can hear the whine…
(direct link here)

The last thing needed was to have the changer start up when the pi reboots. I’m planning on carrying the Pi in a pouch on my belt, powered via one of those cell phone external battery packs. I can’t log in and start the tool whenever it boots. The fix is to put the ‘play’ and other amixer commands into a simple shell script (I put it in /root/setup.sh), and using the @reboot entry that the Pi’s version of Linux supports, add this line to root’s crontab:

@reboot sh /root/setup.sh > /root/sound.log 2>&1

Rebooting now works without a monitor and keyboard attached, and the sound processor starts right up. Ready to go!

Leave a comment if you have any questions, this post will be updated as I continue work on the system…

Travelling to Tennessee

Over the next few days I’ll be travelling with my Mom to Knoxville, TN to visit relatives neither of us have seen in many many many years. I’m both looking forward to and nervous about this trip, as there’s lots of chances for things to go off the rails.

I hope to be tweeting fairly constantly during the trip, checking in, posting pictures, etc. Please follow me! 🙂

I’m also going to enable Facebook cross-posting from Twitter. If you’re on Facebook, hopefully whatever they use for an algorithm will allow you to see my tweets.

When Sites Get Stupid – Techspot Raspberry Pi Ripoff

I have a pretty comprehensive RSS collection, using Feedly as my portal into all things awesome. I’m also really enjoying playing with my Raspberry Pi teeny computer, so when I saw a posting come up saying “The Complete Raspberry Pi 2 Starter Kit – just $115 in the TechSpot Store – gives you all the tools and resources you need to start your Raspberry Pi experience right.“, I had to give it a look.

techspots shameful bundling
Shame on Techspot for an idiotic bundle.

What a scam. Shame on you Techspot. Take a look at that “Kit”. It’s the baseline Raspberry Pi, at a slightly higher, but still “in the realm of normal” price. An case / kit – well, okay, that’s helpful, though pricier than what you can find on Amazon with 5 seconds of searching… and 4 ‘courses’, at $200 each. Yes kids, they’re valuing information anyone can get with 10 seconds of googling at $200 a pop.

A new low Techspot. A new low.