1

So i have managed to get input from a microphone using I2S interface following this link . https://learn.adafruit.com/adafruit-i2s-mems-microphone-breakout/raspberry-pi-wiring-and-test

if i use the following command to record audio and then playback.. the volume level is pretty high: arecord -D dmic_sv -c2 -r 48000 -f S32_LE -t wav -V mono -v recording.wav

Note: the Alsamixer mic volume is 100% . and the i2s driver installed doesnt come with a volume control feature. Hence I use a soft_vol config in the ~/.asoundrc for the volume ctrl of the mic .

The problem begins here . I am using the pyaudio module for python to record the stream . It gets recorded all fine But the volume is too low . Is there a way to turn it up a bit .

  • Can you please be more specific here? Do you wanna tune a microphone input gain or do you wanna tune the volume output? – user91822 Oct 15 '18 at 12:36
  • I want to tune the input gain . Basically i need a pyaudio call which can manipulate slave devices as well . – Aashwin Gaur Oct 15 '18 at 13:34
  • i know i can increase the microphone input volume level by editing the ~/.asound file using soft_val . But when i do this a virtual slave device called dmic_sv is created with the high input gain . The pyaudio API provides a call to open the audio stream using the index number of the device .And so when i input the index number , the original device without the input gain settings opens up . – Aashwin Gaur Oct 15 '18 at 13:55
1

Ok I found the solution. First edit the ~/.asound file (If its not there , create it).Add the following

pcm.dmic_hw {
type hw
card sndrpisimplecar    
channels 2
format S32_LE
}

pcm.dmic_sv {
type softvol
slave.pcm dmic_hw
control {
    name "Boost Capture Volume"
    card sndrpisimplecar
}
    min_dB -3.0
    max_dB 30.0
}

As you can see this virtual slave device is named dmic_sv Make a note of that . Now create a test file with the following python code . It will list the indexes of all the soundcard connected devices including the virtual ones . (Tried and tested on Raspberry Pi 3B+).

import pyaudio
p = pyaudio.PyAudio()
info = p.get_host_api_info_by_index(0)
numdevices = info.get('deviceCount')

for i in range(0, numdevices):


    if(p.get_device_info_by_host_api_device_index(0,i).get
    ('maxInputChannels')):
            print "Input Device id ", i, " - ", 
            p.get_device_info_by_host_api_device_index(0, 
            i).get('name')
  • if by chance the software device doesn't show up add the contents of ~/.asound to /usr/share/alsa/alsa.conf – Aashwin Gaur Oct 15 '18 at 14:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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