Encode PCM audio samples to OGG Vorbis format.
WASM (libvorbis via wasm-media-encoders) — works in both node and browser.
import ogg from '@audio/ogg-encode';
const encoder = await ogg({ sampleRate: 44100, channels: 1, quality: 5 });
const chunk = encoder.encode(channelData); // → Uint8Array (OGG pages)
const tail = encoder.flush(); // → Uint8Array (remaining)| 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) |
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();