Audio routing using PulseAudio

· by tuxdna · Read in about 1 min · (160 words) ·

How to play audio on multiple devices on your Ubuntu machine?

Lets say we want to play audio on multiple output devices:

  • Bluetooth Speaker
  • PC Speaker

We can use pacmd[1] for this purpose.

List sources

$ pacmd list-sources |grep name:
	name: <bluez_sink.00_00_00_00_D2_89.a2dp_sink.monitor>
	name: <alsa_output.pci-0000_00_1f.3.analog-stereo.monitor>

List sinks

$ pacmd list-sinks | grep name:
	name: <bluez_sink.00_00_00_00_D2_89.a2dp_sink>
	name: <alsa_output.pci-0000_00_1f.3.analog-stereo>

We want to replay audio coming out from:

  • Bluetooth Speaker bluez_sink.00_00_00_00_D2_89.a2dp_sink.monitor
  • to PC Speaker alsa_output.pci-0000_00_1f.3.analog-stereo

We can simply create a loopback module that connects Bluetooth (source) to to PC Speaker (sink) using following command:

$ pacmd load-module module-loopback source="bluez_sink.00_00_00_00_D2_89.a2dp_sink.monitor" sink="alsa_output.pci-0000_00_1f.3.analog-stereo"

Lets see if our connection is showing up:

$ pacmd list-modules | grep name: | grep loopback
	name: <module-loopback>

Now all audio playback will be routed to both devices.

To remove the replay we just created above, we can simply unload that module:

$ pacmd unload-module module-loopback
$ pacmd list-modules | grep name: | grep loopback

I hope that is useful.

References:

[1] https://manpages.ubuntu.com/manpages/bionic/man1/pacmd.1.html