Skip to main content
Deno 2 is finally here πŸŽ‰οΈ
Learn more

opus

Tags CI Status License

const SAMPLE_RATE = 48000;
const FRAME = 20;
const CHANNELS = 2;

await Opus.load();

// Optimize encoding for audio. Available applications are VOIP, AUDIO, and RESTRICTED_LOWDELAY
let encoder = new Opus(SAMPLE_RATE, CHANNELS, OpusApplication.AUDIO);

let frameSize = SAMPLE_RATE * FRAME / 1000;

// Get PCM data from somewhere and encode it into opus
let pcmData = new Uint8Array();
let encodedPacket = encoder.encode(pcmData, frameSize);

// Decode the opus packet back into PCM
let decodedPacket = encoder.decode(encodedPacket);
console.log(decodedPacket);

// Delete the encoder when finished with it (Emscripten does not automatically call C++ object destructors)
encoder.delete();

Maintainers

Other

  • opusscript - nodejs bindings for libopus 1.3.1, ported with emscripten

Contribution

Pull request, issues and feedback are very welcome. Code style is formatted with deno fmt and commit messages are done following Conventional Commits spec.

Licence

Copyright 2020-present, the denosaurs team. All rights reserved. MIT license.