Bluez pulseaudio module bluetooth

Bluez pulseaudio module bluetooth

A2DP is the «Advanced Audio Distribution Profile», a standard for how Bluetooth devices can stream high-quality audio to remote devices. This is most commonly used for linking wireless headphones and speakers to your PC. The instructions in this page should apply to any A2DP-compatible device.

Pre-configuration

In short: To connect to a given device, you need Bluetooth hardware on your PC (either built-in, or in the form of a USB dongle), the Bluez daemon, and a compatible audio server (either PulseAudio or PipeWire).

Firmware

If your hardware supports Bluetooth but Debian is unable to find any Bluetooth devices, you may have a dongle based on a Broadcom BCM203x chipset, requiring extra firmware to be installed.

Add a non-free component to your apt sources and install the bluez-firmware package.

PulseAudio

PulseAudio is the default audio server in Debian. Unless you know what you’re doing, you probably want to follow these instructions.

Install the pulseaudio-module-bluetooth package if it’s not already installed. You probably also want pavucontrol (or pavucontrol-qt on LXQt or Plasma desktops) to configure your device after connecting it.

Once you have installed the Bluetooth module, it may be necessary to restart the bluetooth and pulseaudio services:

# service bluetooth restart $ killall pulseaudio

After connecting your device (see the «Pairing» section), your device will appear in Pavucontrol, where you can set it as your default audio output device, change individual applications to output using it, configure its profile, etc.

PipeWire

These instructions are mutually exclusive to the PulseAudio section, for users that are using the newer PipeWire audio server instead. This is also documented on the PipeWire wiki page in brief. Note that simply having the pipewire package installed does not mean this section is relevant to you, as it needs to have also been specially configured to replace PulseAudio.

In Debian, PipeWire supports more modern codecs than PulseAudio without the need to install any external modules. In particular, PipeWire 0.3.26 supports mSBC, SBC, SBC-XQ, LDAC, AptX, and AptX-HD. It also supports the HSP_HS, HSP_AG, HFP_HF, and HFP_AG headset roles. Support for more codecs is in-progress.

At minimum, you will need to install the libspa-0.2-bluetooth package, remove the pulseaudio-module-bluetooth package (if previously installed), and then either reboot your computer or restart the PipeWire services, otherwise device connections will fail with «Protocol not available».

Note that, if you’re using the GNOME desktop, the gnome-core package has a hard dependency on pulseaudio-module-bluetooth. Attempting to remove it will also prompt to remove your desktop. If you run into issues when attempting to use Bluetooth with this package installed, you may still have to use PulseAudio in order to have functioning Bluetooth audio.

Читайте также:  Sony колонки подключить блютуз

PipeWire will attempt to choose the best possible codec by default. You can override this, and tweak many other related settings, in the /etc/pipewire/media-session.d/bluez-monitor.conf file. You can edit this directly, or store local per-user changes by copying the file to ~/.config/pipewire/media-session.d/bluez-monitor.conf and editing that instead. You can check the currently-used codec with pactl list sinks

ALSA only

If you want to completely avoid using a higher-level audio server like PipeWire or PulseAudio, see BlueALSA. Currently only available in Debian Unstable.

Pairing

It is also highly recommended to install a graphical pairing tool. GNOME relies on gnome-bluetooth, after which you can find a «Bluetooth» section of your settings. KDE Plasma relies on bluedevil, which is a module for your system settings, a system tray applet, and a wizard for connecting to your devices. Other desktops can use the agnostic blueman tool.

More information, and instructions on using the CLI bluetoothctl tool, can be found on the main BluetoothUser page.

Troubleshooting

Refused to switch profile to a2dp_sink: Not connected

Your Bluetooth headset is connected, but PulseAudio fails to pick up the connected device, or there’s no device to pick. This happens because GDM captures A2DP sink on session start, as GDM needs PulseAudio in the GDM session for accessibility. For example, the screen reader requires it. See 805414 for some discussion.

Workaround 1: Disable PulseAudio in GDM

In order to prevent GDM from capturing the A2DP sink on session start, edit /var/lib/gdm3/.config/pulse/client.conf (or create it, if it doesn’t exist):

autospawn = no daemon-binary = /bin/true

After that you have to grant access to this file to Debian-gdm user:

