The driver for the microphone works with Raspberry Pi OS Bookworm and Bullseye. This has been tested with both 32-bit and 64-bit Lite releases.
You can add mono or stereo I2S microphones to your Raspberry Pi, too! This will work with any Raspberry with a 2x20 GPIO connector.
This guide is largely based on this great git repo, which we forked for use here. Also useful was the information provided in this forum post.
Wiring For Mono Mic
- Mic 3V to Pi 3.3V
- Mic GND to Pi GND
- Mic SEL to Pi GND (this is used for channel selection, connect to either 3.3V or GND)
- Mic BCLK to BCM 18 (pin 12)
- Mic DOUT to BCM 20 (pin 38)
- Mic LRCL to BCM 19 (pin 35)
Wiring For Stereo Mic
Connect both mics as above except for the SEL pin.
- Left Mic SEL to Pi GND
- Right Mic SEL to Pi 3.3V
Install Raspbian on an SD Card
You'll need to start with Raspbian or Raspbian Lite. Get the latest version from the Raspberry Pi Download page and follow these instructions to install the OS image to the SD card.
The following line needs to be added to config.txt.
dtoverlay=googlevoicehat-soundcard
Starting with the PiOS Bookworm config.txt is located in:
/boot/firmware/config.txt
Earlier PiOS releases such as Bullseye have the file located in:
/boot/config.txt
That is it! reboot your Pi.
sudo reboot
arecord -l
You should see a card entry with information similar to this:
Note the card number. In the screen shot above it is 1
. You can record a wav file in mono with this command (change the -plughw
parameter to match the card number from above):
arecord -D plughw:1 -c1 -r 48000 -f S32_LE -t wav -V mono -v file.wav
Or, if you have two i2s mics installed, record in stereo with this command:
arecord -D plughw:1 -c2 -r 48000 -f S32_LE -t wav -V stereo -v file_stereo.wav
If all is working correctly, you should see the VU meter react at the bottom of the terminal window:
Test Playback
If you have speakers hooked up to the Pi, you can play the file back directly on the device:
aplay file.wav
Or, you can copy it over to your computer for playback :), make sure SSH is enabled and then:
scp pi@raspberrypi:file.wav ~/Desktop/file.wav
Volume Control is not supported with the googlevoicehat-soundcard.
The googlevoicehat-soundcard module is great in that it comes precompiled and just works. This is what most people should use. It will be at a fixed 48 kHz.
If you want to record at higher frequencies checkout the rpi-i2s-audio overlay. There is a report of successful recording up to 96 kHz.
tip credit: forum user @grondeau
Adding Volume Control
You can add volume control to your mic via alsamixer and alsa config. (Hat tip to RickTracer). To do so, create and edit a file .asoundrc in your home directory.
nano ~/.asoundrc
and put the following in:
#This section makes a reference to your I2S hardware, adjust the card name # to what is shown in arecord -l after card x: before the name in [] #You may have to adjust channel count also but stick with default first pcm.dmic_hw { type hw card sndrpii2scard channels 2 format S32_LE } #This is the software volume control, it links to the hardware above and after # saving the .asoundrc file you can type alsamixer, press F6 to select # your I2S mic then F4 to set the recording volume and arrow up and down # to adjust the volume # After adjusting the volume - go for 50 percent at first, you can do # something like # arecord -D dmic_sv -c2 -r 48000 -f S32_LE -t wav -V mono -v myfile.wav pcm.dmic_sv { type softvol slave.pcm dmic_hw control { name "Boost Capture Volume" card sndrpii2scard } min_dB -3.0 max_dB 30.0 }
Now before you can change the volume you need to use the device once (this is an alsa thing)
Run:
arecord -D dmic_sv -c2 -r 44100 -f S32_LE -t wav -V mono -v file.wav
And cancel with ^C once it starts recording.
Now you can run alsamixer - press F6 and select the I2S sound card
It will complain there are no playback controls (because its for recording only).
Press F4 to switch to Capture mode and you should be able to adjust the volume with up/down arrow keys.
Then you can record with the i2c mic device using:
arecord -D dmic_sv -c2 -r 48000 -f S32_LE -t wav -V mono -v recording.wav
and playback with:
aplay recording.wav
Page last edited October 19, 2024
Text editor powered by tinymce.