web api interface
AudioData
Available in workers
The AudioData interface of the WebCodecs API represents an audio sample.
AudioData is a transferable object.
Description
An audio track consists of a stream of audio samples, each sample representing a captured moment of sound. An AudioData object is a representation of such a sample. Working alongside the interfaces of the Insertable Streams API, you can break a stream into individual AudioData objects with MediaStreamTrackProcessor, or construct an audio track from a stream of frames with MediaStreamTrackGenerator.
[!NOTE] Find out more about audio on the web in Digital audio concepts.
The media resource
An AudioData object contains a reference to an attached media resource. This media resource contains the actual audio sample data described by the object. A media resource is maintained by the user agent until it is no longer referenced by an AudioData object, for example when close() is called.
Planes and audio format
To return the sample format of an AudioData use the format property. The format may be described as interleaved or planar. In interleaved formats, the audio samples from the different channels are laid out in a single buffer, described as a plane. This plane contains a number of elements equal to numberOfFrames * numberOfChannels.
In planar format, the number of planes is equal to numberOfChannels, and each plane is a buffer containing a number of elements equal to numberOfFrames.
Constructor
AudioData()- : Creates a new
AudioDataobject.
- : Creates a new
Instance properties
formatRead only- : Returns the sample format of the audio.
sampleRateRead only- : Returns the sample rate of the audio in Hz.
numberOfFramesRead only- : Returns the number of frames.
numberOfChannelsRead only- : Returns the number of audio channels.
durationRead only- : Returns the duration of the audio in microseconds.
timestampRead only- : Returns the timestamp of the audio in microseconds.
Instance methods
allocationSize()- : Returns the number of bytes required to hold the sample as filtered by options passed into the method.
copyTo()- : Copies the samples from the specified plane of the
AudioDataobject to the destination.
- : Copies the samples from the specified plane of the
clone()- : Creates a new
AudioDataobject with reference to the same media resource as the original.
- : Creates a new
close()- : Clears all states and releases the reference to the media resource.