-
Notifications
You must be signed in to change notification settings - Fork 189
Setting up a USB audio device as a Bluetooth speaker under Ubuntu
This guide explains how to configure a USB audio (or onboard audio) device attached to a Ubuntu 22.04 machine as a bluetooth speaker.
Ubuntu 22.04 users can install bluez-alsa-utils
and the bluez
bluetooth configuration tools by running:
$ sudo apt install bluez bluez-alsa-utils
Note that Ubuntu 22.04 is the first release of Ubuntu to have the bluez-alsa-utils
package in its repos and at least one bug is known to be fixed in the latest code compared to the version in the 22.04 repos, automatic resampling of a2dp capture devices but this can be worked around with the ALSA configuration below.
Before we go any further, lets check Ubuntu recognises your machines Bluetooth adapter:
$ bluetoothctl show
This command will show the name of your Bluetooth controller if it has been recognised by the Linux kernel.
Edit /etc/systemd/system/bluetooth.target.wants/bluez-alsa.service
and modify the ExecStart
line so that it reads:
ExecStart=/usr/bin/bluealsa -p ad2dp-sink
ad2p-sink
is the only bluez-alsa profile required for a bluetooth speaker but if you were using a headset you would need to add -p a2dp-source
to this command.
Inform systemd that the service has been modified by running:
$ sudo systemctl daemon-reload
Unless you tell it to do otherwise, ALSA will default to using your computers onboard audio device, if it is supported by ALSA. In this guide we want ALSA to use an external USB audio device so we must first find out the ALSA device name of the audio device we wish to use to playback the bluetooth audio stream with. You may not need to create an ALSA config file if you are using the default audio device or a newer distro than Ubuntu 22.04.
You can list all of the audio devices currently attached and supported by ALSA by running:
$ aplay -L
There is a bug in the version of bluez-alsa-utils
used in the Ubuntu 22.04 repos that causes errors when resampling a2dp streams so under 22.04 we must use create a new ALSA pcm device that uses the ALSA plug plugin to fix this resampling issue.
aplay -L
told me that my USB audio device is called front:CARD=UACDemoV10,DEV=0
so I created a /etc/asound.conf
ALSA config file like this:
pcm.front-plug {
type plug
slave.pcm "front:CARD=UACDemoV10,DEV=0"
}
This code creates a new ALSA pcm device called front-plug
that uses my USB audio device, front:CARD=UACDemoV10,DEV=0
to output the audio and uses the ALSA plug
plugin to resample the stream so that it will play without errors. You will need to adjust the audio device name used by slave.pcm
but you can call this new device what you wish instead of front-plug
.
At this point you may want to either restart bluez-alsa and ALSA or just reboot your machine.
There are two steps to connecting your bluetooth device, pairing and connection. You usually only have to pair the device once but you will have to run the connect command each time you connect.
Enter the bluetoothctl console by running bluetoothctl
with no extra options then run scan on
. Turn the BT connection on your device and you should see it recognised with its address listed in the bluetoothctl
console. As soon as you've got the correct address to pair with, you can stopping scanning by running scan off
and then quit the bluetoothctl
console by typing exit
or quit
. You will usually only need to perform these steps to discover a devices address the first time you pair it.
You should now be able to pair and connect to your device by running:
$ bluetoothctl pair XX:XX:XX:XX:XX:XX
$ bluetoothctl connect XX:XX:XX:XX:XX:XX
If your device says it is connected to your Ubuntu machine under its bluetooth settings, you should now be ready to playback the a2dp steam (ie whatever audio is playing on your connected BT device) on your Ubuntu box by running:
$ bluealsa-aplay -D front-plug
Replace front-plug
with the name of the ALSA pcm device you want to use for playback or just run bluealsa-aplay
to use the default.