AudioContextOptions

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() 构造函数。

特性

latencyHint 可选
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 of AudioContext.baseLatency to determine the true latency after creating the context.
sampleRate 可选
sampleRate to be used by the AudioContext , specified in samples per second. The value may be any value supported by AudioBuffer . If not specified, the preferred sample rate for the context's output device is used by default.

常量

Standard values for latencyHint

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:

描述
"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.

范例

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
});
					

规范

规范 状态 Comment
Web 音频 API
The definition of 'AudioContextOptions' in that specification.
工作草案 初始定义。

浏览器兼容性

更新 GitHub 上的兼容性数据
Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
AudioContextOptions Chrome 60 Edge ≤79 Firefox 61 IE No Opera ? Safari ? WebView Android 60 Chrome Android 60 Firefox Android 61 Opera Android ? Safari iOS ? Samsung Internet Android 8.0
latencyHint Chrome 60 Edge ≤79 Firefox 61 IE No Opera ? Safari ? WebView Android 60 Chrome Android 60 Firefox Android 61 Opera Android ? Safari iOS ? Samsung Internet Android 8.0
sampleRate Chrome 74 Edge 79 Firefox 61 IE No Opera No Safari ? WebView Android 74 Chrome Android 74 Firefox Android 61 Opera Android ? Safari iOS ? Samsung Internet Android 11.0

图例

完整支持
完整支持
不支持
不支持
兼容性未知
兼容性未知