libopus-wasm
Small, modern WASM bindings for libopus raw packet encode/decode.
libopus-wasm is a JavaScript library that brings the Opus audio codec to browsers and Node.js applications without requiring any native compilation. Opus is a widely used audio format for real-time voice and music transmission, and this library packages the official C reference implementation (libopus) as a single-file WebAssembly module that works identically in a browser or on a Node.js server.
The main use case is voice communication: the default settings encode audio at 48 kHz stereo with 20 ms frames, which is the standard configuration for voice-over-IP and real-time chat. You create an encoder, feed it raw audio samples as either 16-bit integers or 32-bit floats depending on what your audio pipeline produces, and receive compact Opus packets ready to send over a network. On the receiving end, a decoder turns those packets back into audio samples. Both factories share a single WebAssembly module instance that loads once and remains available for all subsequent calls.
The library supports loss recovery. You can enable in-band Forward Error Correction (FEC), which embeds partial recovery data in each packet so the decoder can partially reconstruct audio from a lost packet using the next one that arrives. If no recovery data is available, the decoder can synthesize a concealment frame to fill the gap without a harsh audio dropout.
Tuning options include variable or constant bitrate, complexity level (trading CPU usage for audio quality), signal type (voice versus music), bandwidth constraints, and discontinuous transmission to stop sending packets during silence. A control passthrough exposes less common encoder and decoder settings directly.
For discord.js users, the library includes a compatibility adapter that matches the API shape of the existing @discordjs/opus package, making it a drop-in replacement that does not require a C++ compiler or build toolchain. The npm package ships pre-compiled output, so most users never need to build from source. Building from source requires Emscripten. The library is ESM-only and requires Node.js 20 or any current browser.