Skip to content

Instantly share code, notes, and snippets.

@mgbckr
Last active November 22, 2023 09:03
Show Gist options
  • Save mgbckr/1e994da0c408004d563e1b1d3952d630 to your computer and use it in GitHub Desktop.
Save mgbckr/1e994da0c408004d563e1b1d3952d630 to your computer and use it in GitHub Desktop.
Method to make audio quality better for bluetooth headsets on linux (Fedora 34) using mSBC
#!/bin/bash
# source: https://bbs.archlinux.org/viewtopic.php?pid=1973004
# prepare via enabling mSBC codec for HSP/HFP:
# https://wiki.archlinux.org/title/PipeWire#Low_audio_quality_on_Bluetooth
# the `bluez-monitor.conf` is located at:
# `/usr/share/pipewire/media-session.d/bluez-monitor.conf`
# note that the settings gui needs to be restarted after editing the file and calling
# `systemctl --user restart pipewire.service`
#msbc=`pactl list | grep Active | grep msbc`
a2dp=`pactl list | grep Active | grep a2dp-sink`
echo "Profiles:"
#echo $msbc
echo $a2dp
echo
card=`pactl list | grep "Name: bluez_card." | cut -d ' ' -f 2`
echo Card:
echo $card
echo
if [ -n "$a2dp" ]; then
echo "Switching $card to msbc..."
pactl set-card-profile $card headset-head-unit-msbc
echo "...done"
else
echo "Switching $card to a2dp..."
pactl set-card-profile $card a2dp-sink
echo "...done"
fi

README

I tried making the audio quality (listen and record) better for Jabra 85t on Fedora 34. This (using mSBC) is what worked for me. Still not A2DP quality but better than the default (HSP/HFP).

Update (2021-11-29): The same script works for Aftershokz OpenComm and probably for many other bluetooth headsets.

Prerequisties

I am using Fedora 34 with PipeWire (PulseAudio replacement) installed and enabled.

Enable mSBC

Source: https://wiki.archlinux.org/title/PipeWire#Low_audio_quality_on_Bluetooth

Edit /usr/share/pipewire/media-session.d/bluez-monitor.conf (this path is different from the source above)

...
rules = [
  ...
  actions = {
    ...
    update-props = {
     ...
     bluez5.msbc-support = true  # enable this (uncommented by default)
...

Then restart PipeWire: systemctl --user restart pipewire.service

Changing profiles

Systems Settings GUI

After restarting PipeWire you need to close and reopen the audio settings GUI (Systems Settings) in case you are changing the profiles there (I am still using X11 + KDE). Otherwise changing profiles there doesn't do anything.

Scripting

Alternatively, you can run a script to switch back and forth between A2DP and the new HSP/HFP with mSBC profiles: bash switch_bluetooth_profile.sh

@JittoJoseph
Copy link

i am running ubuntu 22 and i didnt have the file /usr/share/pipewire/media-session.d/bluez-monitor.conf

@aanno
Copy link

aanno commented Sep 4, 2023

The

a2dp=`pactl list | grep Active | grep a2dp-sink`

is problematic if you use a non-english locale. E.g. it should be

a2dp=`pactl list | grep Aktives | grep a2dp-sink`

for German.

Hence to resolve the issue, prepend the following to the script

export LANG=C
export LC_ALL=C

Than it works like a charm even for German speaking users.

@DrainGangScholar
Copy link

i am running ubuntu 22 and i didnt have the file /usr/share/pipewire/media-session.d/bluez-monitor.conf

did you manage to fix this?

@petre2dor
Copy link

@DrainGangScholar You can just create that file or ~/.config/pipewire/media-session.d/bluez-monitor.conf. Works the same.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment