question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Audio from bluetooth device is delayed by around 3 seconds

See original GitHub issue

System: image

Bug: Audio from bluetooth device is delayed by around 3 seconds. See https://github.com/rbn42/panon/issues/26.

Reproducible script:

import soundcard as sc
import numpy as np
sample_rate=44100
channel_count=2
fps=60

blocksize = sample_rate // fps
mics = sc.all_microphones(exclude_monitors=False)

streams = []

for mic in mics:
    stream = mic.recorder(
        sample_rate,
        channel_count,
        blocksize,
    )
    stream.__enter__()
    streams.append(stream)

for i,mic in enumerate(mics):
    print('Stream %d id:%s'%(i,mic.id))
    print('Stream %d name:%s'%(i,mic.name))

while True:
    msg=''
    for i,stream in enumerate(streams):
        data = stream.record(blocksize)
        if np.sum(data)==0:
            msg+='Stream %d:paused '%i
        else:
            msg+='Stream %d:playing '%i
    print(msg,end='\r')

Requires NumPy. Thanks to @rbn42 for creating the script.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:20 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
matanui159commented, May 8, 2020

Sorry for the delay, mix of busyness and sleep. image The times stay about the same constantly but the headset is still delayed by 3s. Playing the audio through other channels does not delay the audio and (when using Panon) selecting only the headset also does not delay the audio.

1reaction
bastibecommented, May 8, 2020

Can I use concurrent.futures.ThreadPoolExecutor instead of a very short blocksize?

Probably, yes. I think CFFI releases the GIL while calling C functions, so that should be ok. (Don’t use async though. Async certainly does not work.)

But I think the blocksize is not a problem here.

So far, I had assumed that the latency was incurred in the record step. But you are right, this doesn’t make sense. If one record were to take three seconds, it would delay all other records as well. So SoundCard is probably pulling the data off the sound card as fast as it is produced (with the occasional missed block as we discussed), but the Bluetooth device on pulse somehow has a built-in delay of three seconds before it is even passed to SoundCard.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Fix Sound Delay in Bluetooth Headphones
Reset your Bluetooth headphones and speakers then try reconnecting them again to your computer after a few seconds. With luck, it would reset...
Read more >
bluetooth headphone sound starts after 2 to 3 seconds delay
bluetooth headphone sound starts after 2 to 3 seconds delay. This problem happens whenever something tries to play a "new" sound for exemple ......
Read more >
How To Fix Bluetooth Audio Delay? - TechNewsToday
Hard reset your Bluetooth Device. Most Bluetooth earphone devices reset after pressing the power button for 5-10 seconds of the case. Some ...
Read more >
Fix Bluetooth sound delay in Windows 11/10
One of these solutions is sure to help fix the Bluetooth sound delay and audio lag & latency problem in Windows 11/10 effortlessly....
Read more >
9 Ways to Fix a Bluetooth Audio Delay in Windows 11
1. Reconnect Your Bluetooth Hardware · 2. Rule Out Interference From Other Devices · 3. Rule Out Hardware Issues · 4. Ensure Your...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found