OfflineAudioContext() constructor—part of the Web Audio 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.
new OfflineAudioContext(numberOfChannels, length, sampleRate)
You can specify the parameters for the
as either the same set of parameters as are inputs into the
BaseAudioContext.createBuffer method, or by passing those parameters in an
options object. Either way, the individual parameters are the same.
An integer specifying the number of channels the resulting
An integer specifying the size of the buffer to create for the audio context, in sample-frames, where one sample-frame is a unit that can contain a single sample of audio data for every channel in the audio data. For example, a 5-second buffer with a
sampleRateof 48000Hz would have a length of
5 * 48000 = 240000sample-frames.
The sample-rate of the linear audio data in sample-frames per second. All user agents are required to support a range of 8000Hz 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
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 with the
BaseAudioContext.createBuffer method. For more detail, read Audio buffers: frames, samples and channels from our Basic concepts guide.
|Web Audio API
BCD tables only load in the browser