chown Debian-gdm:Debian-gdm /var/lib/gdm3/.config/pulse/client.conf

You may also need to disable PulseAudio startup (however in Debian 10/Buster and newer, this has already been removed in the gdm3 postinst):

rm /var/lib/gdm3/.config/systemd/user/sockets.target.wants/pulseaudio.socket

In order to auto-connect A2DP for some devices, add this to /etc/pulse/default.pa:

load-module module-switch-on-connect

Now your audio device should be accessible through pavucontrol and your desktop’s standard audio settings.

Workaround 2: Disable PulseAudio’s Bluetooth in GDM

The actual solution package maintainers are looking into next is to simply disable the Bluetooth sink in the GDM PulseAudio daemon so that it doesn’t take over the device. Add this to /var/lib/gdm3/.config/pulse/default.pa:

#!/usr/bin/pulseaudio -nF # # load system wide configuration .include /etc/pulse/default.pa ### unload driver modules for Bluetooth hardware .ifexists module-bluetooth-policy.so unload-module module-bluetooth-policy .endif .ifexists module-bluetooth-discover.so unload-module module-bluetooth-discover .endif

This was first discovered in the Arch wiki.

Solution

The actual solution is for PulseAudio to release the Bluetooth device when it is not in use. This is discussed in the PulseAudio 845938 which has a few upstream bugs pending as well that are related.

Читайте также:  Jbl bluetooth наушники разборка

Unable to control volume with volumeicon-alsa

The volumeicon tray icon may not automatically recognize a Bluetooth A2DP device when a connection is established. See issue #73, «volumeicon does not work to adjust bluetooth volume» and issue #49, «change of the default device not automatically detected» for discussion and possible workarounds / fix. You might also try simply restarting Volumeicon, or adjusting your PulseAudio configuration to switch on connect.

a2dp-sink profile connect failed [. ]: Protocol not available

This error can appear when using PipeWire as your audio server and attempting to pair a device via Bluetooth, without first uninstalling the pulseaudio-module-bluetooth package.

If you’re using PulseAudio, PulseAudio may not be properly connecting to the device. It might be because it was already playing. Stopping anything playing on PulseAudio, restarting PulseAudio, and reconnecting to the device may fix the problem.

In addition, you need the following settings in /etc/pulse/default.pa or /etc/pulse/default.pa.d/bluez5.pa:

load-module module-bluez5-device load-module module-bluez5-discover

AptX, LDAC, and AAC codecs are not available with PulseAudio

While newer audio codecs such as AptX and LDAC are available in PipeWire, they’re still unavailable for PulseAudio users in Debian. AAC is unavailable outright because the library is non-free. However, PulseAudio has recently gained support for all of these codecs via GStreamer. Unfortunately, GStreamer is only supporting these codecs from v1.20 onwards. This means that support for modern codecs with PulseAudio is not available in Debian 10 or Debian 11. It is expected to land in Debian 12.

A third-party project adds support for these additional codecs as well. It is deprecated and the creator recommends users either avoid it entirely, or switch to PipeWire. Nonetheless, it’s still a fully functional option in Debian 10: https://github.com/EHfive/pulseaudio-modules-bt

Additionally, a third-party script for Debian 10 is available which will automatically configure and install the additional codecs via the deprecated pulseaudio-modules-bt project: https://github.com/lagerimsi-ds/debian-buster_bluetooth_aptX-LDAC

If the PulseAudio sink adjusts automatically to SBC-sink (not A2DP-sink with aptX or LDAC), just reconnect your device.

See also

  • BluetoothUser — Main page for Bluetooth in Debian
  • BlueDevil — Bluetooth with KDE Plasma
  • BlueALSA — Bluetooth over ALSA alone

Источник

Linux. Делаем Bluetooth колонку из ПК

Соглашусь, задача странная на первый взгляд. Но по крайне мере я искал информацию об этом и судя по сообщениям на форумах я не единственный и явно не последний. А поскольку такой простой инструкции на русском языке в интернете нет, я её напишу.

Я делал такое на Debian 9 x32, Lubuntu 18.04 x32, Debian 11 x64 и Ubuntu 21.04, на других дистрибутивах даже не основанных на Debian тоже будет работать если там можно установить приложения упомянутые в этой инструкции. Действия описаны на примере Debian, если у вас другой дистрибутив замените apt на ваш пакетный менеджер или ищите иной способ установки тех же приложений.

