audio

@audio/encode-ogg1.3.1

Encode PCM audio samples to OGG Vorbis format via WASM

Status
calibrated
Updated
Family
encode, 15 packages under it
Category
codecs
Licence
MIT AND BSD-3-Clause AND Apache-2.0
Bundles
libogg, libvorbis, swc-helpers, wasm-media-encoders
Dependencies
none
Downloads
9,408 last month
Tests
at least 34 in audiojs/encode's CI, passed at 22bf060,

Encode PCM audio samples to OGG Vorbis format.
WASM (libvorbis via wasm-media-encoders) — works in both node and browser.

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

const encoder = await ogg({ sampleRate: 44100, channels: 1, quality: 5 });
const chunk = encoder.encode(channelData); // → Uint8Array (OGG pages)
const tail = encoder.flush();              // → Uint8Array (remaining)

Options

Option Default Description
sampleRate — Sample rate (required)
channels auto 1 (mono) or 2 (stereo). Auto-detected from first encode call.
quality 3 VBR quality −1 to 10 (higher = better)

Streaming

const encoder = await ogg({ sampleRate: 44100, channels: 1 });
const a = encoder.encode(chunk1);
const b = encoder.encode(chunk2);
const c = encoder.flush();
// complete OGG = concat(a, b, c)
encoder.free();

Streaming output

stream: true with meta: the comment header is rewritten as the stream goes and later pages are renumbered on the fly, so tags never hold the output back.

License

MIT. ogg-encode.js bundles libvorbis and libogg, BSD-3-Clause (LICENSE.libvorbis, LICENSE.libogg), compiled by wasm-media-encoders, MIT (LICENSE.wasm-media-encoders), with three helpers of @swc/helpers, Apache-2.0 (LICENSE.swc-helpers).

ॐ