Ubuntu Bluetooth Headphones Fix

After extensive testing and research, I have put together a complete work-around for playing high-quality audio through Bluetooth headphones using the Blueman Bluetooth application. I haven’t bothered testing this with other Bluetooth applications. If memory serves me, the alternative Bluetooth apps lack the ability to choose audio profiles – but I might be wrong. Going forward, just understand that this was done exclusively with Blueman.

Bluetooth Working

Default Ubuntu Bluetooth settings work, but don’t work

By default, Ubuntu’s (and other distros’) Bluetooth settings provide working connections to most Bluetooth speakers and smartphones. Heck, using a cheap Bluetooth dongle on your computer, you can share your smart phone’s 4G Internet connection. Works incredibly well. And the same can be said when connecting to your Bluetooth speaker. Using the A2DP (Advanced Audio Distribution Profile) Bluetooth profile setting, today’s modern Bluetooth speakers work well because they only offer one profile – A2DP.

Bluetooth Speaker

This leads us back to Bluetooth headphones. While there are exceptions, many of these headphones are actually headsets. This means they serve as a means of speaking to others over the phone or VoIP. Complete with a microphone, these headsets are considered to be HSP/HFP (Headset Profile) devices first, A2DP (high quality audio) second.

So here’s the meat of the problem with these headsets acting as headphones – Ubuntu’s default Bluetooth settings don’t like to cooperate with A2DP settings. Just as frustrating, the microphone portion of HSP doesn’t work due to a known bug.

Let’s summarize:

– Bluetooth speakers using A2DP only work fine.
– Bluetooth headsets using HSP/A2DP do not. An exception to this might be headsets without HSP profile functionality.

To address this problem, we’re going to be editing some specific files so that we can get Bluetooth headsets to work correctly and provide us with A2DP functionality. This will allow us to enjoy high-quality audio for watching videos, listening to podcasts or simply enjoying our favorite music. Sadly, at this time I haven’t had any luck with getting HSP profiles to allow for microphone compatibility. This may be fixed sometime in the future.

Editing the right conf files

To make things work correctly, we’re going to edit the following.

/etc/Bluetooth/input.conf
/usr/bin/start-pulseaudio-x11
/etc/Bluetooth/main.conf
/etc/pulse/default.pa

Now, I highly recommend backing up each of these files before editing them.

sudo cp /etc/Bluetooth/input.conf /etc/Bluetooth/input.bak
sudo cp /usr/bin/start-pulseaudio-x11 /usr/bin/start-pulseaudio-x11.bak
sudo cp /etc/Bluetooth/main.conf /etc/Bluetooth/main.bak
sudo cp /etc/pulse/default.pa /etc/pulse/default.bak

By backing these files up, you’re able to restore them instantly should you find this doesn’t work with your headset in question. That said, if you follow my instructions, happen to be using bluez 5.37-0ubuntu5, pulseaudio 1:8.0-0ubuntu3.2 running on Ubuntu 16.04, you should have no problem getting this to work.

Important! Be aware that when I updated Ubuntu 16.04 to use a newer version of pulseaudio, I found that the ability to switch audio profiles wasn’t cooperating. I’m still testing the newer version of pulseaudio to see if any additional changes need to be made. Therefore, on my daily PC, I am only running with security updates and various PPAs – I’m not updating recommended or unsupported updates. This will change once I have a chance to better vet the newer pulseaudio package.

First, we have /etc/Bluetooth/input.conf to edit. With each file, my recommendation is to erase the contents of the original and replace it with my edited version of each file.

http://pastebin.com/nzzTQCUT

Erase the original contents of your /etc/Bluetooth/input.conf, then copy the above pastebin and make it your new /etc/Bluetooth/input.conf – the active part here is IdleTimeout=0, which should help prevent your Bluetooth from timing out.

Next we need to edit the /usr/bin/start-pulseaudio-x11 file:

http://pastebin.com/TSkxbQh6

The part of the file that matters here is below:

if [ x"$SESSION_MANAGER" != x ] ; then
/usr/bin/pactl load-module module-x11-xsmp "display=$DISPLAY session_manager=$SESSION_MANAGER" > /dev/null
fi

