W3cubDocs

/Web APIs

AudioData

Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

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 AudioData.close() is called.

Planes and audio format

To return the sample format of an AudioData use the AudioData.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 AudioData.numberOfFrames * AudioData.numberOfChannels.

In planar format, the number of planes is equal to AudioData.numberOfChannels, and each plane is a buffer containing a number of elements equal to AudioData.numberOfFrames.

Constructor

AudioData() Experimental

Creates a new AudioData object.

Instance properties

AudioData.format Read only Experimental

Returns the sample format of the audio.

AudioData.sampleRate Read only Experimental

Returns the sample rate of the audio in Hz.

AudioData.numberOfFrames Read only Experimental

Returns the number of frames.

AudioData.numberOfChannels Read only Experimental

Returns the number of audio channels.

AudioData.duration Read only Experimental

Returns the duration of the audio in microseconds.

AudioData.timestamp Read only Experimental

Returns the timestamp of the audio in microseconds.

Instance methods

AudioData.allocationSize() Experimental

Returns the number of bytes required to hold the sample as filtered by options passed into the method.

AudioData.copyTo() Experimental

Copies the samples from the specified plane of the AudioData object to the destination.

AudioData.clone() Experimental

Creates a new AudioData object with reference to the same media resource as the original.

AudioData.close() Experimental

Clears all states and releases the reference to the media resource.

Specifications

Browser compatibility

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari WebView Android Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet
AudioData 94 94 No No 80 No 94 94 No 66 No 17.0
AudioData 94 94 No No 80 No 94 94 No 66 No 17.0
allocationSize 94 94 No No 80 No 94 94 No 66 No 17.0
clone 94 94 No No 80 No 94 94 No 66 No 17.0
close 94 94 No No 80 No 94 94 No 66 No 17.0
copyTo 94 94 No No 80 No 94 94 No 66 No 17.0
duration 94 94 No No 80 No 94 94 No 66 No 17.0
format 94 94 No No 80 No 94 94 No 66 No 17.0
numberOfChannels 94 94 No No 80 No 94 94 No 66 No 17.0
numberOfFrames 94 94 No No 80 No 94 94 No 66 No 17.0
sampleRate 94 94 No No 80 No 94 94 No 66 No 17.0
timestamp 94 94 No No 80 No 94 94 No 66 No 17.0

© 2005–2023 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/AudioData