Step-By-Step Procedure
Prepare the Operating System
We’ll start with a fresh operating system installation. So, start installing Raspberry PI OS Lite. You can also use this with Raspberry PI OS desktop, working from its internal terminal console.
Make the OS up to date. From the terminal:
sudo apt update -y && sudo apt upgrade -y
Identify the USB Microphone Hardware
We’ll use the Linux “lsusb” utility to check if the USB microphone is detected by our Raspberry PI. The “lsusb” is a utility for displaying information about USB buses in the system and the devices connected to them (ref. https://linux.die.net/man/8/lsusb).
Let’s check its output BEFORE plugging the USB microphone. From the terminal, you will have a result similar to the following:
pi@raspberrypi:~ $ lsusb
Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
This result may change depending on the Raspberry PI computer board version and model you’re using (this output is from my Raspberry PI 5 Model B) and these entries are the USB ports.
Please plug in now the USB Microphone. Check again the USB list:
pi@raspberrypi:~ $ lsusb
Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 003 Device 002: ID 8086:0808 Intel Corp. USB PnP Sound Device
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
In the previous output, I’ve highlighted the new line that appeared after plugging the USB microphone. This new line means that the external device has been detected from the OS and that Bus 003 Device 002 is my USB microphone.
Test the USB Microphone on Raspberry PI with Arecord
Arecord is a command-line sound recorder, already installed in our Raspberry PI OS Lite.
Let’s check the list of audio input devices and the card ID detected from it with the following terminal command:
pi@raspberrypi:~ $ arecord -l
**** List of CAPTURE Hardware Devices ****
card 2: Device [USB PnP Sound Device], device 0: USB Audio [USB Audio]
Subdevices: 1/1
Subdevice #0: subdevice #0
As highlighted in the previous output, my microphone matches the card 2 – device 0 sound device. In the next tests, this card identification will be mapped in the following arecord option: “plughw:2,0“.
Now, we can test a simple recording by typing:
arecord -D plughw:2,0 -d 3 test.wav
This command will perform a voice recording:
using the card 2 – device 0 input equipment (the “-D plughw:2,0” option)
with a duration of 3 seconds (the “-d 3” option)
saving the recording to a file named “test.wav”
The following output will appear:
pi@raspberrypi:~ $ arecord -D plughw:2,0 -d 3 test.wav
Warning: Some sources (like microphones) may produce inaudible results
with 8-bit sampling. Use '-f' argument to increase resolution
e.g. '-f S16_LE'.
Recording WAVE 'test.wav' : Unsigned 8 bit, Rate 8000 Hz, Mono
Now you can simply check the recorded file by connecting and downloading it with your favourite SFTP software (for example Filezilla) to your Raspberry PI, by setting an SFTP connection (using your RPI user and password).
https://peppe8o.com/use-usb-microphone-with-raspberry-pi-os-lite/