大网数据广告活动
Web 标准与前端开发

AudioData

· 52CE 我爱测

The **`AudioData`** interface of the WebCodecs API represents an audio sample.

WebCodecs APIwindow_and_dedicated

The AudioData interface of the WebCodecs API represents an audio sample.

AudioData is a transferable object.

Constructor

  • AudioData.AudioData
    • : Creates a new AudioData object.

Instance properties

  • AudioData.format
    • : Returns the sample format of the audio.
  • AudioData.sampleRate
    • : Returns the sample rate of the audio in Hz.
  • AudioData.numberOfFrames
    • : Returns the number of frames.
  • AudioData.numberOfChannels
    • : Returns the number of audio channels.
  • AudioData.duration
    • : Returns the duration of the audio in microseconds.
  • AudioData.timestamp
    • : Returns 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 AudioData object to the destination.
  • AudioData.clone()
    • : Creates a new AudioData object with reference to the same media resource as the original.
  • AudioData.close()
    • : Clears all states and releases the reference to the media resource.

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.

Specifications

Browser compatibility

来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。