Now we begin editing the Bluetooth configuration itself, in /etc/Bluetooth/main.conf:

http://pastebin.com/CSH9dtVp

I won’t bother touching on all the parts of this file that allow stuff to work, but suffice it to say we’re setting this up with a minimal configuration.

Then finally, we have our system wide pulseaudio settings in /etc/pulse/default.pa:

http://pastebin.com/q1jB7qDs

In this file, you can find the changes by looking for Matt in the code. I added it for the sections that I tweaked for this file. For this file, I made changes to “load-module module-udev-detect tsched=0” and “load-module module-suspend-on-idle timeout=30.” Once again, this is informational only. You should be copying and pasting the entire configuration for each file after removing the original contents.

And that’s it! Assuming you backed up the original files, emptied the original file(s) contents, and pasted in my tweaked versions – you’re all ready to reboot your PC.

Blueman is the way to Bluetooth

With the computer rebooted, plug in your Linux compatible Bluetooth dongle. If your have Bluetooth installed on a laptop, just keep reading.

sudo apt install blueman

Now run Blueman, and then “Turn Bluetooth On” from the applet itself. Again from the applet, you will want to toggle down to Devices. First, put your headset into discoverable mode and then click Search on Blueman. Once Blueman detects the device, right click on the representative entry in Blueman, click Pair and then Trust.

Once the headset connects (it might take a moment), right click on the entry again and change the profile to Off. Turn off the headset. Now turn the headset on again, and then right click on entry and this time select the A2DP profile. From this moment on, you’re ready to listen to high quality audio through your Bluetooth headset.

So what about when you’re done with the headset? Well, you will need to stop the audio (music, etc) you’re listening to. Then go back to Blueman, right click on the entry and change the profile back to off. From here, you’re free to turn off and charge your headset.

The best part is that when you connect, your default sound device becomes the Bluetooth headset – automatically! And yes kids, this will work on other HSP/A2DP headsets as well.

Using Bluetooth headset on a daily basis:

Bluetooth Off

Once set up, here are the usage instructions

– Turn on headset, switch entry profile to A2DP – enjoy.

When finished listening to headset…

– switch Bluetooth entry profile to Off – turn off headset.

This last part is literally all there is to it now that we did the heavy lifting with the initial setup.

A2DP Profile

Equipment used for Bluetooth Audio

– Levn M32-black Hi-fi V+4.1 Stereo Bluetooth Headset
– Plugable USB Bluetooth 4.0 Low Energy Micro Adapter

I also tested this using another HSp/A2DP headset that was earbud in nature and tried this on a MBP running Ubuntu MATE, with built in Bluetooth. This also worked!

Troubleshooting Bluetooth Audio

Ideally Bluetooth audio should play perfectly. But that’s not the nature of Bluetooth technology being piped through your desktop computer. Sometimes lag can get the better of the situation.

Problem: Bluetooth pairs and connects, but you can’t change profile.

Solution:
– Erase your changed config files (you backed up the originals), try again following the above guide.
– Verify you’re using bluez 5.37-0ubuntu5, pulseaudio 1:8.0-0ubuntu3.2 on Ubuntu 16.04 LTS.  I still need to test the newer releases of both packages before signing off on them.

Problem: Bluetooth works, but then it starts skipping and disconnects.

Solution:
– Use a USB extension cable if you’re using a Bluetooth dongle on a desktop PC.
– Position Bluetooth dongle closer to where you use your headset.
– Sometimes bringing up dialog boxes or other PC activity can in rare cases make things skip.
– Some javascript heavy pages loading can in some systems, allow your audio to skip.
– Perhaps most importantly, returning from a PC suspend state can add latency and create skipping.
– Other considerations that can interfere with Bluetooth can be found here.

Also check out...

Matt Hartley
Freedom Penguin’s founder & talking head – Matt has over a decade working with Linux desktops, his operating system experience consists of both Windows and Linux operating platforms. In addition to writing articles on Linux and open source technology for Datamation.com and OpenLogic.com/wazi, Matt also once served as a co-host for a popular Linux-centric podcast.

