The AudioContextOptions
dictionary is used to specify configuration options when constructing a new AudioContext
object to represent a graph of web audio nodes. It is only used when calling the AudioContext()
constructor.
Properties
latencyHint
Optional- The type of playback that the context will be used for, as a value from the
AudioContextLatencyCategory
enum or a double-precision floating-point value indicating the preferred maximum latency of the context in seconds. The user agent may or may not choose to meet this request; check the value ofAudioContext.baseLatency
to determine the true latency after creating the context. sampleRate
Optional- The
sampleRate
to be used by theAudioContext
, specified in samples per second. The value may be any value supported byAudioBuffer
. If not specified, the preferred sample rate for the context's output device is used by default.
Constants
Standard values for latencyHint
The latencyHint
property can be number specifying a preferred maximum latency in seconds or a string from the AudioContextLatencyCategory
enumerated string, which selects a standard value for a given type of audio usage:
Value | Description |
---|---|
"balanced" |
The user agent should balance audio output latency and power consumption when selecting a latency value. |
"interactive" |
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 user agent should select 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. |
"playback" |
The user agent should select 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. |
Example
This example instantiates an audio context for music playback (optimized for power consumption over latency), with the sample rate 48,000 Hz.
let musicContext = new AudioContext({ latencyHint: "playback", sampleRate: 48000 });
Specifications
Specification | Status | Comment |
---|---|---|
Web Audio API The definition of 'AudioContextOptions' in that specification. |
Working Draft | Initial definition. |
Browser compatibility
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
AudioContextOptions | Chrome Full support 60 | Edge Full support ≤79 | Firefox Full support 61 | IE No support No | Opera ? | Safari ? | WebView Android Full support 60 | Chrome Android Full support 60 | Firefox Android Full support 61 | Opera Android ? | Safari iOS ? | Samsung Internet Android Full support 8.0 |
latencyHint | Chrome Full support 60 | Edge Full support ≤79 | Firefox Full support 61 | IE No support No | Opera ? | Safari ? | WebView Android Full support 60 | Chrome Android Full support 60 | Firefox Android Full support 61 | Opera Android ? | Safari iOS ? | Samsung Internet Android Full support 8.0 |
sampleRate | Chrome Full support 74 | Edge Full support 79 | Firefox Full support 61 | IE No support No | Opera No support No | Safari ? | WebView Android Full support 74 | Chrome Android Full support 74 | Firefox Android Full support 61 | Opera Android ? | Safari iOS ? | Samsung Internet Android Full support 11.0 |
Legend
- Full support
- Full support
- No support
- No support
- Compatibility unknown
- Compatibility unknown