11
votes

I am currently working on an Android audio visualizer using connected smart home devices (such as Philips hue) to visualize music. I have trouble compensating the delay caused by bluetooth speakers.

I have noticed, that the Youtube app, in difference to many other video streaming apps, has almost no delay between audio and video, when using bluetooth speakers. I figure, that they must compensate for the bluetooth latency by adjusting (delaying) the video signal.

Is there a reasonable way of detecting or approximating the latency/delay of bluetooth speakers?

Thank you very much for you help!!

Best, Stefan

2
It seems like YouTube may be using google.github.io/ExoPlayer for playback, which has some code to detect audio latency: github.com/google/ExoPlayer/blob/master/library/src/main/java/…Tavian Barnes
Damn, seems that's not quite enough! Their AudioTrack implementation reports positions about two seconds behind reality in my car.Tavian Barnes
Well actually, YouTube is off by a couple seconds too in my car, so maybe that's as good as possible.Tavian Barnes
Updated ExoPlayer link: github.com/google/ExoPlayer/blob/… - They ask android.media.AudioTrack for the getLatency method.Henk Poley
Apart from source code strewn around the web, some documentation on AudioTrack getLatency here: developer.amazon.com/docs/fire-tv/…Henk Poley

2 Answers

3
votes

This would not work for Bluetooth speakers. However, I have been able to measure the audio latency of a Bluetooth dongle using Google's Dr. Rick O'Rang loopback dongle, using Glenn Kasten test app.

0
votes

AVDTP 1.3 protocol supports delay reporting. Try looking to see if Android exports this data.

It's in the somewhere: AVDT_PSC_DELAY_RPT is present in https://android.googlesource.com/platform/system/bt/+/master/stack/include/avdt_api.h#153.