#Try it
libopus-wasm wraps libopus 1.6.1 in a small, single-file WebAssembly module. The default path is realtime voice: 48 kHz, stereo, 20 ms frames, raw Opus packets — no Ogg or WebM container in the way.
import { createEncoder, createDecoder } from "libopus-wasm";
const encoder = await createEncoder(); // 48 kHz, stereo, 20 ms, audio
const decoder = await createDecoder();
const pcm = new Int16Array(960 * 2); // one 20 ms stereo frame
const packet = encoder.encode(pcm); // -> Uint8Array, a raw Opus packet
const frame = decoder.decode(packet); // -> Int16Array, interleaved PCM
encoder.free();
decoder.free();
The same module runs unchanged in browsers and Node. There is no locateFile hook, no second .wasm request, and no native build step at install time.
#What it does
- Raw Opus packets. Encode/decode single frames and batches. You own the
- Browser and Node from one entry. A single-file ES module with the WASM
- Int16 and Float32 PCM. Use whichever your audio pipeline already speaks.
- Loss resilience. In-band FEC plus packet-loss concealment for the frames
- Tunable. Bitrate, VBR/CBR, complexity, signal type, bandwidth, DTX, and a
- Drop-in for
@discordjs/opus. A compatibility adapter keeps the same
framing, so it drops straight into WebRTC, Discord, or a custom transport.
inlined. Bundles cleanly with Vite, webpack, esbuild, and friends.
that never arrive.
curated CTL passthrough for everything else.
method shape, minus the native toolchain.
#Pick your path
- Just trying it. Install then Quickstart —
- Encoding audio. Encoding covers Int16 vs Float32, frame
- Decoding audio. Decoding covers output capacity and
- Handling loss. Packet loss walks through FEC and PLC for
- Inspecting packets. Packet inspection reads a packet's
- Tuning quality and bitrate. Encoder tuning and the
- Coming from Discord. discord.js compatibility is a near
- Shipping to the web. Browser usage covers bundlers and Web
- Looking up a method. The API reference lists every
- Handling failures. Errors & validation explains when a call
a full encode/decode roundtrip in a couple of minutes.
sizes, and batches.
variable packet durations.
realtime streams.
duration, frames, and bandwidth without decoding it.
drop-in for @discordjs/opus.
Audio capture.
function, option, and constant.
throws RangeError versus OpusError.
#Project
Wraps libopus 1.6.1 from Xiph.Org. Released under the MIT license; libopus carries its own BSD license, reproduced in THIRDPARTYNOTICES. Source and issues live on GitHub. Not affiliated with Xiph.Org or the Opus authors.