The AudioContextOptions dictionary (used when instantiating an AudioContext) may contain a property named latencyHint, which indicates the preferred maximum latency in seconds for the audio context. The value is specified either as a predefined String or a double-precision value.


audioContextOptions.latencyHint = "interactive";
audioContextOptions.latencyHint = 0.2;

var latencyHint = audioContextOptions.latencyHint;


The preferred maximum latency for the AudioContext. There are two ways this value can be specified.

The best way to specify the preferred latency is to use a predefined String. The allowed strings are:

The browser balances audio output latency and power consumption when selecting a latency value.
The audio is involved in interactive elements, such as responding to user actions or needing to coincide with visual cues such as a video or game action. The browser selects the lowest possible latency that doesn't cause glitches in the audio. This is likely to require increased power consumption. This is the default value.
The browser selects a latency that will maximize playback time by minimizing power consumption at the expense of latency. Useful for non-interactive playback, such as playing music.

The value can also be specified as a double-precision floating-point value, specifying the preferred maximum latency in seconds. This provides more precise control over the balance between audio latency and device energy usage.

To determine the actual latency of the context after creating it, check the value of the context's baseLatency property.


Web Audio API
# dom-audiocontextoptions-latencyhint

Browser compatibility

BCD tables only load in the browser

See also