Last Updated on
Some advanced projects with Raspberry Pi can foresee also the use of voice controls. While these projects are not simple to setup (I’m scheduling some tests in the very next future), giving a microphone to your RPI can be a very simple operation. A very interesting project, in this sense, is the Google home assistant project.
Remember that Raspberry Pi doesn’t come with a built-in audio device. A very cheap solution is the use of some USB microphones which can be found on-line, costing a few dollars.
Installing USB microphone from a terminal is simple and is the only way if you don’t have a desktop environment installed.
What We Need
We’ll use an SSH session to connect our Raspberry Pi, so no USB keyboards or video cables are needed. I also suggest to add these hardware in your favourite shopping chart, so that you’ll have the overall cost and will be able to evaluate if continuing with the project or removing them.
We’ll start from a fresh installation of the recent Raspbian Buster Lite (here the procedure).
I’ll use a Raspberry Pi 3 A+, but the procedure is the same for all recent RPI models.
Once Raspbian is installed and the USB Microphone is plugged in, check the USB device connection:
this will show the following output:
Bus 001 Device 001 is the phisical hub inside RPI board, while Bus 001 Device 002 is my USB microphone. With RPI model B this could show 5 devices, being RPI model B equipped with 4 USB ports (+ internal hub).
Let’s check the list of audio input devices with the following:
this output should be shown:
So, my microphone matches with card 1 / device 0. This will be mapped in the following with plughw:1,0.
Now, we can test a simple recording by typing:
arecord -D plughw:1,0 -d 3 test.wav
The following output will appear:
Now you can simple check this file by connecting and downloading it with your favourite FTP software (for example Filezilla) to your RPI with ad SFTP connection (using your RPI user and password, pi and raspberry if you left the factory ones).
Recording volume can be very low in some cases. Alsamixer helps us with a simple interface to manage audio devices volumes. Type in your terminal:
You’ll see the default console:
Now, you have to switch to the correct audio device by pressing F6:
In my case, the correct sound card is the one marked as bcm2835 ALSA:
Use up / down arrow keys to regulate at your choice. Press ESC to save and exit. Test againg.