https://github.com/abalabahaha/opusscript
JS bindings for libopus 1.4, ported with Emscripten
https://github.com/abalabahaha/opusscript
emscripten libopus
Last synced: about 2 months ago
JSON representation
JS bindings for libopus 1.4, ported with Emscripten
- Host: GitHub
- URL: https://github.com/abalabahaha/opusscript
- Owner: abalabahaha
- License: mit
- Created: 2016-08-15T02:05:27.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2023-10-13T16:29:41.000Z (over 1 year ago)
- Last Synced: 2024-04-24T18:55:02.903Z (about 1 year ago)
- Topics: emscripten, libopus
- Language: JavaScript
- Homepage:
- Size: 1.91 MB
- Stars: 58
- Watchers: 4
- Forks: 18
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# OpusScript
JS bindings for libopus 1.4, ported with Emscripten.
----
## Usage
```js
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.
```js
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.
```ts
// Import using:
import OpusScript = require("opusscript");// and NOT:
import OpusScript from "opusscript";
```