60

I have paired my Bluetooth headset with my Ubuntu 12.04 laptop with a Bluetooth chip inside:

lsusb | grep Bluetooth

Bus 003 Device 003: ID 045e:0745 Microsoft Corp. Nano Transceiver v1.0 for Bluetooth

The device has been paired, and with the help of blueman, I've connected it to PulseAudio as a sink. Audio does come across in A2DP mode, but is terribly choppy and skips to the point of being not much better than nothing.

I read around and saw that there was a fix involving adjusting the nice priority of the PulseAudio server. Since by default, PulseAudio runs on a per-user basis, I added the following to my /etc/security/limits.conf:

*       hard    rtpio   0
*       soft    rtpio   0
@audio  hard    rtpio   20
@audio  soft    rtpio   20
pulse   hard    rtpio   20
pulse   soft    rtpio   20

I then added myself to the audio group to be able to schedule priority for the pulseaudio process. It seems that pulseaudio is now running with a priority of -11:

ps -eo pri,ni,cmd | grep [p]ulse

30 -11 /usr/bin/pulseaudio --start --log-target=syslog

This should mean that PulseAudio is running with a priority of -11, which is good.

However, even after restarting, I still get the terrible choppy audio.

How should I proceed? I'm trying to make this Bluetooth headset I purchased usable.

Note: I've tried pairing this device with an Android tablet right next to my laptop and it works fine, so it's not wireless congestion, it seems to be directly correlated to Linux somehow.

Naftuli Kay
  • 4,226
  • I have the same problem with playing videos — where sound latency offset cannot be a solution, unfortunately. So I am pretty desperate. Any ideas? – KiriSakow Feb 15 '21 at 17:25
  • which media player you are using ? if vlc. please try a different media player like :- firefox, chrome, parole media player . It works for me. because bluetooth give choppy sound only for vlc, bot for others media player. – jak bin Feb 06 '24 at 05:34

7 Answers7

111

As none of the other answers worked on my system (Ubuntu 18.04 LTS on a 2012 MacBook Air), I found my solution on the german ubuntuusers wiki. English summary of the german instructions:

The choppy output might be caused by the A2DP implementation, and how it buffers sound before encoding it. For me, changing this buffer's size solved the choppy sound problem. You need to perform three steps:

  1. Find necessary info about the bluetooth device (while it is connected!)

    pactl list | grep -Pzo '.*bluez_card(.*\n)*'
    

The output should be something like

    Name: bluez_card.28_11_A5_84_B6_F9
    Driver: module-bluez5-device.c
    ...
    Ports:
    speaker-output: Speaker (priority: 0, latency offset: 0 usec, available)
        Part of profile(s): a2dp_sink, headset_head_unit
    speaker-input: Bluetooth Input (priority: 0, latency offset: 0 usec, not available)
        Part of profile(s): headset_head_unit

We see that the buffers have currently 0 latency. In the next step, you will need the NAME and PORT of your output. In this example, these are bluez_card.28_11_A5_84_B6_F9 and speaker-output, respectively.

  1. Set the buffer size (latency) of your card to a suitable value with this command pattern:

    pactl set-port-latency-offset <NAME> <PORT> <BUFFER_SIZE_MICROSECONDS> 
    

The latency unit of the following command is microseconds, so I'm using a 50 millisecond buffer for my command here:

    pactl set-port-latency-offset bluez_card.28_11_A5_84_B6_F9 speaker-output 50000 
  1. Restart your bluetooth service to apply your change

    sudo service bluetooth restart
    

As there is usually no documentation about this, you may have to experiment with higher or lower buffer values. Many people people posted their working latencies in the comments to this answer. Check them out for guidance on the latency value.

