OpusScript
JS bindings for libopus 1.3.1, ported with Emscripten.
Usage
var OpusScript = require("opusscript");
var samplingRate = 48000;
var frameDuration = 20;
var channels = 2;
var encoder = new OpusScript(samplingRate, channels, OpusScript.Application.AUDIO);
var frameSize = samplingRate * frameDuration / 1000;
var pcmData = new Buffer(pcmSource);
var encodedPacket = encoder.encode(pcmData, frameSize);
var decodedPacket = encoder.decode(encodedPacket);
encoder.delete();
Note: WASM
If your environment doesn't support WASM, you can try the JS-only module. Do note that the JS-only version barely has optimizations due to compiler/toolchain limitations, and should only be used as a last resort.
var encoder = new OpusScript(samplingRate, channels, OpusScript.Application.AUDIO, {
wasm: false
});
Note: TypeScript
Since this module wasn't written for TypeScript, you need to use import = require
syntax.
import OpusScript = require("opusscript");
import OpusScript from "opusscript";