Search code examples
audioraspberry-piusbraspbian

How to set default microphone on Raspberry Pi 3B with Raspbian Stretch?


So far I have not found any guides on how to set the default USB microphone for Stretch and so I've followed all of the guides for Wheezy and Jessie and they do not work.

Typing in the command arecord sound.wav does not record anything from the microphone. However, if I were to type in this command it would work arecord -f cd -D hw:1,0 -d 10 sound.wav.

Here is what appears when I enter in arecord -l

**** List of CAPTURE Hardware Devices ****
card 1: Headset [Plantronics Headset], device 0: USB Audio [USB Audio]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

I've edited this file /usr/share/alsa/alsa.conf and set the values to this

defaults.ctl.card 1
defaults.pcm.card 1

I've also edited the /etc/asoundrc file and changed it to this:

pcm.!default {
         type asym
         playback.pcm {
                 type plug
                 slave.pcm "hw:0,0"
         }
         capture.pcm {
                 type plug
                 slave.pcm "hw:1,0"
         } 
 }

 ctl.!default {
        type hw
        card 0
}

and this:

pcm.!default {
        type hw
        card 1
}

ctl.!default {
        type hw
        card 1
}

and it still does not work.


Solution

  • I've been having headaches with this one for about a day, but I finally made it work.

    Your .asoundrc should actually look like this:

    pcm.!default {
        type asym
        playback.pcm "plughw:0"
        capture.pcm  "plughw:1"
    }
    
    ctl.!default {
        type hw
        card 1
    }
    

    Otherwise your settings are ok, but I think this command is wrong:

    arecord sound.wav
    

    The proper command for testing the mic (or at least the one that works for me) is this:

    arecord -D plughw:1,0 --duration=3 test.wav && aplay test.wav
    

    This is setup for a 3 seconds recording and after recording stops it automatically plays back to you (assuming your audio also works). This part plughw:1,0 points to your mic, which I see is set to card 1. I you have created this file /etc/modprobe.d/alsa-base.conf during your tests please delete it and reboot your pi.

    sudo rm -f /etc/modprobe.d/alsa-base.conf
    

    Also if you have tried this for the AlexaPi project, make sure the service is stopped before you try your mic and audio.

    sudo systemctl stop AlexaPi.service