npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@vocaltale/opus.js

v1.0.0-beta.3

Published

Opus codec ported with emscripten, supports PCM in 32-bits Float format. Useful for Web Audio AudioWorkletProcessor

Downloads

5

Readme

opus.js

Inspired by OpusScript and opus-recorder,a JavaScript library compiled from libopus using Emscripten.

Usage

Install with

npm i -S @vocaltale/opus.js

// or

yarn add @vocaltale/opus.js

Here is an example using Node.js to encode PCM in 32-bits floating point to opus and write it to a file using Ogg container format.

const fs = require('fs')
const {
  Encoder,
  Ogg,
} = require('@vocaltale/opus.js')

const encoder = new Encoder(48000, 1, { maxFrameSize: 960 })
// const decoder = new Decoder(48000, 1, { maxFrameSize: 960 })

const raw = new Float32Array(960)
let encoded = null
const ogg = new Ogg(48000, 1, 960, 16)
const stream = fs.createWriteStream('test.opus')

stream.write(ogg.generateIdPage())
stream.write(ogg.generateCommentPage())

raw.fill(0.1)
encoded = encoder.encodeFloat(raw)

// console.log(encoded.length)
const packets = ogg.segmentPacket(encoded)

packets.forEach(packet => {
  stream.write(packet)
})

const all = ogg.finalize()

stream.write(all)
stream.end()

encoder.delete()

For browser applications, we might want to use esModule version for Webpack 5 Lazy-loading.

import {
  Codec,
  OpusApplication
} from '@vocaltale/opus.js/esm'

const codec = new Codec(48000, 1, {
  maxFrameSize: 960,
  application: OpusApplication.RESTRICTED_LOWDELAY,
})

const raw = new Float32Array(960)
let encoded = null

raw.fill(0.1)
encoded = codec.encodeFloat(raw)

// ...

const decoded = codec.decodeFloat(encoded)

codec.delete()

The only tricky part is to place the build/opus-<codec|encoder|decoder>.wasm to the correct place so the script can run, but let's stop here for you as a challenge.

Remember opus is a stateful codec; don't use the same encoder/decoder with multiple sources. Or you might can weird, noisy results.

Enhancements

  1. Webpack 5 Lazy-loading support (using await import() syntax) (only available for esModule, @vocaltale/opus.js/esm)
  2. Automatically fallback to opus-<codec|encoder|decoder>.asm.js if WASM is not supported
  3. Support 32-bits Float formatted PCM data
  4. Lower memory usage by limiting the stack size and the heap size further
  5. Separated encoder and decoder, .wasm files can be much smaller if don't need both of them. Original codec is also there if you need both of them; they share the same stack and heap memory.