I am running latest Mopidy version (as a service) and it is perfectly working connected to my HiFi amplifier through Raspi audio output.
I am wondering if it’s possible to add also bluetooth streaming to a remote speaker, using internal Raspi bluetooth services, without disabling audio out to amplifier (both working).
On Raspbian you can select a bluetooth speaker as a default sink with an /etc/asound.conf configuration that looks like this (leveraging bluealsa, no pulse needed):
pcm.!default {
type asym
capture.pcm "mic"
playback.pcm "speaker"
}
pcm.mic {
type plug
slave {
pcm "hw:1,0"
}
}
pcm.speaker {
type plug
slave.pcm {
type bluealsa
device "BLUETOOTH_SPEAKER_PHYSICAL_ADDRESS"
profile "a2dp"
}
}
Routing the audio to two output devices at the same time might be a bit trickier though. A feature has been worked in the past to support multiple/plug’n’play outputs but as far as I know it’s been abandoned. Probably you can set up a gstreamer pipeline that copies the audio to two sinks, but I’m relatively confident that in the case of a bluetooth and a “standard” sink it might break. The most viable option I’d advise for now would be to leverage Snapcast: your mopidy instance can dump the audio to a snapserver pipe, and you can use two snapclient instances connected to two different sinks via pulseaudio.
You can use pulse to route the audio from an app to a specific output. Routing from the same app to multiple devices might be possible (https://askubuntu.com/questions/78174/play-sound-through-two-or-more-outputs-devices) but I’ve never tested it myself, as I personally prefer the mopidy+snapcast option as it gives me much more flexibility.
That abandoned feature was really about dynamic outputs (part of the MPD protocol we do not support). For a static setup where you are happy to always output to both Bluetooth and your soundcard then a custom Gstreamer pipeline similar to what is described in ours docs for Icecast should work. Something like the following lets me output to two soundcards so maybe you can adapt that:
[audio]
output = tee name=t ! queue ! audioresample ! alsasink device=hw:1,0 t. ! queue ! audioresample ! alsasink device=hw:2,0
Where hw:1,0 would be Card 1, device 0 and hw:2,0 is Card 2, device 0 (taken from the output of aplay -l on my system). I’m not sure if your bluetooth device would appear in aplay -l but you should also be able to refer to specific devices by name e.g. alsasink device-name=<something>.
Running Mopidy as your user or as the service? If the latter, the service runs as user mopidy which will have no idea about anything in your user .asoundrc file. It also may or may not have access to the bluetooth device. If the former, try pairing up those audioresample elements with an audioconvert element (wild guess).
Hello, I was wondering if it would be too crazy to this same thing but with two bluetooth speakers? This could save me some nasty wiring and saving the expense of an entire rpi for each speaker on my house.
You are great! The solution is also working for me with only a small issue I would like to resolve and I hope you can help me. The jack output and BT are working together as you described above but if I turn off my BT device the other output also falls silent with error in the log:
ERROR GStreamer error: gst-resource-error-quark: Error outputting to audio device. The device has been disconnected. (
ERROR GStreamer error: gst-resource-error-quark: Could not open audio device for playback. (6)
Is there a possible configuration to keep jack output working when the system does not find the BT device?
Hi, @fmarzocca I tried to follow the instructions but I am not able to make it work properly.
I have a Mopidy as a service, latest version in rpi. my audio works (with the jack) when I set output = alsasink instead of the default autoaudiosink. My bluetooth is paired and it works when used with youtube.
my .asoundrc looks like this
pcm.!default {
type asym
playback.pcm {
type plug
slave.pcm “output”
}
capture.pcm {
type plug
slave.pcm “input”
}
}
pcm.output {
type bluealsa
device “B9:12:32:79:B0:A2”
profile “a2dp”
}
however that does not work when testing separately
aplay -D output /usr/share/sounds/alsa/Noise.wav
Playing WAVE ‘/usr/share/sounds/alsa/Noise.wav’ : Signed 16 bit Little Endian, Rate 48000 Hz, Mono
aplay: set_params:1345: Channels count non available
ctl.!default {
type bluealsa
}
and I can’t make gst-launch-1.0 to play bluetooth following your command.
however I do get the test tone in bluetooth by testing with
gst-launch-1.0 audiotestsrc ! audioconvert ! audioresample ! alsasink