Facebook Twitter Instagram Pinterest YouTube
    Trending
    • Add Kodi to RetroPie Menu
    • Disable Auto-login in Raspberry Pi OS
    • Raspberry Pi Cloud Storage with MEGA
    • RetroPie Temperature Monitor from Menu
    • Pi Pico Pinout and Power Pins
    • Install Arduino IDE on Raspberry Pi
    • Raspberry Pi 400 SSD Upgrade
    • Raspberry Pi Temperature Monitoring
    Facebook Twitter Instagram Pinterest YouTube RSS
    Raspberry Pi SpyRaspberry Pi Spy
    • Home
    • Categories
      • General
      • Hardware
      • Programming
      • Python
      • Software
      • Tutorials & Help
    • BerryClip
      • BerryClip Instructions
      • BerryClip Plus Instructions
      • Videos & Reviews
    • Buy
      • Buy Pi
      • Buy Pi Accessories
      • Buy Books
    • Tools
      • Ultimate Raspberry Pi Alexa Skill
      • Pi Power Estimator App
      • Pi-Lite 14×9 LED Matrix Sprite Editor
      • RPiREF Pin-out Reference App
      • Simple Ohm’s Law Calculator
      • Web Sites & Links
    • Tutorials & Help
        Featured
        November 9, 20200

        Raspberry Pi Temperature Monitoring

        Recent
        May 6, 2022

        Add Kodi to RetroPie Menu

        February 26, 2022

        Disable Auto-login in Raspberry Pi OS

        February 2, 2022

        Raspberry Pi Cloud Storage with MEGA

      1. Contact Us
      2. Site Map
      Raspberry Pi SpyRaspberry Pi Spy
      You are at:Home»Hardware»Pi Zero»Amplified Voice Changer using a Raspberry Pi Zero
      Voice Changer System

      Amplified Voice Changer using a Raspberry Pi Zero

      0
      By Matt on March 23, 2017 Pi Zero, Tutorials & Help

      While researching possible upgrades for my son’s Star Wars Bounty Hunter costume I came across an excellent blog post by Dave Shevett over at Planet-Geek.com on using a Raspberry Pi to create a voice changer for a halloween costume. This looked like something I could integrate into our lovingly constructed bounty hunter helmet.

      Mandalorian Costume

      The system uses SoX to record sound via a microphone, distort it and then send to an amplified speaker.

      I collected the hardware and followed in Dave’s footsteps. For my project I decided to use the Raspbian Lite and a Pi Zero W. It all work so this post is presented for anyone who wants to do something similar and may find these steps useful.

      Voice Changer System

      Voice Changer Hardware

      • Raspberry Pi Zero W
      • microUSB to USB adapter
      • USB hub (optional)
      • Keyboard
      • USB sound adapter
      • 5V power supply
      • 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 standard USB plug, 3.5mm microphone jack and a 3.5mm headphone jacks. Inside there is a really bright red LED which I tamed with some electrical tape.

      There are lots of alternatives but it’s hard to know how compatible they are with the Pi. They are available from [eBay] for a few $/£.

      Amplified Speaker

      Voice Changer - Amplified SpeakerI bought a “N74” portable amplified voice speaker from [eBay] for £20. It has a built-in rechargeable battery, a line-in socket and came with two microphones. I needed to dig out a 5V power adapter to charge it up.

      Configuration

      To start off create a fresh 4GB microSD card using the latest Raspbian Lite image. The Pi Zero should be connected to an HDMI monitor and a keyboard using appropriate adapters. When the Pi boots for the first time log in with the default username and password (pi/raspberry).

      Start the configuration utility :

      sudo raspi-config

      and make the following setting changes :

      • Hostname > “VoiceChanger”
      • Boot Options > Desktop/CLI > Console Autologin
      • Boot Options > Wait for Network at Boot > No
      • Interfacing Options > SSH > Yes
      • Advanced Options > Expand Filesystem

      Select <Finish> and reboot the Pi when prompted.

      Setup WiFi (Optional)

      Connecting the Pi to a network allows you do the rest of the configuration using SSH on a PC. This saves a bit of typing as you can cut-n-paste text and transfer files.

      To configure the WiFi edit the wpa_supplicant.conf file :

      sudo nano /etc/wpa_supplicant/wpa_supplicant.conf

      It should already contain :

      ctrl_interface=/var/run/wpa_supplicant
      update_config=1

      then insert :

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

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

      Connect USB Audio Device

      Shutdown the Pi using :

      sudo halt

      and disconnect the power.

      If you have a USB hub you can connect both the keyboard and the USB sound dongle at the same time. If you are going to connect to the Pi using SSH then you don’t need the hub and replace the keyboard with the USB sound dongle.

      Reconnect the power and allow the Pi to startup. With any luck your Pi will be connected to WiFi and SSH will be enabled.

      Check USB Audio Device

      Once booted connect to the Pi using any SSH terminal utility (such as Putty or MobaXterm). Or use the keyboard if you’ve still got it attached.

      Now check the USB audio device was detected :

      lsusb

      You should see the audio device listed along with any other USB devices connected :

      USB Audio Adapter lusb output

      More information about the adapter can be seen using :

      dmesg | grep C-Media

      To find out the device’s card number use :

      aplay -l

      The device should be listed as “card 1”.

      USB Audio Adapter play device listing

      Create the “asoundrc” file using :

      sudo nano .asoundrc

      and add the following text :

      pcm.!default {
       type hw
       card 1
      }
      
      ctl.!default {
       type hw 
       card 1
      }

      This tells the system to use Card 1 as the default audio input and output.

      Once you have saved the file (CTRL-X, Y) you can check the content at any time using :

      cat .asoundrc

      Install SoX

      In order to use the “play” utility we need to install “SoX” :

      sudo apt-get install sox

      Install mpg123 (Optional)

      To enable the system to play MP3 files I also installed mp123 but this is optional.

      sudo apt-get install mpg123

      You can play MP3 files using :

      mpg123 mysong.mp3

      Alsamixer

      To check the speaker and microphone are not muted you can run Alsamixer using :

      alsamixer

      This should show you a gauge for “Speaker”, “Mic” and “Auto Gain Control”.

      USB Aduio Adapter alsamixer output

      Using the arrow keys you can adjust the gain of both channels and turn auto-gain on or off. A channel can be muted using the M key. “MM” appears if the channel is muted. Press “Esc” to return to the command line.

      Speaker Test

      With headphones or a speaker attached to the dongle you can use the simple speaker-test utility :

      speaker-test -c2

      or

      speaker-test -c2 -t sine -f 500

      You should hear white-noise or a 500Hz tone through your speaker. Press CTRL-Z to exit the test.

      Reboot

      As you have installed some packages and edited the .asoundrc file reboot to ensure all changes are active. The speaker-test command can sometimes result in “Device or reource busy” errors so a reboot it useful at this point :

      sudo reboot

      Playing WAV Files (optional)

      Almost there! If you want to play a test WAV file you can download a test file using :

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

      and then play using :

      play piano2.wav

      Voice Changing Using SoX

      Using Dave Shevett’s method you can dynamically change your voice using :

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

      This processes data from the microphone channel using “rec” and passes it to “play” which sends the result to the speaker.

      • buffer allows the stream to collect microphone data to process before sending it to the speaker. This will add some delay. You can reduce the number but the buffer may overflow if it can’t keep up.
      • pitch reduces the pitch of the voice
      • echos add some echos (you guessed that already, right?)
      • band adds a filter centred on 1.2kHz with a 1.5Hz slope either side.

      All the SoX options are detailed on the SoX options page.

      USB Audio Adapter voice changing with Play and Rec

      You can play around with the options and values to get different effects.

      Auto-start on Boot

      If you want the voice changer to be portable you can set up a script to auto-run the play command when the Pi boots. This can be done by configuring a cron job.

      First we need to create a script :

      nano voicechanger.sh

      then paste in 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"

      Access the cron settings for the Pi user using :

      crontab -e

      Select “nano” if it asks for a text editor. Then add the following line :

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

      Save and quit using CTRL-X, Y.

      When you next reboot the play command should be automatically executed.

      Final Thoughts

      One thing that I wasted a lot of time on was the microphone connection to the USB audio device. If the 3.5mm jack was pushed all the way into the socket the microphone didn’t work. I spent ages wondering why it wasn’t working until I pulled it out slightly, the connection was made and the microphone worked as expected.

      In some ways the voice changer worked great but just didn’t quite sound how I expected. I decided not to use the voice changer in the end because my son’s actual voice was just too obvious in the background. I had covered a lot of ground at this point so decided to write it up anyway in case anyone else found it useful.

      Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
      Previous ArticleRaspberry Pi 5th Birthday Party in Cambridge
      Next Article Setup WiFi on a Pi Manually using wpa_supplicant.conf

      Related Posts

      Add Kodi to RetroPie Menu

      Disable Auto-login in Raspberry Pi OS

      Raspberry Pi Cloud Storage with MEGA

      Leave A Reply Cancel Reply

      This site uses Akismet to reduce spam. Learn how your comment data is processed.

      Recent Posts
      May 6, 2022

      Add Kodi to RetroPie Menu

      February 26, 2022

      Disable Auto-login in Raspberry Pi OS

      February 2, 2022

      Raspberry Pi Cloud Storage with MEGA

      January 7, 2022

      RetroPie Temperature Monitor from Menu

      January 24, 2021

      Pi Pico Pinout and Power Pins

      Categories
      • 1-wire
      • 3D Printing
      • Add-ons
      • BBC Micro:bit
      • BerryClip
      • Books
      • Camera Module
      • Cases
      • Events
      • General
      • Hardware
      • I2C
      • Infographics
      • Interfaces
      • Minecraft
      • Model A+
      • Model B+
      • News
      • Pi Models
      • Pi Zero
      • Power
      • Programming
      • Python
      • Raspberry Pi OS
      • Raspbian
      • RetroGaming
      • Robotics
      • Sensors
      • Software
      • SPI
      • Tutorials & Help
      Tags
      3D Printing Arduino audio battery berryclip Birthday bluetooth cambridge camera CamJam DigiMakers display games GPIO I2C interface Kickstarter LCD LED Linux media Minecraft Model A Model B motionEyeOS PCB photography photos Pi-Lite portable power python Raspberry Jam Raspberry Pi Bootcamp raspbian Retrogaming retroPie screen SD card security sensor SPI temperature ultrasonic video
      Raspberry PI Related
      • Adafruit Blog
      • Average Maker
      • Official RaspBerry Pi Site
      • Raspberry Pi Pod
      • RasPi.tv
      • RaspTut
      • Stuff About Code
      Tech Resources
      • MattsBits – Pi Resources
      • Microbit Spy
      • Technology Spy
      Archives
      About

      Unofficial site devoted to the Raspberry Pi credit card sized computer offering tutorials, guides, resources,scripts and downloads. We hope to help everyone get the most out of their Pi by providing clear, simple articles on configuring, programming and operating it.

      Popular Posts
      September 19, 2014

      Top 5 Reasons The Raspberry Pi Sucks

      July 27, 2012

      16×2 LCD Module Control Using Python

      October 20, 2013

      Analogue Sensors On The Raspberry Pi Using An MCP3008

      Recent Posts
      May 6, 2022

      Add Kodi to RetroPie Menu

      February 26, 2022

      Disable Auto-login in Raspberry Pi OS

      February 2, 2022

      Raspberry Pi Cloud Storage with MEGA

      Facebook Twitter Instagram Pinterest YouTube RSS

      Entries RSS | Comments RSS

      This site is not associated with the official Raspberrypi.org site or the Raspberry Pi Foundation. Raspberry Pi is a trademark of the Raspberry Pi Foundation.

      Copyright © 2022 - All Rights Reserved - Matt Hawkins

      Type above and press Enter to search. Press Esc to cancel.