Posts: 1317
Joined: Thu Jan 30, 2014 9:53 am

Newbie on audio: How do I get a mini usb mic to record audio

Fri Feb 02, 2018 11:17 pm

I have gotten a few of these mini microphones in order to try to make a RPi3 able to record audio:
I am running the latest Raspbian Stretch and there is no screen attached (running headless).
All commands are via PuTTY ssh console.
I could do the following after plugging in the mic:

Code: Select all

$ lsusb -t
/:  Bus 01.Port 1: Dev 1, Class=root_hub, Driver=dwc_otg/1p, 480M
    |__ Port 1: Dev 2, If 0, Class=Hub, Driver=hub/5p, 480M
        |__ Port 1: Dev 3, If 0, Class=Vendor Specific Class, Driver=smsc95xx, 480M
        |__ Port 4: Dev 5, If 1, Class=Audio, Driver=snd-usb-audio, 12M
        |__ Port 4: Dev 5, If 2, Class=Human Interface Device, Driver=usbhid, 12M
        |__ Port 4: Dev 5, If 0, Class=Audio, Driver=snd-usb-audio, 12M
$ arecord -l
**** List of CAPTURE Hardware Devices ****
card 1: Device [USB PnP Sound Device], device 0: USB Audio [USB Audio]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
$ arecord -D plughw:1,0 -d 3 tes2t.wav
Recording WAVE 'tes2t.wav' : Unsigned 8 bit, Rate 8000 Hz, Mono
$ ls -l t*
-rw-r--r-- 1 pi pi 24044 Feb  2 17:00 tes2t.wav
So the arecord command produces a wav file and if I copy this to my PC I can play it with VLC, but the sound is very low volume and very distorted and noisy when playback volume is raised to actually hear anything...

I have tried to find a way to increase the recording level but failed, none of the files referenced in the various pages I found actually exist on my RPi3.
So is there some kind of extra installation one should do in order to be able to record sound properly?
And get the config files in place that can set the volume (and quality).

And why is it saying 8bit while recording? Surely a better quality should be available than 8 bit?
Bo Berglund

Posts: 1317
Joined: Thu Jan 30, 2014 9:53 am

Re: Newbie on audio: How do I get a mini usb mic to record audio

Sat Feb 03, 2018 11:05 am

So I found that there is a description page for arecord that supplies an example command using more arguments, so I tried with this instead:

Code: Select all

arecord -D plughw:1,0 -d 5 -f S16_LE -c1 -r44100 test3.wav
Now the recorded audio does not contain such a lot of noise, but it is still very low volume.
The page mentions volume only as follows:
Disable software volume control (softvol).
But it seems illogical to disable the volume, I want to set it at a higher level only.

How can one raise the recording volume?

I tried this but it did nothing helpful, volume is still way too low:

Code: Select all

arecord -D plughw:1,0 -d 5 -f S16_LE -c1 -r16000 --disable-softvol test5.wav
If I load the wav file into Audacity the only thing visible is a straight line. I have to use the Audacity "Normalize" function to boost the volume and then it is possible to hear the recorded audio.
There seems to be no arecord argument that can set the volume higher for me.

My plan is to use the microphone to pick up sounds at the location of the RPi and stream these via the Apache webserver if someone clicks a suitable link. (Monitoring the baby bedroom via the LAN)

Is this at all possible?
Bo Berglund

Posts: 1317
Joined: Thu Jan 30, 2014 9:53 am

Re: Newbie on audio: How do I get a mini usb mic to record audio

Sun Feb 04, 2018 5:03 pm

Thanks, but as I said I am running a headless RPi, so the only user interface is an SSH command prompt via PuTTY.
In most places I have looked the descriptions assume I have a GUI so there are screenshots with buttons to click, boxes to check etc.
This does not apply for my application, though.

I thought that there could be some howto describing the way to work with audio without having a GUI screen...
After all audio handling should not require a GUI screen to operate.

The link you provided fails already at the first reply from "number22" since there is not even a directory called /var/lib/alsa/ on my RPi3.
Therefore also no /var/lib/alsa/asound.conf file.

Seems like my Raspbian Stretch is missing some audio components altogether.
Bo Berglund

Posts: 133
Joined: Sat Aug 09, 2014 11:48 pm

Re: Newbie on audio: How do I get a mini usb mic to record audio

Thu Jun 14, 2018 3:38 pm

alsamixer works in a terminal OK and allows increasing gain

(on a pi with sound enabled it will be card 1 so)

alsamixer -c 1

allows settting gain to 23.81

but they are very quiet even at max gain

seems there is a way to use a softvol in .asoundrc, not got it working yet

however sox seems to work OK to give a boost to the gain

$sudo apt-get install libsox-fmt-mp3 sox

$ export AUDIODRIVER=alsa
$ export AUDIODEV=hw:1,0
$ rec -r 44100 -c 1 testsox.mp3 gain 50

Does anyone know how to set up a ~/.asoundrc to add a softvol for card 1, card 0 is default pi audio output.

I tried the following but no sign of any reference to it after a reboot

pcm.loudmic {
type asym
capture.pcm {
type softvol
slave.pcm "hw:1,0" "Softmaster"
control.card 1

min_dB -10.0
max_dB 50.0

Return to “Graphics, sound and multimedia”