Amplified Voice Changer utilizing a Raspberry Pi Zero

Amplified Voice Changer using a Raspberry Pi Zero - Raspberry Pi Spy


Whereas researching potential upgrades for my son’s Star Wars Bounty Hunter costume I got here throughout a superb weblog publish by Dave Shevett over at Planet-Geek.com on utilizing a Raspberry Pi to create a voice changer for a halloween costume. This seemed like one thing I may combine into our lovingly constructed bounty hunter helmet.

Mandalorian Costume

The system makes use of SoX to file sound through a microphone, distort it after which ship to an amplified speaker.

I collected the {hardware} and adopted in Dave’s footsteps. For my challenge I made a decision to make use of the Raspbian Lite and a Pi Zero W. All of it work so this publish is offered for anybody who needs to do one thing related and will discover these steps helpful.

Voice Changer System

Voice Changer {Hardware}

  • Raspberry Pi Zero W
  • microUSB to USB adapter
  • USB hub (elective)
  • Keyboard
  • USB sound adapter
  • 5V energy provide
  • Amplified speaker

USB Sound Adapter

MVoice Changer - USB Sound Audio Adaptery USB sound audio adapter dongle thingee was a “C-Media Electronics Inc CM108 Audio Controller”. It has a regular USB plug, 3.5mm microphone jack and a 3.5mm headphone jacks. Inside there’s a actually vivid crimson LED which I tamed with some electrical tape.

There are many alternate options but it surely’s arduous to understand how suitable they’re with the Pi. They’re obtainable from [eBay] for a number of $/£.

Amplified Speaker

Voice Changer - Amplified SpeakerI purchased a “N74” transportable amplified voice speaker from [eBay] for £20. It has a built-in rechargeable battery, a line-in socket and got here with two microphones. I wanted to dig out a 5V energy adapter to cost it up.

Configuration

To start out off create a recent 4GB microSD card utilizing the newest Raspbian Lite picture. The Pi Zero must be linked to an HDMI monitor and a keyboard utilizing applicable adapters. When the Pi boots for the primary time log in with the default username and password (pi/raspberry).

Begin the configuration utility :

sudo raspi-config

and make the next setting adjustments :

  • Hostname > “VoiceChanger”
  • Boot Choices > Desktop/CLI > Console Autologin
  • Boot Choices > Anticipate Community at Boot > No
  • Interfacing Choices > SSH > Sure
  • Superior Choices > Increase Filesystem

Choose <End> and reboot the Pi when prompted.

Setup WiFi (Non-compulsory)

Connecting the Pi to a community permits you do the remainder of the configuration utilizing SSH on a PC. This protects a little bit of typing as you’ll be able to cut-n-paste textual content and switch information.

To configure the WiFi edit the wpa_supplicant.conf file :

sudo nano /and so forth/wpa_supplicant/wpa_supplicant.conf

It ought to already comprise :

ctrl_interface=/var/run/wpa_supplicant
update_config=1

then insert :

community={
  scan_ssid=1
  key_mgmt=WPA-PSK WPA-EAP
  psk="1234567890"
  ssid="MyWIFISSID"
}

Use your individual password and SSID. Double examine the values , save (CTRL-X, Y) and return to the command line.

Join USB Audio System

Shutdown the Pi utilizing :

sudo halt

and disconnect the facility.

You probably have a USB hub you’ll be able to join each the keyboard and the USB sound dongle on the similar time. If you’ll connect with the Pi utilizing SSH then you definitely don’t want the hub and change the keyboard with the USB sound dongle.

Reconnect the facility and permit the Pi to startup. Hopefully your Pi can be linked to WiFi and SSH can be enabled.

Verify USB Audio System

As soon as booted connect with the Pi utilizing any SSH terminal utility (equivalent to Putty or MobaXterm). Or use the keyboard in the event you’ve nonetheless obtained it hooked up.

Now examine the USB audio machine was detected :

lsusb

You need to see the audio machine listed together with every other USB units linked :

USB Audio Adapter lusb output

Extra details about the adapter could be seen utilizing :

dmesg | grep C-Media

