# opusscript

> JS bindings for libopus 1.4, ported with emscripten

Latest version **0.1.1** (published 2023-10-10) · MIT license · 0 weekly downloads

## Install

```sh
npm install opusscript
pnpm add opusscript
yarn add opusscript
bun add opusscript
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.1 |
| Published | 2023-10-10 |
| First published | 2016-08-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 925.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 70 |
| Author | abalabahaha |
| Maintainers | abalabahaha |
| Keywords | libopus, encoder, emscripten |

## Links

- npm: https://www.npmjs.com/package/opusscript
- Repository: https://github.com/abalabahaha/opusscript
- Homepage: https://github.com/abalabahaha/opusscript#readme
- Issues: https://github.com/abalabahaha/opusscript/issues
- npm.io page: https://npm.io/package/opusscript

## Alternatives

- [flatbuffers](https://npm.io/package/flatbuffers.md) — 6.0M weekly downloads
- [jwt-simple](https://npm.io/package/jwt-simple.md) — 259.5K weekly downloads
- [@exodus/patch-broken-hermes-typed-arrays](https://npm.io/package/@exodus/patch-broken-hermes-typed-arrays.md) — 28.5K weekly downloads
- [@native-to-anchor/buffer-layout](https://npm.io/package/@native-to-anchor/buffer-layout.md) — 12.2K weekly downloads
- [binary-parser-encoder](https://npm.io/package/binary-parser-encoder.md) — 5.3K weekly downloads

## Recent versions

- 0.1.1 (latest) — 2023-10-10
- 0.1.0 — 2023-04-24
- 0.0.8 — 2021-02-24
- 0.0.7 — 2019-08-08
- 0.0.6 — 2017-12-13
- 0.0.4 — 2017-10-03
- 0.0.3 — 2017-03-12
- 0.0.2 — 2017-01-26
- 0.0.1 — 2016-08-28

## 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";
```

---
_Source: https://npm.io/package/opusscript · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
