AudioContext()
构造函数创建新
AudioContext
object which represents an audio-processing graph, built from audio modules linked together, each represented by an
AudioNode
.
var audioCtx = new AudioContext(); var audioCtx = new AudioContext(options);
选项
可选
AudioContextOptions
dictionary that contains zero or more optional properties to configure the new context. Available properties are as follows:
latencyHint
可选
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.
The newly constructed
AudioContext
实例。
NotSupportedError
sampleRate
isn't supported by the context.
The specification doesn't go into a lot of detail about things like how many audio contexts a user agent should support, or minimum or maximum latency requirements (if any), so these details can vary from browser to browser. Be sure to check the values if they matter to you.
In particular, the specification doesn't indicate a maximum or minimum number of audio contexts that must be able to be open at the same time, so this is left up to the browser implementations to decide.
Prior to version 66 Google Chrome only supported up to six audio contexts per tab at a time.
If the value of the
latencyHint
property isn't valid, Chrome throws a
TypeError
exception with the message "The provided value '...' is not a valid enum value of type AudioContextLatencyCategory".
This example creates a new
AudioContext
for interactive audio (optimizing for latency) and a sample rate of 44.1kHz.
var AudioContext = window.AudioContext || window.webkitAudioContext;
var audioCtx = new AudioContext({
latencyHint: 'interactive',
sampleRate: 44100,
});
| 规范 | 状态 | 注释 |
|---|---|---|
|
Web 音频 API
The definition of 'AudioContext()' in that specification. |
工作草案 | 初始定义。 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
AudioContext()
构造函数
|
Chrome
55
注意事项
|
Edge ≤18 | Firefox 25 | IE 不支持 No | Opera 42 |
Safari
Yes
Prefixed
|
WebView Android 55 |
Chrome Android
55
注意事项
|
Firefox Android 26 | Opera Android 42 |
Safari iOS
Yes
Prefixed
|
Samsung Internet Android
6.0
注意事项
|
latencyHint
option
|
Chrome 60 | Edge 79 | Firefox 不支持 No | IE 不支持 No | Opera 47 | Safari ? | WebView Android 60 | Chrome Android 60 | Firefox Android 不支持 No | Opera Android 44 | Safari iOS ? | Samsung Internet Android 8.0 |
sampleRate
option
|
Chrome 74 | Edge 79 | Firefox 不支持 No | IE 不支持 No | Opera 不支持 No | Safari Yes | WebView Android 74 | Chrome Android 74 | Firefox Android ? | Opera Android ? | Safari iOS Yes | Samsung Internet Android 11.0 |
完整支持
不支持
兼容性未知
实验。期望将来行为有所改变。
见实现注意事项。
要求使用供应商前缀或不同名称。
AudioContext
AudioContext()
AnalyserNode
AudioBuffer
AudioBufferSourceNode
AudioContextOptions
AudioDestinationNode
AudioListener
AudioNode
AudioNodeOptions
AudioParam
AudioProcessingEvent
AudioScheduledSourceNode
AudioWorklet
AudioWorkletGlobalScope
AudioWorkletNode
AudioWorkletProcessor
BaseAudioContext
BiquadFilterNode
ChannelMergerNode
ChannelSplitterNode
ConstantSourceNode
ConvolverNode
DelayNode
DynamicsCompressorNode
GainNode
IIRFilterNode
MediaElementAudioSourceNode
MediaStreamAudioDestinationNode
MediaStreamAudioSourceNode
OfflineAudioCompletionEvent
OfflineAudioContext
OscillatorNode
PannerNode
PeriodicWave
StereoPannerNode
WaveShaperNode