npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@audio/decode

v3.15.0

Published

Decode audio data in node or browser

Readme

@audio/decode test

Try it in the browser: Extract audio from video, Audio converter. Runs on this package, nothing is uploaded.

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

| Format | Package | Size | Engine | |--------|---------|------|--------| | MP3 | @audio/decode-mp3 | 92 KB | WASM | | WAV | @audio/decode-wav | 11 KB | JS | | OGG Vorbis | @audio/decode-vorbis | 166 KB | WASM | | FLAC | @audio/decode-flac | 135 KB | WASM | | Opus | @audio/decode-opus | 166 KB | WASM | | M4A / AAC / ALAC | @audio/decode-aac | 368 KB | WASM + JS | | MP4 / MOV / M4V / 3GP video | @audio/decode-mp4 | 12 KB + codec | JS demux | | QOA | @audio/decode-qoa | 8 KB | JS | | AIFF | @audio/decode-aiff | 20 KB | JS | | CAF | @audio/decode-caf | 9 KB | JS | | WebM / MKV video | @audio/decode-webm | 250 KB | WASM | | AVI video | @audio/decode-avi | 8 KB + codec | JS demux | | AC-3 | @audio/decode-ac3 | 43 KB | WASM | | DTS | @audio/decode-dts | 200 KB | WASM | | E-AC-3 (Dolby Digital Plus, + AC-3) | @audio/decode-eac3 | 432 KB | WASM (FFmpeg libavcodec, LGPL) | | APE (Monkey's Audio) | @audio/decode-ape | 262 KB | WASM (FFmpeg libavcodec, LGPL) | | AMR | @audio/decode-amr | 241 KB | WASM | | WMA | @audio/decode-wma | 91 KB | WASM | | WavPack | @audio/decode-wavpack | 51 KB | WASM | | TTA (True Audio) | @audio/decode-tta | 11 KB | JS | | Musepack SV7 / SV8 | @audio/decode-mpc | 51 KB | WASM | | MOD / XM / S3M / IT tracker modules | @audio/decode-mod | 1.4 MB | WASM (libopenmpt) | | DSF / DFF (DSD64–512 → PCM) | @audio/decode-dsd | 18 KB | JS |

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, 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'))

| Container | Package | Audio codecs | |---|---|---| | MP4, MOV, M4V, 3GP | @audio/decode-mp4 | AAC, ALAC, MP3, FLAC, Opus, AC-3, DTS, AMR, PCM, G.711 | | WebM, MKV | @audio/decode-webm | Opus, Vorbis, AAC, ALAC, MP3, FLAC, AC-3, DTS, PCM | | AVI | @audio/decode-avi | PCM, 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

  • 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-wma, @audio/decode-ac3 and @audio/decode-dts GPL-2.0-or-later; @audio/decode-ape and @audio/decode-eac3 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.