audio

@audio/encode-wav1.5.3

Encode PCM audio samples to WAV format

Status
calibrated
Updated
Family
encode, 15 packages under it
Category
codecs
Standards
EBU Tech 3306
Licence
MIT
Dependencies
none
Downloads
8,025 last month
Tests
at least 34 in audiojs/encode's CI, passed at 22bf060,

Encode PCM audio samples to WAV format.
Pure JS — no WASM, no native bindings, works in both node and browser.

import wav from '@audio/encode-wav';

const encoder = await wav({ sampleRate: 44100 });
encoder.encode(channelData);    // buffer PCM
const buffer = encoder.flush(); // → complete WAV file as Uint8Array

Options

Option Default Description
sampleRate — Sample rate (required)
bitDepth 16 16 (PCM int) or 32 (IEEE float)

Streaming

const encoder = await wav({ sampleRate: 44100, bitDepth: 16 });
encoder.encode(chunk1); // buffer chunk
encoder.encode(chunk2); // buffer chunk
const file = encoder.flush(); // → Uint8Array (complete WAV)
encoder.free();

Input is Float32Array[] — one array per channel. Channels are interleaved automatically.

Streaming output

stream: true: the header goes out with the first samples, sizes 0xFFFFFFFF (read to the end) and a JUNK chunk reserved for ds64, metadata chunks (meta, markers, regions) inside it. After flush(), head() returns the exact header, RF64 past 4 GB (EBU Tech 3306), to write over the start of a file. With frames (the exact length, known upfront) the header goes out exact and head() has nothing to add.

License

MIT

ॐ