Chris_128
  • 1,211
  • 7
    You deserve more upvotes! I would like to mention that 45000 works well for the Macbook Air (early 2014) and Bose QC35 – Ole Aldric Mar 13 '20 at 11:42
  • 1
    This is correct, thank you – jhtong Apr 19 '20 at 03:11
  • 3
    Still stuttering for me :( (Manjaro) – Lucas Bustamante May 11 '20 at 14:38
  • Which latencies did you try? – Chris_128 May 12 '20 at 09:35
  • 3
    a much smaller value worked most of the time, but I had to crank it up to 64448 to get rid of skips when doing stuff like inspecting elements in chrome and changing styles. – Nick May 15 '20 at 21:13
  • 1
    Seems to work on ubuntu 20.04 with external dongle and Sony WH-CH710N. I'm testing a little bit more and later I'll give a thumbs up. – rneves Aug 24 '20 at 19:45
  • 1
    Finally a solution which fixed the sound for my Sennheiser MTW2! Thanks, @Chris_128! That stuttering was driving me mad... Strange that I never had this issue with my older Sennheiser M2 AEBT... Why is that? Linux Mint 20 here (Ubuntu 20.04) – Ed'ka Sep 23 '20 at 14:45
  • 1
    Hm... there is a twist: I recently had to remove my M2 AEBT from the list of devices on my Mint and then when I paired them back they initially exhibited the same stuttering :-/ I had to add 100ms latency to fix it but it showed that the problem was probably introduced to Linux recently but somehow it didn't affect the already registered devices. Not sure how it is possible, but that was my experience. – Ed'ka Sep 26 '20 at 09:26
  • Interesting, thanks for sharing! You didn't by chance check the latency if your M2 AEBT before you removed it? Maybe before, it had automatically received a sensible default value (like 100ms) and some bug in a new update sets the delay (buffer) to zero for newly added devices. – Chris_128 Sep 26 '20 at 10:25
  • 1
    This works! <3

    I ran the command then I went to the sound preferences and switched the speaker to built in and then to bluetooth again - that kind of resets it and it started working.

    – Salar Khan Sep 26 '20 at 20:37
  • 1
    This works, but my latency value has to be set to a much higher value though, 250000 for now – Jeffrey04 Oct 28 '20 at 22:54
  • 1
    Works on Pop!_OS (20.10) on an old Mac mini with Sony XM3s and external BT dongle, latency of 65000 – Kyrre Oct 29 '20 at 09:55
  • Sound latency offset cannot be a solution for playing video, unfortunately. – KiriSakow Feb 15 '21 at 17:17
  • On the contrary, it can be a solution. If the offset is smaller than human perception levels, there is no issue. Perception of audio-to-video offset depends on content, but very broadly speaking, it is around ~100ms, see https://link.springer.com/article/10.3758/s13414-015-1026-y. – Chris_128 Feb 16 '21 at 19:44
  • 1
    50000 latency value worked for me on Ubuntu 20.04 running on Macbook pro 2019 model. – Srisa May 29 '21 at 13:29
  • 1
    This worked for me too! But what would be the canonical way to make this configuration persist across restarts? – Shon Aug 19 '21 at 18:57
  • 1
    5000 latency offset worked for me. Thanks for sharing this! – brunodd Nov 05 '21 at 11:05
  • 3
    Works for me on 20.04 LTS, Sennheiser CX400BT used @OleAldric 's latency 45000 – prabhu Nov 07 '21 at 12:27
  • 1
    This worked for me, but I had to crank it up to 100,000 latency. I'm using Ubuntu 20.04.03 on a Dell Vostro 3460 and JBL Endurance Peak II bluetooth earbuds :) – Faust Feb 14 '22 at 20:09
  • 2
    This works for me (ubuntu 22.04). knb's method below works too and it doesn't involve command line commands. – Andrei B Jun 17 '22 at 12:07
  • Yeah, I suspect that my method is doing the same as @knb's below, but just with command line instead of GUI. If you set the latency with one mode (command line vs GUI), do you see that value in the other mode? – Chris_128 Jun 19 '22 at 19:53
  • 1
    Literal lifesaver. I thought this problem was related to bluetooth low-energy mode or something, but this just fixed it. – xjcl Jul 11 '22 at 15:00
  • 1
    Thank you! This helped me make my Fairphone earbuds work smoothly together with 22.04 (It worked the day before, but today something in my environment has changed and i heard stuttering, like when a CD has scratches. This solved it.) – Hoov Nov 09 '22 at 21:56
  • I get "Failure: No such entity". I think the port "speaker-output" doesn't work for me. How do I find which port to use? – Lost Crotchet Jan 31 '23 at 01:08
  • I now tried the port as "headset-output". The command worked this time, but after restarting my computer, I still have terrible bluetooth headset output – Lost Crotchet Jan 31 '23 at 01:36
  • I find my bluetooth device i've connected the info in the first step, however there's no ports at all? What do I do? – snipers500 Mar 18 '23 at 02:49
  • 1
    Appears to work for 75000µs, on Ubuntu 22.04.2 LTS, for a Sony WH-1000XM3, kernel 5.15.0-67-generic and 1:15.99.1 for pulsaudio-bluetooth. A latency of 50k already improved significantly, from there I stepped it up in 5000 steps. – jippie Mar 26 '23 at 11:41
49

Edit the ALSA configuration file

sudo gedit /etc/modprobe.d/alsa-base.conf

Add the line

options snd-hda-intel model=generic

to the end of the file, and restart the bluetooth service:

sudo service bluetooth restart
brianrobt
  • 103
  • 3
    This worked wonderfully for my BOSE quiet comfort 35 II speakers (ubuntu 18.04) – Victor Parmar Jun 26 '18 at 12:39
  • This simple fix also worked for me after a lot of searching. Ubuntu 18.10, bluetooth earphones (promate trueBlue). – Francesco Napolitano Nov 20 '18 at 14:15
  • Created an account to mention that this solved my problems too (QC35II). An explanation would be helpful; but either way, you are a life saver – Sam Jan 03 '19 at 10:34
  • I see about 95% less choppiness with this fix with QC35II on Debian 9 testing, kernel 4.18.20-2. – Andrey Portnoy Jan 05 '19 at 07:52
  • 1
    Although there's this Canonical article that advises against doing this: In particular, avoid model=generic – that is almost guaranteed to give you trouble. In many cases, when trying different models, you will find that you might fix one thing but break another. http://voices.canonical.com/david.henningsson/2012/07/13/top-five-wrong-ways-to-fix-your-audio/ – Andrey Portnoy Jan 05 '19 at 07:57
  • I tried setting options snd-hda-intel model=auto instead as they seem to recommend, but that didn't work as well. Sticking to options snd-hda-intel model=generic for now. Thank you! – Andrey Portnoy Jan 05 '19 at 08:05
  • 8
    at the end after editing this file you don't need to restart, just run sudo service bluetooth restart – Dinuka Salwathura Jan 13 '19 at 03:49
  • This worked like a charm at first. However, it sometimes randomly stops working after the machine stays on for a longer time, or after it goes to sleep and comes back. Any ideas? – grzkv Apr 06 '19 at 22:26
  • In my case only after restarting ubuntu, BOSE quiet comfort 35 II worked perfectly with any music app like spotify and conferences like appear/whereby and hangouts. – Capy Aug 24 '19 at 16:42
  • This worked for me too in ubuntu 10.05 for Padmate pamu slide. – Pericolo Sep 22 '20 at 00:20
  • This also worked for me on Archlinux! I have Sony 1000xm3 and had occasional stuttering. – Martinsos May 03 '22 at 12:08
  • Perfekt, simple solution and works. Here with Ubuntu 22 and JBL. – fischermatte Nov 11 '22 at 16:01
  • Damn! it solve my QC35 II randomly choppiness with Ubuntu 22.04. How it works? – Kuang Wenyi Apr 18 '23 at 20:02
14

You can open the search bar (CTRL-D in unity, Windows-Key in Gnome) type in "Pulse" or "Volume". Open the GUI tool "Pulseaudio Volume Control", its icon looks like knob or gauge.

There you can select your Bluetooth speaker. Click on Advanced, set the Latency value just like proposed in the other answers . 45 ms or 50 ms seems to work for them, but I haven't found a good value that works for me.

A screenshot is attached. My Bluetooth Speaker is called SRS-BTX300. You don't need to restart bluetooth after changing the latency value.

enter image description here

knb
  • 5,004
  • This did the trick! – daviewales Jun 28 '20 at 01:48
  • 2
    Sound latency offset cannot be a solution for playing video, unfortunately. – KiriSakow Feb 15 '21 at 17:19
  • This works for me (ubuntu 22.04) – Andrei B Jun 17 '22 at 12:06
  • Audio-to-video synchronization article on Wikipedia states:

    For television applications, the Advanced Television Systems Committee recommends that audio should lead video by no more than 15 milliseconds and audio should lag video by no more than 45 milliseconds. However, the ITU performed strictly controlled tests with expert viewers and found that the threshold for detectability is -125ms to +45ms. For film, acceptable lip sync is considered to be no more than 22 milliseconds in either direction.

    – Jan Molnár Jul 20 '22 at 11:53
9

Chris_128 answer worked for me but for newbies I'll add a bit detail.

For the NAME and PORT for the command below:

pactl set-port-latency-offset NAME PORT 50000 

You will get it after you have result from typing:

pactl list | grep -Pzo '.*bluez_card(.*\n)*'


Name: bluez_card.5C_FB_7C_0D_0F_EE
Driver: module-bluez5-device.c
Owner Module: 28
Properties:
    ...
Profiles:
    headset_head_unit: Headset Head Unit (HSP/HFP) (sinks: 1, sources: 1, priority: 30, available: yes)
    a2dp_sink: High Fidelity Playback (A2DP Sink) (sinks: 1, sources: 0, priority: 40, available: yes)
    off: Off (sinks: 0, sources: 0, priority: 0, available: yes)
Active Profile: a2dp_sink
Ports:
    headset-output: Headset (priority: 0, latency offset: 0 usec, available)
        Part of profile(s): headset_head_unit, a2dp_sink
    headset-input: Headset (priority: 0, latency offset: 0 usec)
        Part of profile(s): headset_head_unit

The NAME will be "bluez_card.5C_FB_7C_0D_0F_EE" and the PORT will be "headset-output"

So for my case my command is

"pactl set-port-latency-offset bluez_card.5C_FB_7C_0D_0F_EE headset-output 50000"

Restart your bluetooth service

sudo service bluetooth restart
okto
  • 91
6

Had the same issue with Ubuntu 18.04 running as dual boot in MacBook Mini. Tried changing the ALSA configuration as mentioned by @ConfirmAndCreateThisAccount.

But it didn't work.

So i installed Blueman using the below command

sudo apt-get install blueman

Then i disconnected the bluetooth device from the system bluetooth settings & re-paired using Blueman. Now everything is fine. Even the Play/Pause controls work.

iamnagaky
  • 161
  • 1
  • 1
  • For me what this did is that it switched from A2DP to headset profile. It does use less bandwidth and work better when WiFi is active, but sound quality is worse. – jpa Oct 13 '23 at 07:06
4

The fix worked for me, although I did find that I had to REM the line before it. See below:

# Keep snd-usb-audio from beeing loaded as first soundcard  
# options snd-usb-audio index=-2  <-REM this line if it doesn't work at first  
options snd-hda-intel model=generic
  • My problem is sound stuttering in videos — where sound latency offset cannot be a solution, unfortunately. – KiriSakow Feb 15 '21 at 17:22
2

I solved my problem by changing the wifi connection I am using from using the 2.4 ghz connection (same as bluetooth) to a 5 ghz connection. My router and laptop are able to use both.

select
  • 641
  • 7
  • 5