15

I have an onboard sound card, and also a connected bluetooth headset. I have configured the bluetooth device in /etc/asound.conf:

# cat /etc/asound.conf

pcm.bluetooth {
    type bluetooth
    device 12:34:56:78:9a:bc
    profile "auto"
}

ctl.bluetooth {
    type bluetooth
}

By default, the onboard card is used for all sound (apparently, the default onboard card does not even need to be listed in asound.conf)

When I want an application to use my bluetooth alsa device, I have to specify it, such as:

mplayer -ao alsa:device=bluetooth file.mp3

That's fine for me. But I need a way to tell my browsers to use bluetooth alsa device as well.

I have found a way how to start chromium using the --alsa-output-device commandline option:

chromium --alsa-output-device=bluetooth

I need a similar way to start firefox, but I could not find any.

How can I tell firefox to use my bluetooth alsa device, without having to modify /etc/asound.conf or ~/.asoundrc every time ?

UPDATE:

I have followed @lgeorget's advice and my /etc/asound.conf now looks like this:

pcm.!default {
type plug
slave.pcm {
        @func getenv
        vars [ ALSAPCM ]
        default "hw:0,0"
    }
}

pcm.bluetooth {
    type bluetooth
    device 12:34:56:78:9a:bc
    profile "auto"
}

ctl.bluetooth {
    type bluetooth
}

When I start firefox using ALSAPCM=bluetooth firefox, I do get sound in my bluetooth headset, but firefox runs at 100% CPU (on my 4 cores) and the youtube video plays at 10x speed (and the sound is correspondingly (garbled). I don't understand what's happening. When I start firefox without ALSAPCM=bluetooth, everything is OK, and sound plays on default alsa device.

2
  • 1
    Wow, a user with 21 gold badges and only 28 rep! How did you do it? Sep 20, 2016 at 11:32
  • 7
    @Dmitry Grigoryev - I spend everything on bounties ... Sep 20, 2016 at 13:35

3 Answers 3

11

Apparently there is no option for firefox, but you can manipulate the ALSA output through environment variables.

Try for example:

ALSA_PCM_CARD=bluetooth firefox

Alternatively, if this does not work, try scripting a little your .asoundrc

pcm.!default {
type plug
slave.pcm {
        @func getenv
        vars [ ALSAPCM ]
        default "hw:hdmi"
    }
}

(replace "hw:hdmi" with your normal pcm). Then if you want a program to use a specific PCM, use:

ALSAPCM=bluetooth firefox

Sources:

4
  • the first approach does not work. When I try the second approach, I do get sound in my bluetooth headset, but firefox runs at 100% CPU (on my 4 cores) and the youtube video plays at 10x speed. I don't understand what's happening. When i start firefox without ALSAPCM=bluetooth, everything is OK, and sound plays on default alsa device. Sep 15, 2016 at 10:26
  • There are different ALSA environment variables (see the link to the Archlinux wiki), maybe another one would work. I'm really surprised about the CPU problem, I don't see what could cause that.
    – lgeorget
    Sep 15, 2016 at 11:27
  • 1
    the CPU load is most likely caused by the fact, that the video and audio is being played and streamed at 10x speed. The mystery is why ALSAPCM=bluetooth changes video speed to 10x. Sep 15, 2016 at 11:32
  • @MartinVegter Well, I copy-pasted the definition of the pcm.!default in my post from a wiki, it might not be suited for your specific case. Especially the "type plug" and "slave" part.
    – lgeorget
    Sep 15, 2016 at 13:31
2

Remark: Current Firefox versions seem to ignore ~/.asound.conf on unknown reasons.

If you don't use pulseaudio (it is mainly an unneeded layer over alsa, despite that most distros install it), then in most cases, you only need to select the default audio output to a different one.

This can be done with the following .asound.conf in your home:

pcm.!default {
    type hw
    card N
}

ctl.!default {
    type hw           
    card N
}

Substitute N with a small integer, 0 for your first sound card (which is the default), 1 for your second, and so on.

The ! in !default isn't negation here! It is an overriding of the previously (system-wide defined) global alsa.conf .

More tricky configurations can be read here.

0

It looks like an incarnation of this bug. There are some solutions suggested, but they seem to be Intel specific.

Try using pulseaudio. If it works, you can redirect your ALSA programs to pulseaudio with the following asound.conf:

pcm.pulse {
    type pulse
}
ctl.pulse {
    type pulse
}
pcm.!default {
    type pulse
}
ctl.!default {
    type pulse
}

If that doesn't help, try adding rate 44100 or rate 48000 to the pcm.bluetooth section of your asound.conf. Maybe ALSA will come to its senses then.

You might also try Html5 Youtube Video Speed Controller, though I doubt it will help.

3
  • 2
    thanks, but I am not interested in solutions using pulseaudio. Sep 20, 2016 at 13:34
  • Sorry. Could you try that rate parameter then? Sep 20, 2016 at 14:07
  • with the rate parameter (both with 44100 and 48000), I get following error: ALSA lib audio/pcm_bluetooth.c:1449:(bluetooth_parse_config) Invalid type for rate. Looks like bluetooth does not support the rate parameter. Sep 21, 2016 at 18:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .