opusscript
JS bindings for libopus 1.2.1, ported with emscripten
Last updated 9 years ago by abalabahaha .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install opusscript 
SYNC missed versions from official npm registry.

OpusScript

JS bindings for libopus 1.4, ported with Emscripten.


Usage

var OpusScript = require("opusscript");

// 48kHz sampling rate, 20ms frame duration, stereo audio (2 channels)
var samplingRate = 48000;
var frameDuration = 20;
var channels = 2;

// Optimize encoding for audio. Available applications are VOIP, AUDIO, and RESTRICTED_LOWDELAY
var encoder = new OpusScript(samplingRate, channels, OpusScript.Application.AUDIO);

var frameSize = samplingRate * frameDuration / 1000;

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

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

// Delete the encoder when finished with it (Emscripten does not automatically call C++ object destructors)
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 using:
import OpusScript = require("opusscript");

// and NOT:
import OpusScript from "opusscript";

Current Tags

  • 0.1.1                                ...           latest (3 years ago)

9 Versions

  • 0.1.1                                ...           3 years ago
  • 0.1.0                                ...           3 years ago
  • 0.0.8                                ...           5 years ago
  • 0.0.7                                ...           7 years ago
  • 0.0.6 [deprecated]           ...           8 years ago
  • 0.0.4                                ...           9 years ago
  • 0.0.3                                ...           9 years ago
  • 0.0.2                                ...           9 years ago
  • 0.0.1                                ...           10 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 1
Last Day 0
Last Week 1
Last Month 0
Dependencies (0)
None
Dev Dependencies (0)
None
Dependents (1)

Copyright 2013 - present © cnpmjs.org | Home |