@audio/decode-webm

中文文档
1.6.1发布于 2026/08/29MITTypeScriptES Module近 30 天下载 64.8万

Decode WebM / Matroska audio (Opus, Vorbis, AAC, MP3, FLAC, ALAC, PCM) to PCM samples

原始使用文档
文档目录7 节
  1. Install
  2. Usage
  3. API
  4. decode(src): Promise<AudioData>
  5. decoder(): Promise<WebmDecoder>
  6. Codecs
  7. License

@audio/decode-webm

Decode WebM and Matroska (MKV) audio to PCM float samples — the audio track of video files included (Opus, Vorbis, AAC, ALAC, MP3, FLAC, AC-3, DTS, PCM).

Install

npm i @audio/decode-webm

Usage

import decode, { decoder } from '@audio/decode-webm'

let { channelData, sampleRate } = await decode(webmBytes)

let dec = await decoder() // initialize Opus and Vorbis WASM
let result = dec.decode(chunk)
let tail = dec.flush()
dec.free()

Video tracks are skipped; the first audio track is decoded. Laced blocks (Xiph, EBML, fixed) are split into frames.

API

decode(src): Promise<AudioData>

Decode a complete Uint8Array or ArrayBuffer.

decoder(): Promise<WebmDecoder>

Initialize the codec runtimes and return a streaming decoder. For the WebM codecs (Opus, Vorbis) decode() and flush() are synchronous. For Matroska-only codecs the call that completes the track header returns a Promise while the codec package loads; later calls are synchronous. flush() ends the stream.

The factory prepares the Opus and Vorbis runtimes, then releases what the track does not need once the header is read.

Codecs

CodecIDDecoded by
A_OPUSbundled libopus WASM core from @audio/decode-opus
A_VORBISbundled @audio/decode-vorbis
A_AAC (all profiles)@audio/decode-aac, loaded on demand
A_ALAC@audio/decode-aac, loaded on demand
A_MPEG/L3@audio/decode-mp3, loaded on demand
A_FLAC@audio/decode-flac, loaded on demand
A_PCM/INT/LIT, A_PCM/INT/BIG, A_PCM/FLOAT/IEEEbuilt in
A_AC3@audio/decode-ac3, loaded on demand
A_DTS (core of DTS-HD too)@audio/decode-dts, loaded on demand
A_EAC3@audio/decode-eac3, loaded on demand

TrueHD, MPEG Layer I/II, WavPack, TTA and A_MS/ACM tracks throw an error naming the codec. DiscardPadding on Opus blocks is honoured, so files from @audio/encode-webm decode sample-exact.

On-demand codec packages are imported dynamically, which is unavailable inside an AudioWorklet — Opus and Vorbis work there, the others need the main thread or a Worker.

License

ॐ · MIT. Bundled libopus is BSD 3-Clause.

版本与发布记录

@audio/decode-webm 共发布 14 个版本,首次发布于 2026/04/04;过去 12 个月发布了 14 个版本。

版本发布日期距今
1.6.1latest2026/08/292 个月前
1.6.02026/08/282 个月前
1.5.02026/08/282 个月前
1.4.12026/08/132 个月前
1.4.02026/08/122 个月前
1.3.32026/07/143 个月前

关于 @audio/decode-webm 的常见问题

@audio/decode-webm 是什么?

Decode WebM / Matroska audio (Opus, Vorbis, AAC, MP3, FLAC, ALAC, PCM) to PCM samples

如何安装 @audio/decode-webm?

在项目目录运行 npm install @audio/decode-webm,或使用 pnpm add / yarn add / bun add。

@audio/decode-webm 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@audio/decode-webm 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@audio/decode-webm 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=18。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@audio/decode-webm 可以商用吗?

@audio/decode-webm 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@audio/decode-webm 的下载量有多少?

根据 npm 官方下载统计,@audio/decode-webm 在 2026/10/07 – 2026/11/05 这 30 天内被下载 648,406 次,日均约 21,614 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@audio/decode-webm 还在维护吗?

最新版本 1.6.1 发布于 2026/08/29(2 个月前);至今共发布 14 个版本,其中过去 12 个月发布了 14 个;首次发布于 2026/04/04。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。