To seek out out the machine’s card quantity use :

aplay -l

The machine must be listed as “card 1”.

USB Audio Adapter play device listing

Create the “asoundrc” file utilizing :

sudo nano .asoundrc

and add the next textual content :

pcm.!default {
 sort hw
 card 1
}

ctl.!default {
 sort hw 
 card 1
}

This tells the system to make use of Card 1 because the default audio enter and output.

Upon getting saved the file (CTRL-X, Y) you’ll be able to examine the content material at any time utilizing :

cat .asoundrc

Set up SoX

So as to use the “play” utility we have to set up “SoX” :

sudo apt-get set up sox

Set up mpg123 (Non-compulsory)

To allow the system to play MP3 information I additionally put in mp123 however that is elective.

sudo apt-get set up mpg123

You possibly can play MP3 information utilizing :

mpg123 mysong.mp3

Alsamixer

To examine the speaker and microphone will not be muted you’ll be able to run Alsamixer utilizing :

alsamixer

This could present you a gauge for “Speaker”, “Mic” and “Auto Acquire Management”.

USB Aduio Adapter alsamixer output

Utilizing the arrow keys you’ll be able to alter the acquire of each channels and switch auto-gain on or off. A channel could be muted utilizing the M key. “MM” seems if the channel is muted. Press “Esc” to return to the command line.

Speaker Take a look at

With headphones or a speaker hooked up to the dongle you should use the straightforward speaker-test utility :

speaker-test -c2

or

speaker-test -c2 -t sine -f 500

You need to hear white-noise or a 500Hz tone via your speaker. Press CTRL-Z to exit the check.

Reboot

As you may have put in some packages and edited the .asoundrc file reboot to make sure all adjustments are energetic. The speaker-test command can typically end in “System or reource busy” errors so a reboot it helpful at this level :

sudo reboot

Taking part in WAV Recordsdata (elective)

Nearly there! If you wish to play a check WAV file you’ll be able to obtain a check file utilizing :

wget http://www.kozco.com/tech/piano2.wav

after which play utilizing :

play piano2.wav

Voice Altering Utilizing SoX

Utilizing Dave Shevett’s technique you’ll be able to dynamically change your voice utilizing :

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

This processes knowledge from the microphone channel utilizing “rec” and passes it to “play” which sends the end result to the speaker.

  • buffer permits the stream to gather microphone knowledge to course of earlier than sending it to the speaker. This can add some delay. You possibly can cut back the quantity however the buffer might overflow if it may possibly’t sustain.
  • pitch reduces the pitch of the voice
  • echos add some echos (you guessed that already, proper?)
  • band provides a filter centred on 1.2kHz with a 1.5Hz slope both facet.

All of the SoX choices are detailed on the SoX choices web page.

USB Audio Adapter voice changing with Play and Rec

You possibly can mess around with the choices and values to get completely different results.

Auto-start on Boot

In order for you the voice changer to be transportable you’ll be able to arrange a script to auto-run the play command when the Pi boots. This may be executed by configuring a cron job.

First we have to create a script :

nano voicechanger.sh

then paste within the play command :

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

Entry the cron settings for the Pi consumer utilizing :

crontab -e

Choose “nano” if it asks for a textual content editor. Then add the next line :

@reboot sh /house/pi/voicechanger.sh > /house/pi/voicechanger.log 2>&1

Save and give up utilizing CTRL-X, Y.

Once you subsequent reboot the play command must be routinely executed.

Closing Ideas

One factor that I wasted loads of time on was the microphone connection to the USB audio machine. If the three.5mm jack was pushed all the way in which into the socket the microphone didn’t work. I spent ages questioning why it wasn’t working till I pulled it out barely, the connection was made and the microphone labored as anticipated.

In some methods the voice changer labored nice however simply didn’t fairly sound how I anticipated. I made a decision to not use the voice changer ultimately as a result of my son’s precise voice was simply too apparent within the background. I had coated loads of floor at this level so determined to put in writing it up anyway in case anybody else discovered it helpful.



Supply hyperlink

Leave a Reply

Your email address will not be published. Required fields are marked *