Читайте также:  Bluetooth hp probook 4520s

Требования

Подключённое и исправное устройство вывода звука (наушники/колонки/динамики) и рабочий сервер PulseAudio. Чтобы это проверить воспроизведите что-нибудь через mplayer с ключом -ao pulse , например мой рингтон.

sudo apt-get install mplayer -y mplayer -ao pulse https://iasivan.ru/ringtone_zemlyane.mp3

Ну и конечно же Bluetooth адаптер. Он может быть встроенный либо внешний, подключённый в USB. Не знаете есть ли он? Проверьте.

Приступим

Устанавливаем необходимые 3 пакета.
BlueZ — стек основных протоколов Bluetooth
Bluetooth — служба и консольный интерфейс для работы с Bluetooth
pulseaudio-module-bluetooth — связующее звено между Bluetooth и PulseAudio

sudo apt-get install bluetooth bluez pulseaudio-module-bluetooth -y

Добавим 2 плагина в автозапуск PulseAudio. Для этого нужно в файл /etc/pulse/system.pa дописать две строки. Сделаем это через echo чтобы вы могли просто скопировать команды даже не читая этот текст.

sudo echo "load-module module-bluetooth-policy" >> /etc/pulse/system.pa sudo echo "load-module module-bluetooth-discover" >> /etc/pulse/system.pa

Ну и конечно же перезапустим службу bluetooth и сервер PulseAudio. Именно в таком порядке.

sudo systemctl restart bluetooth.service pulseaudio --kill sleep 1 pulseaudio --start

По сути уже можно использовать, но такое устройство будет отображаться в Bluetooth поиске как ПК, заменим class устройства в поиске оно считалось колонкой.
Для начала отключим плагин hostname в bluetoothd чтобы class не считывался с самого устройства. Открываем файл /etc/systemd/system/bluetooth.target.wants/bluetooth.service, находим в нём параметр ExecStart и в конце строки дописываем —noplugin=hostname .

sudo nano /etc/systemd/system/bluetooth.target.wants/bluetooth.service

Теперь собственно сменим class. Открываем файл /etc/bluetooth/main.conf, в нём находим параметр class , убираем # в начале строки если есть, стираем текущее значение и вводим то что соответствует колонке, а именно 0x1c0420 . Можно и не только колонкой его сделать, class другого устройства можете нагуглить.

Поскольку мы отключили плагин hostname у ПК не будет название в поиске Blutooth. Чтобы это исправить редактируем файл /var/lib/bluetooth/00:1A:7D:DA:71:13/settings, при чём вместо 00:1A:7D:DA:71:13 будет адрес вашего адаптера. Удобнее всего найти файл settings через консольный файломый менеджер mc. Папка в нём открывается на Enter, навигиция стрелочками на клавиатуре, редактировать выбранный файл — F4.

sudo apt-get install mc sudo mc /var/lib/bluetooth/

В этот файл пишем следующее. Вместо IAS-Speaker придуманное вами название.

После проделанного разумеется перезапускам службу bluetooth.service.

sudo systemctl restart bluetooth.service

Использование

Открываем bluetoothctl — это консольный интерфейс управления Bluetooth. Делаем устройство видимым и доступным.

discoverable on pairable on

Ищем устройство с телефона. Отправляем запрос на сопряжение и на телефоне соглашаемся.

В терминале появится строка вроде [CHG] Device A4:55:90:BF:4B:1F Connected: yes здесь A4:55:90:BF:4B:1F это адрес телефона, его нужно добавить в доверенные чтобы с телефона можно было подключаться.

Из bluetoothctl можно выйти командой exit. В таком случае ПК перестанет отображаться в поиске, но с телефона который мы добавили в доверенные можно будет подключиться в любое время. ПК будет работать как колонка, звук выводимый телефоном на Bluetooth колонку будет воспроизводиться в динамики/колонки/наушники ПК.

Всего вам хорошего, друзья!
Изучайте Linux. Используйте Linux. С ним ваши возможности почти безграничны.

Источник

Оцените статью
Adblock
detector