How to make Alsa pick a preferred sound device automatically?

Solution 1:

Find your card with

$ cat /proc/asound/cards

To get valid ALSA card names, use aplay:

$ aplay -l

and then create /etc/asound.conf with following:

pcm.!default {
    type hw
    card 1
}

ctl.!default {
    type hw           
    card 1
}

Replace "card 1" with the number or name of your card determined above.

Alternatively, you can change ordering of your cards so your USB card will be card 0 and it will work without editing asound.conf.

Solution 2:

this is the method for selecting default sound card in Alsa. You may want to install Alsa for this method to work if you are using Pulse Audio.

cat /proc/asound/modules

will list your sound modules .The output of the command will be like this (eg):

0 snd_hda_intel

1 snd_usb_intel

you can pretty easily understand which one is your usb sound card from above.

nano /etc/modprobe.d/alsa-base.conf

edit this alsa-base.conf in such a way that your preferred card has an index =-2 / 0 and the other card has index =-1 / 1 (stick with -2 and -1 )

options snd_hda_intel index=-1

options snd_usb_intel index=-2

in this case usb device is preferred device.

if you are having two differnt cards with same name from the output, like this:

options snd_hda_intel

options snd_hda_intel

issue this command to find out which is which:

cat /proc/asound/cards

then edit modules in this way:

options snd_hda_intel enable=1 index=0

options snd_hda_intel enable=0 index=1

a reboot may be necessary.so you might have to manually switch over your sound cards.

Solution 3:

I also couldnt get output from my USB device. My cat /proc/asound/modules output was:

0 snd_hda_intel

1 snd_hda_intel

2 snd_usb_audio

I have tried both answer described here which didnt help (with many index combination and lot of restart). I think problem was my USB device initialize after boot-up. Whatever, so my working solution is blacklisting other 2 sound device by updating /etc/modprobe.d/blacklist.conf as:

blacklist snd_hda_intel