audiojs/decode

Minimal audio decoders layer

JavaScript

209

261 commits

updated Oct 8, 2026

See the code

README

@audio/decode test

Try it in the browser: Extract audio from video, Audio converter.

Decode any audio format to raw samples.
JS / WASM with no ffmpeg or native bindings; works in Node.js and browsers.
Small API, minimal size, near-native performance, lazy-loading, chunked decoding.

npm install @audio/decode

import decode from '@audio/decode';

const { channelData, sampleRate } = await decode(anyAudioBuffer);

Supported formats

FormatPackageSizeEngine
MP3@audio/decode-mp392 KBWASM
WAV@audio/decode-wav11 KBJS
OGG Vorbis@audio/decode-vorbis166 KBWASM
FLAC@audio/decode-flac135 KBWASM
Opus@audio/decode-opus166 KBWASM
M4A / AAC / ALAC@audio/decode-aac368 KBWASM + JS
MP4 / MOV / M4V / 3GP video@audio/decode-mp412 KB + codecJS demux
QOA@audio/decode-qoa8 KBJS
AIFF@audio/decode-aiff20 KBJS
CAF@audio/decode-caf9 KBJS
WebM / MKV video@audio/decode-webm250 KBWASM
AVI video@audio/decode-avi8 KB + codecJS demux
AC-3@audio/decode-ac343 KBWASM
DTS@audio/decode-dts200 KBWASM
E-AC-3 (Dolby Digital Plus, + AC-3)@audio/decode-eac3432 KBWASM (FFmpeg libavcodec, LGPL)
APE (Monkey's Audio)@audio/decode-ape262 KBWASM (FFmpeg libavcodec, LGPL)
AMR@audio/decode-amr241 KBWASM
GSM 06.10 (raw frames, by name)@audio/decode-gsm23 KBWASM (libgsm)
WMA (v1, v2, Pro, Lossless)@audio/decode-wma463 KBWASM (FFmpeg libavcodec, LGPL)
WavPack@audio/decode-wavpack51 KBWASM
TTA (True Audio)@audio/decode-tta11 KBJS
Musepack SV7 / SV8@audio/decode-mpc51 KBWASM
MOD / XM / S3M / IT tracker modules@audio/decode-mod1.4 MBWASM (libopenmpt)
DSF / DFF (DSD64–512 → PCM)@audio/decode-dsd18 KBJS

Whole-file

Auto-detects format. Input can be ArrayBuffer, Uint8Array, Buffer, or anything that materializes to bytes, including a Blob/File or fetch Response.

import decode from '@audio/decode'

let { channelData, sampleRate } = await decode(buf)
let fromFile = await decode(fileInput.files[0])   // File
let fromUrl  = await decode(await fetch(url))      // Response

Chunked

let dec = await decode.mp3()
let a = await dec(chunk1)    // { channelData, sampleRate }
let b = await dec(chunk2)
await dec()                  // close

Streaming

import decode from '@audio/decode'

for await (let { channelData, sampleRate } of decode.mp3(response.body)) {
  // process chunks
}

Works with ReadableStream, fetch body, Node stream, or any async iterable.

Formats: mp3, flac, opus, oga, m4a, mp4, mov, wav, qoa, aac, aiff, caf, webm, mkv, avi, ac3, dts, amr, gsm, wma, eac3, ape, wv, tta, mpc, dsf, dff, mod, xm, s3m, it.

Video files

Video containers decode straight to their audio track — the video stream is skipped, no ffmpeg involved:

let { channelData, sampleRate } = await decode(await fetch('trailer.mp4'))
ContainerPackageAudio codecs
MP4, MOV, M4V, 3GP@audio/decode-mp4AAC, ALAC, MP3, FLAC, Opus, AC-3, DTS, AMR, PCM, G.711
WebM, MKV@audio/decode-webmOpus, Vorbis, AAC, ALAC, MP3, FLAC, AC-3, DTS, PCM
AVI@audio/decode-aviPCM, MP3, AAC, AC-3, DTS, G.711

Surround tracks keep their layout (up to 5.1, WAV channel order). E-AC-3 and TrueHD tracks throw an error naming the codec.

Browser

Works from a CDN without a bundler. Codecs load on demand via dynamic import, only for formats you decode:

<script type="module">
  import decode from 'https://esm.sh/@audio/decode'
  let { channelData, sampleRate } = await decode(buf)
</script>

For self-hosting, use an import map to point @audio/decode and each needed @audio/decode-* package to local files. Codec-internal files load by relative path.

Each codec package's main export works in an AudioWorklet without Blob, TextDecoder, Worker, or fetch. Import codec packages directly because @audio/decode uses dynamic imports.

Initialize WASM before rendering. Decoding runs on the worklet thread and can interrupt audio output.

Synchronous codecs

The umbrella remains async for detection, lazy imports, and Blob/Response inputs. Import a codec package directly for synchronous calls.

wav, qoa, aiff, and caf are synchronous:

import decode from '@audio/decode-wav'
let pcm = decode(wavBytes)

WASM codecs initialize asynchronously, then decode synchronously:

import { decoder } from '@audio/decode-flac'
let dec = await decoder()
let pcm = dec.decode(bytes)
let tail = dec.flush()
dec.free()

Metadata

Read tags, pictures, markers and regions without decoding samples. Available for wav, mp3, flac, oga (Ogg Vorbis), opus, and m4a.

import { wav, mp3, flac, oga, opus, m4a } from '@audio/decode/meta'

let { meta, sampleRate, markers, regions } = mp3(bytes)
// meta: { title, artist, album, year, bpm, key, comment, pictures, raw, ... }
// markers: [{ sample, label }]
// regions: [{ sample, length, label }]

Each codec sub-package also exposes its parser directly:

import { parseMeta } from '@audio/decode-wav/meta'
let info = parseMeta(wavBytes)

WebWorker

Each @audio/decode-* package is a self-contained ESM module that can run in a worker:

// decode-worker.js
import decode from '@audio/decode-mp3'

self.onmessage = async ({ data }) => {
  let pcm = await decode(data)
  self.postMessage(pcm, pcm.channelData.map(ch => ch.buffer))
}

// main.js
let worker = new Worker('./decode-worker.js', { type: 'module' })
worker.postMessage(mp3buf, [mp3buf])
worker.onmessage = ({ data }) => { /* { channelData, sampleRate } */ }

See also

  • audio – edit, measure and save: trim, loudness to spec, delivery checks, a CLI.
  • encode – encode PCM into any audio format.
  • audio-type – detect audio format from buffer.

Licensing

The umbrella and most codec packages are MIT. Codecs built on other libraries carry that library's license: @audio/decode-aac GPL-2.0; @audio/decode-ac3 and @audio/decode-dts GPL-2.0-or-later; @audio/decode-ape, @audio/decode-eac3 and @audio/decode-wma LGPL-2.1-or-later (a slim FFmpeg libavcodec build, no GPL components); @audio/decode-wavpack, @audio/decode-mpc and @audio/decode-mod BSD-3-Clause; @audio/decode-amr Apache-2.0. Install only the codecs whose licenses fit your project. The umbrella loads them on demand.

ॐ · MIT

audio
codec
decoder
wav
webassembly

audiojs/decode

Minimal audio decoders layer

JavaScript

209

261 commits

updated Oct 8, 2026

See the code

README

@audio/decode test

Try it in the browser: Extract audio from video, Audio converter.

Decode any audio format to raw samples.
JS / WASM with no ffmpeg or native bindings; works in Node.js and browsers.
Small API, minimal size, near-native performance, lazy-loading, chunked decoding.

npm install @audio/decode

import decode from '@audio/decode';

const { channelData, sampleRate } = await decode(anyAudioBuffer);

Supported formats

FormatPackageSizeEngine
MP3@audio/decode-mp392 KBWASM
WAV@audio/decode-wav11 KBJS
OGG Vorbis@audio/decode-vorbis166 KBWASM
FLAC@audio/decode-flac135 KBWASM
Opus@audio/decode-opus166 KBWASM
M4A / AAC / ALAC@audio/decode-aac368 KBWASM + JS
MP4 / MOV / M4V / 3GP video@audio/decode-mp412 KB + codecJS demux
QOA@audio/decode-qoa8 KBJS
AIFF@audio/decode-aiff20 KBJS
CAF@audio/decode-caf9 KBJS
WebM / MKV video@audio/decode-webm250 KBWASM
AVI video@audio/decode-avi8 KB + codecJS demux
AC-3@audio/decode-ac343 KBWASM
DTS@audio/decode-dts200 KBWASM
E-AC-3 (Dolby Digital Plus, + AC-3)@audio/decode-eac3432 KBWASM (FFmpeg libavcodec, LGPL)
APE (Monkey's Audio)@audio/decode-ape262 KBWASM (FFmpeg libavcodec, LGPL)
AMR@audio/decode-amr241 KBWASM
GSM 06.10 (raw frames, by name)@audio/decode-gsm23 KBWASM (libgsm)
WMA (v1, v2, Pro, Lossless)@audio/decode-wma463 KBWASM (FFmpeg libavcodec, LGPL)
WavPack@audio/decode-wavpack51 KBWASM
TTA (True Audio)@audio/decode-tta11 KBJS
Musepack SV7 / SV8@audio/decode-mpc51 KBWASM
MOD / XM / S3M / IT tracker modules@audio/decode-mod1.4 MBWASM (libopenmpt)
DSF / DFF (DSD64–512 → PCM)@audio/decode-dsd18 KBJS

Whole-file

Auto-detects format. Input can be ArrayBuffer, Uint8Array, Buffer, or anything that materializes to bytes, including a Blob/File or fetch Response.

import decode from '@audio/decode'

let { channelData, sampleRate } = await decode(buf)
let fromFile = await decode(fileInput.files[0])   // File
let fromUrl  = await decode(await fetch(url))      // Response

Chunked

let dec = await decode.mp3()
let a = await dec(chunk1)    // { channelData, sampleRate }
let b = await dec(chunk2)
await dec()                  // close

Streaming

import decode from '@audio/decode'

for await (let { channelData, sampleRate } of decode.mp3(response.body)) {
  // process chunks
}

Works with ReadableStream, fetch body, Node stream, or any async iterable.

Formats: mp3, flac, opus, oga, m4a, mp4, mov, wav, qoa, aac, aiff, caf, webm, mkv, avi, ac3, dts, amr, gsm, wma, eac3, ape, wv, tta, mpc, dsf, dff, mod, xm, s3m, it.

Video files

Video containers decode straight to their audio track — the video stream is skipped, no ffmpeg involved:

let { channelData, sampleRate } = await decode(await fetch('trailer.mp4'))
ContainerPackageAudio codecs
MP4, MOV, M4V, 3GP@audio/decode-mp4AAC, ALAC, MP3, FLAC, Opus, AC-3, DTS, AMR, PCM, G.711
WebM, MKV@audio/decode-webmOpus, Vorbis, AAC, ALAC, MP3, FLAC, AC-3, DTS, PCM
AVI@audio/decode-aviPCM, MP3, AAC, AC-3, DTS, G.711

Surround tracks keep their layout (up to 5.1, WAV channel order). E-AC-3 and TrueHD tracks throw an error naming the codec.

Browser

Works from a CDN without a bundler. Codecs load on demand via dynamic import, only for formats you decode:

<script type="module">
  import decode from 'https://esm.sh/@audio/decode'
  let { channelData, sampleRate } = await decode(buf)
</script>

For self-hosting, use an import map to point @audio/decode and each needed @audio/decode-* package to local files. Codec-internal files load by relative path.

Each codec package's main export works in an AudioWorklet without Blob, TextDecoder, Worker, or fetch. Import codec packages directly because @audio/decode uses dynamic imports.

Initialize WASM before rendering. Decoding runs on the worklet thread and can interrupt audio output.

Synchronous codecs

The umbrella remains async for detection, lazy imports, and Blob/Response inputs. Import a codec package directly for synchronous calls.

wav, qoa, aiff, and caf are synchronous:

import decode from '@audio/decode-wav'
let pcm = decode(wavBytes)

WASM codecs initialize asynchronously, then decode synchronously:

import { decoder } from '@audio/decode-flac'
let dec = await decoder()
let pcm = dec.decode(bytes)
let tail = dec.flush()
dec.free()

Metadata

Read tags, pictures, markers and regions without decoding samples. Available for wav, mp3, flac, oga (Ogg Vorbis), opus, and m4a.

import { wav, mp3, flac, oga, opus, m4a } from '@audio/decode/meta'

let { meta, sampleRate, markers, regions } = mp3(bytes)
// meta: { title, artist, album, year, bpm, key, comment, pictures, raw, ... }
// markers: [{ sample, label }]
// regions: [{ sample, length, label }]

Each codec sub-package also exposes its parser directly:

import { parseMeta } from '@audio/decode-wav/meta'
let info = parseMeta(wavBytes)

WebWorker

Each @audio/decode-* package is a self-contained ESM module that can run in a worker:

// decode-worker.js
import decode from '@audio/decode-mp3'

self.onmessage = async ({ data }) => {
  let pcm = await decode(data)
  self.postMessage(pcm, pcm.channelData.map(ch => ch.buffer))
}

// main.js
let worker = new Worker('./decode-worker.js', { type: 'module' })
worker.postMessage(mp3buf, [mp3buf])
worker.onmessage = ({ data }) => { /* { channelData, sampleRate } */ }

See also

  • audio – edit, measure and save: trim, loudness to spec, delivery checks, a CLI.
  • encode – encode PCM into any audio format.
  • audio-type – detect audio format from buffer.

Licensing

The umbrella and most codec packages are MIT. Codecs built on other libraries carry that library's license: @audio/decode-aac GPL-2.0; @audio/decode-ac3 and @audio/decode-dts GPL-2.0-or-later; @audio/decode-ape, @audio/decode-eac3 and @audio/decode-wma LGPL-2.1-or-later (a slim FFmpeg libavcodec build, no GPL components); @audio/decode-wavpack, @audio/decode-mpc and @audio/decode-mod BSD-3-Clause; @audio/decode-amr Apache-2.0. Install only the codecs whose licenses fit your project. The umbrella loads them on demand.

ॐ · MIT

audio
codec
decoder
wav
webassembly

Project health

Latest release

4.1.1 · Oct 7, 2026

Releases this year

15

Significant stargazers

Chris Needham

206 followers · starred Jan 2019

Dannii Willis

119 followers · starred Oct 2024

katspaugh

704 followers · starred Aug 2023

Miika Kuisma

9 followers · starred Mar 2024