javascript – AudioElement/WebAudio/WebSpeech and output latency

I tried three methods of playing back/generating audio on a Mac and on Android devices. The three methods are

  1. loading a file into an AudioElement (via <audio>),
  2. creating a sound with the WebAudio API,
  3. using the WebSpeech API to generate speech.

Methods 1 and 2 have a considerable latency (i.e. time between call to play and perceivable audio) before they can be heard on my Android devices (though one of the devices appears to have less latency than the other). No latency can be perceived on my Mac.
Method 3 doesn’t seem to have any latency at all.

The latency of Method 2, WebAudio API, can be mitigated by subtracting a calculated output latency from the desired starting time. The formula is:
outputLatency = audioContext.currentTime - audioContext.getOutputTimestamp().contextTime.
It does more or less remove the latency from one of my Android devices, but not from the other.

The improvement I saw after using above formula is the main reason I suspected the problem to be output latency.

According to my research, output latency has at least in part to do with the hardware so WebSpeech being completely unaffected doesn’t make a lot of sense in my opinion.

Is what I am observing here output latency?
If yes, why is WebSpeech not affected by this?
If no, where does the latency come from?

Read more here: Source link