opus-library
v1.0.0
Published
A library wrapping the opus encoder/decoder
Maintainers
Readme
A tiny JS/TS wrapper around libopus compiled to WASM for browser and AudioWorklet use.
Installation
npm install opus-libraryUsage
import { createEncoder, createDecoder } from 'opus-library';
import wasmBinary from 'opus-library/dist/opusCodec.wasm';
(async () => {
// Create an encoder (48 kHz, mono, VOIP application)
const encoder = await createEncoder(wasmBinary, 48000, 1, 2048);
// Prepare a 20 ms frame at 48 kHz = 960 samples per channel
const pcmFrame = new Float32Array(960);
const encoded = encoder.encode(pcmFrame);
encoder.destroy();
// Create a decoder (48 kHz, mono)
const decoder = await createDecoder(wasmBinary, 48000, 1);
const decoded = decoder.decode(encoded);
decoder.destroy();
console.log(decoded.length); // should be 960
})();License
MIT
