0

I have successfully setup adafruit I2S mem microphone on my RPi3 running buster by following this guide .

It records audio well using arecord :

arecord -D 'plughw:2,0' -c1 -r 48000 -f S32_LE -t wav -V mono -v file.wav

But I need 16-bit signed PCM audio for my project. Running arecord -D 'plughw:2,0' -c1 -r 48000 -f S16_LE -t wav -V mono -v file.wav does not record anything.

What changes do I need to make to change bit depth to 16 ?

Thanks.

1 Answer 1

0

After going through ALSA documentation, I was able to achieve it by configuring ALSA .asoundrc file to get 16 bit pcm with boosted microphone volume for my project.

Microphone is available as card #2. Therefore in line 4, pcm "hw:2,0"

Here are the contents of ~/.asoundrc :

pcm.mymic_main {
        type plug
        slave {
           pcm "hw:2,0"
           rate 48000
           format S32_LE
    }

}

pcm.mymic  {
        type softvol
        slave.pcm mymic_main
        control {
                name "Boost Capture Volume"
                card sndrpii2scard
        }
        min_dB -3.0
        max_dB 30.0
}

In python project :

sudo pip3 install pyalsaaudio

cat myproject.py

import alsaaudio

mic = alsaaudio.PCM( alsaaudio.PCM_CAPTURE,  alsaaudio.PCM_NONBLOCK,  device='mymic',  channels=1, rate=48000, format=alsaaudio.PCM_FORMAT_S16_LE, periodsize=960 )

_ , frame = mic.read()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.