Using a USB Microphone With Raspberry Pi

Adding a USB microphone to your Raspberry Pi can unlock all sorts of new functionality. The most common use for giving your Pi ears is to create a voice assistant such as Alexa or Picroft. But with Python speech-to-text modules such as SpeechRecoginition the fun projects you can take on with a Pi and a mic are endless.

A few summer “camps” ago one of those spectacular projects jumped into my head. I would let the students use their voices to control a robot car! It was going to be a blast!

I already had the cars built. The Raspberry Pis were set up and could pilot the robots around the track with HTTP requests. Now all I needed was some microphones, so I went down to the local superstore and bought some USB microphones that looked like would work.

robot car line-following car sitting on blue and yellow box
ESP32 line-avoiding WiFi-controlled car by me

To see some other things you can make with WiFi-enabled microcontrollers check out my WiFi-controlled LED strip guide or my article on how to make an automated dust extractor.


Table of Contents


Why didn’t the USB Microphone work with my Raspberry Pi?

Getting back to the office, I tore the microphone out of its cardboard and molded-plastic home, hooked it up to a free USB port, and fired up my Python script. I demanded into the mic, “Car, please go forward!” (manners were to be part of my lesson).

The car didn’t move. Looking at the screen, I saw what the Pi heard me say: “Car lease go fore”. That didn’t quite make a match in the script, so I tried again. And again. Finally, on the third attempt, the car lurched forward.

I asked my local co-teacher to come to try. No matter how hard she tried, she couldn’t quite get it. Nothing a little regex can’t fix I said to myself.

When it came to the day of the lesson, the students thought they were controlling the cars with their voices. They didn’t notice the volunteers hovering around with iPads sending the actual commands.

The right quality and sensor for the job

Had I put a little more thought and research into what I wanted to accomplish I might have had better outcomes. Maybe.

The first problem was the quality of the microphone. All the posters on the forums point to the Blue Snowball as the “it-just-works” USB microphone for the Raspberry Pi. But, at that time no store near me in my country carried them, and anyways, I was paying for these mics out of pocket. So I just picked up some mid-range ones (around $20US each).

The second problem is the type of USB microphone I used. Specifically, what kind of pickup pattern should I have chosen for a classroom full of noisy children. I can’t really find any specs for the microphones I bought, but I think most had an omnidirectional pickup pattern:

onidirectional microphone pickup pattern graph
By Galak76 – self-made, Adobe Illustrator, CC BY-SA 3.0

Omnidirectional. That’s Greek for “picks up all the noise in the classroom.” It turns out that what I wanted was a mic with a cardioid pickup pattern. These mics only pick up sound directly in front of them.

By Nicoguaro – Own work, CC BY 4.0

I had a gamer mic that fit the bill. Unfortunately, it is not optimized for the Raspberry Pi.

My friends recently bought a Blue Snowball Ice for their Chinese language learning podcast, Taiwan Feng (shameless plug). The failure of my voice-controlled car lesson always bugged me, so I asked them if I could borrow their Snowball to see how much of a difference it would have made. Results below.

Just a note, the Snowball Ice is a cheaper model of the classic Snowball. The main difference is that the Ice only features the cardioid pickup pattern (perfect for my application). The classic version can switch between three patterns, including omnidirectional, and is probably a better choice if you are building a voice assistant with your Raspberry Pi.


Method

I used a fresh install of Raspberry OS Lite Jammy on a Raspberry Pi 4 4GB updated and upgraded in June 2022. I didn’t install any additional software.

First, I made sure that the microphone was being recognized by typing the following command into the terminal:

lsusb

If you’re sure if your mic is showing up, unplug it, re-run the command, and check if the length of the list of devices has changed.

Satisfied that the USB microphone was connected and recognized, I then got its card and device numbers with the following command:

arecord -l

Once you get the card and device number, you can record with arecord and the options -D plughw: followed by the card and device from the previous command, duration in seconds, and the filename to write out to. My command looked like this (BUT CHANGE YOURS TO MATCH YOUR MIC):

arecord -D plughw:3,0 --duration=10 snowballfan.wav

Here’s what my terminal looked like:

terminal output for recording a short clip
Terminal screenshot by me

You can also check the gain level on your microphone with:

alsamixer

I recorded four clips for each mic: one with no fan in the room (it’s 33C in this box), one with the fan, one with a clip of a noisy classroom in the background, and one of me making noise with a broken, out-of-tune guitar.

For each clip, I said “Testing, testing, 1, 2, 3” (may be some slight variations) twice: once about a foot away from the mic, and once almost touching the mic.

Here are the results:

Foxxray USB Gaming Microphone (with RGB for higher DPS)

foxxray gaming usb microphone sitting on desk
The blue color means it’s in heal mode

Here’s a clip with a little background noise.

Audio clip of me doing a mic check with a floor fan blowing on me.

A clip with little background noise:

Audio clip of me doing a mic check with no real background noise.

And noisy background noise coming from my speakers:

Audio clip of me doing a mic check with a YouTube video of a noisy classroom in the background.

And some crappy guitar strumming:

Audio clip of randomly strumming a beat-up guitar.

As you can hear, there is a persistent clicking noise in all of the clips. My voice was audible when I was close to the microphone, but the quality wasn’t great.


EBooks USB Conference Microphone

conference microphone sitting on a desk next to a pic pico
Pi Pico for scale

Same as the gaming mic, first a little test with a fan blowing at me.

Audio clip of me doing a mic check with a fan blowing at me with a conference mic.

And without the fan (no real difference in sound at all):

Audio clip of me doing a mic check with no real background noise with a conference mic.

And the same YouTube clip.

Mic check with a video of some pesky kids playing in the background.

And me “jamming” again:

Mic check with low resource and skill music.

Even when I was very close to the microphone, my voice was barely audible. I used this kind of microphone for most of the stations during my voice car lesson. Oops.


Blue Snowball Ice USB Microphone

Blue Snowball Ice USB microphone standing next to can of WD-40
360ml can of WD-40 for scale

With fan:

Audio clip of me doing a mic check with no real background noise with a Snowball Blue Ice mic.

Again, no real difference with the fan:

Audio clip of me doing a mic check with a barely audible fan in the background with a Snowball Blue Ice mic.

With noise, the volume is about the same as the gaming mic, but there is not clicking sound:

Audio clip of me doing a mic check with some brats in the background with a Snowball Blue Ice mic.

Guitar (not gonna quit my day job:

Audio clip of me playing experimental music with a Snowball Blue Ice mic.

With alsamixer set to max (the other two mics didn’t have any adjustment available):

Audio clip of me doing a mic check with the inputs turned up to max.

My voice was loud and the sound quality was good even with the noisy classroom in the background.


Conclusion

The Blue Snowball Ice was the clear winner of these three USB microphones hooked up to a Raspberry Pi. Even though the extra quality costs double the price, it would have made my lesson much more enjoyable for my students. If I had to do it again (I won’t), I’d shell out the extra bucks.

Check back soon for a write-up of how to make the WiFi car I used and a real-life test controlling it with the Snowball Ice mic.

Leave a Comment

Your email address will not be published.