OfflineAudioContext()
constructor—part of the
Web 音频 API
—creates and returns a new
OfflineAudioContext
object instance, which can then be used to render audio to an
AudioBuffer
rather than to an audio output device.
var offlineAudioCtx = new OfflineAudioContext(numberOfChannels, length, sampleRate); var offlineAudioCtx = new OfflineAudioContext(options);
You can specify the parameters for the
OfflineAudioContext()
constructor as either the same set of parameters as are inputs into the
AudioContext.createBuffer()
method, or by passing those parameters in an
选项
object. Either way, the individual parameters are the same.
numberOfChannels
AudioBuffer
should have.
length
sampleRate
of 48000Hz would have a length of
5 * 48000 = 240000
sample-frames.
sampleRate
The sample-rate of the linear audio data in sample-frames per second. All user agents are required to support a range of 22050Hz to 96000Hz, and may support a wider range than that. The most commonly-used rate is 44100Hz, which is the sample rate used by CD audio.
It is important to note that, whereas you can create a new
AudioContext
使用
new AudioContext()
constructor with no arguments, the
OfflineAudioContext()
constructor requires three arguments, since it needs to create an
AudioBuffer
. This works in exactly the same way as when you create a new
AudioBuffer
采用
AudioContext.createBuffer()
method. For more detail, read
Audio buffers: frames, samples and channels
from our
基本概念
guide.
新的
OfflineAudioContext
object whose associated
AudioBuffer
is configured as requested.
Like a regular
AudioContext
,
OfflineAudioContext
can be the target of events, therefore it implements the
EventTarget
接口。
const offlineCtx = new OfflineAudioContext({
numberOfChannels: 2,
length: 44100 * 40,
sampleRate: 44100,
});
const source = offlineCtx.createBufferSource();
// etc...
For a full working example, see our offline-audio-context-promise Github repo (see the 源代码 too.)
| 规范 | 状态 | 注释 |
|---|---|---|
|
Web 音频 API
The definition of 'OfflineAudioContext()' in that specification. |
工作草案 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
OfflineAudioContext()
构造函数
|
Chrome
55
|
Edge ≤79 | Firefox 53 | IE No | Opera 42 | Safari ? |
WebView Android
55
|
Chrome Android
55
|
Firefox Android 53 | Opera Android 42 | Safari iOS ? |
Samsung Internet Android
6.0
|
| Parameters accepted as a single object, as well as being passed in individually | Chrome 62 | Edge ≤79 | Firefox 57 | IE No | Opera 49 | Safari No | WebView Android 62 | Chrome Android 62 | Firefox Android 57 | Opera Android 46 | Safari iOS No | Samsung Internet Android 8.0 |
完整支持
不支持
兼容性未知
见实现注意事项。
OfflineAudioContext
OfflineAudioContext()
AnalyserNode
AudioBuffer
AudioBufferSourceNode
AudioContext
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
OscillatorNode
PannerNode
PeriodicWave
StereoPannerNode
WaveShaperNode