AudioData
Limited availability
This feature is not Baseline because it does not work in some of the most widely-used browsers.
Note: This feature is available inDedicated Web Workers.
TheAudioData interface of theWebCodecs API represents an audio sample.
AudioData is atransferable object.
In this article
Description
An audio track consists of a stream of audio samples, each sample representing a captured moment of sound. AnAudioData object is a representation of such a sample. Working alongside the interfaces of theInsertable Streams API, you can break a stream into individualAudioData objects withMediaStreamTrackProcessor, or construct an audio track from a stream of frames withMediaStreamTrackGenerator.
Note:Find out more about audio on the web inDigital audio concepts.
The media resource
AnAudioData object contains a reference to an attachedmedia 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 anAudioData object, for example whenAudioData.close() is called.
Planes and audio format
To return the sample format of anAudioData use theAudioData.format property. The format may be described asinterleaved orplanar. In interleaved formats, the audio samples from the different channels are laid out in a single buffer, described as aplane. This plane contains a number of elements equal toAudioData.numberOfFrames *AudioData.numberOfChannels.
In planar format, the number of planes is equal toAudioData.numberOfChannels, and each plane is a buffer containing a number of elements equal toAudioData.numberOfFrames.
Constructor
AudioData()Creates a new
AudioDataobject.
Instance properties
AudioData.formatRead onlyReturns the sample format of the audio.
AudioData.sampleRateRead onlyReturns the sample rate of the audio in Hz.
AudioData.numberOfFramesRead onlyReturns the number of frames.
AudioData.numberOfChannelsRead onlyReturns the number of audio channels.
AudioData.durationRead onlyReturns the duration of the audio in microseconds.
AudioData.timestampRead onlyReturns the timestamp of the audio in microseconds.
Instance methods
AudioData.allocationSize()Returns the number of bytes required to hold the sample as filtered by options passed into the method.
AudioData.copyTo()Copies the samples from the specified plane of the
AudioDataobject to the destination.AudioData.clone()Creates a new
AudioDataobject with reference to the same media resource as the original.AudioData.close()Clears all states and releases the reference to the media resource.
Specifications
| Specification |
|---|
| WebCodecs> # audiodata-interface> |