Matt has written about various software titles, such as Moodle, Joomla, WordPress, openCRX, Alfresco, Liferay and more. He also has additional Linux experience working with Debian based distributions, openSUSE, CentOS, and Arch Linux.

Leave a Reply

9 Comments on "Ubuntu Bluetooth Headphones Fix"

Notify of
Sort by:   newest | oldest | most voted
Jay LaCroix
Member
I’ve been having issues with my Bluetooth headphones on Ubuntu, but I’m not sure that my problem is the same as yours so I’m not sure if your tweak will work for me. On my end, when I pair my headphones, they will work great the first time. I basically pair them, switch to the appropriate profile, then open pavucontrol to configure it to send audio to my headphones. This all works. But I have the following issues: 1.) When I turn my headphones off and then on, I have to reconfigure pavucontrol again to send audio to my headphones.… Read more »
Matt Hartley
Member
Hi Jay, Based on what your describing, yes, this tweak will fix things as I described above using Blueman – make BT audio sound work reliably – however, you will not merely turn on BT and have the profile switch, you need to do that as mentioned in the article. Also, this will make your default sound card (playback) the Bluetooth headphones once the profile is switched to A2DP – automatically. You do not need to touch pavucontrol to switch devices. When Bluetooth disconnects, your speakers will resume their normal active duties. This approach also backsups the changed files using… Read more »
disqus_hN2pyRSnG3
Member

That’s a giant sized PITA for these newbs with a $5 bluetooth dongle. That config should be defaulted in Ubuntu if it works.

Matt Hartley
Member

I agree it’s a PITA, however this is a long standing issue with Bluez/pulseaudio affecting other distros as well. Ubuntu just pulls from what’s available. Having experienced similar stuff with Bluetooth in Windows, I’ve found the difference here is I can find a fix – in Windows, if it’s a no-go, you’re just boned short of a manufacturer fix. 😉

Szymon Stasik
Member

What is the well known bug affecting the HSP/HFP? I’m trying to find the real reason blocking the use of microphone with linux recently

quage
Member
Hello Matt, thanks for this post. I’m running Mint 18 Cinnamon and trying to (re-)connect devices involved a ridiculous amount to turning things off and turning them back on again. Your settings overcome that (mostly). Here are some extra notes for anyone else anyone else running Mint 18 Cinnamon: 1) “Blueman” = “Bluetooth Manager” and “Turn Bluetooth On” = “Enable Bluetooth” 2) Right-click Pair doesn’t work – you need to use Setup 3) Turn your headset off and back on again after initial pairing 4) Mic won’t work at all because /usr/share/cinnamon/cinnamon-settings/modules/cs_sound.py still has a bug – see https://github.com/linuxmint/Cinnamon/issues/5472 –… Read more »
SuperMin
Admin

Haven’t had need of number 6 myself, so if works, awesome. Perhaps #6 helps with the lag after resume (only time I have had lag on my i7). I’ll have to play with it later.

Remember folks, back up those files before making changes. Even simple ones. Helps if you walk away and forget when you changed later. 🙂

quage
Member

Well, it turns out that #6 did not fix the audio problems. After a fresh restart and auto-connect of my headphones to A2DP the problems were back. Part of the procedure described in this post involves swapping audio profiles between A2DP and HSP/HFP and this apparently causes Pulse to resync. It’s a bug that’s been around for a long time: https://bugs.launchpad.net/ubuntu/+source/bluez/+bug/1211102 and I can confirm that, if I manually switch to HSP/HFP and then back to A2DP, audio is clean and in sync.

SuperMin
Admin

…and auto-connect of my headphones to A2DP the problems were back.

As per this article, you cannot autoconnect – you merely need set things up once as described above. Then…

– Turn on headset, switch entry profile to A2DP – enjoy.

When finished listening to headset…

– switch Bluetooth entry profile to Off – turn off headset.

Also, I found #6 didn’t actually do anything on two different computers, so I didn’t include it in the article. Autoconnection is a nice idea, but hardly needed. 🙂

wpDiscuz