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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@rocket.chat/mp3-encoder

v0.32.0

Published

A LAME encoder to be used in web workers

Readme

@rocket.chat/mp3-encoder

A LAME-based MP3 encoder that runs as a web worker.

npm downloads

This package is a web worker script that encodes raw audio samples into an MP3 stream. It is a TypeScript port of the LAME encoder, so it needs no native code or WebAssembly. Rocket.Chat uses it to encode voice messages recorded in the browser.

The package has no exports. You load its built file as a worker and talk to it with postMessage.

Installation

npm install @rocket.chat/mp3-encoder

There are no dependencies. The worker script is published as dist/index.js, a classic script suitable for new Worker(url).

Usage

Serving the worker

Copy or link node_modules/@rocket.chat/mp3-encoder/dist/index.js to a path your app serves as a static file, then start a worker from it:

const worker = new Worker('/workers/mp3-encoder/index.js');

Encoding audio

The worker understands three commands:

  1. init sets up a new encoder.
  2. encode sends a chunk of samples. Send as many as you need.
  3. finish flushes the encoder. The worker answers with an end message holding the encoded MP3.
const worker = new Worker('/workers/mp3-encoder/index.js');

worker.onmessage = (event: MessageEvent) => {
	if (event.data.command === 'end') {
		const mp3 = new Blob(event.data.buffer, { type: 'audio/mpeg' });
		worker.terminate();
		// upload or play `mp3`
	}
};

worker.postMessage({
	command: 'init',
	config: { sampleRate: 48000, bitRate: 32 },
});

// For each chunk of mono audio, e.g. from an AudioWorklet or ScriptProcessorNode:
worker.postMessage({ command: 'encode', buffer: samples }); // Float32Array in [-1, 1]

// When recording stops:
worker.postMessage({ command: 'finish' });

The encoded output does not depend on how you split the samples into chunks. After finish, send init again to start a new stream.

API

Messages to the worker

| Message | Description | | ----------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------- | | { command: 'init', config?: { numChannels?, sampleRate?, bitRate? } } | Creates the encoder. Defaults: numChannels 1, sampleRate 44100 (Hz), bitRate 32 (kbps). sampleRate must match the audio you send. | | { command: 'encode', buffer: Float32Array } | Encodes a chunk of samples. Values are clamped to [-1, 1] and converted to 16-bit PCM. | | { command: 'finish' } | Flushes the encoder and posts the result. |

Messages from the worker

| Message | Description | | ----------------------------------------- | ------------------------------------------------------------------------------------------------- | | { command: 'end', buffer: Int8Array[] } | The MP3 stream as a list of chunks, in order. Pass the list to new Blob() to get a single file. |

Mono only

Each encode message is treated as a single channel. Mix multi-channel audio down to one channel before sending it.

Development

This package lives in the Rocket.Chat monorepo. From the repository root:

yarn workspace @rocket.chat/mp3-encoder build
yarn workspace @rocket.chat/mp3-encoder start
yarn workspace @rocket.chat/mp3-encoder testunit
yarn workspace @rocket.chat/mp3-encoder lint
yarn workspace @rocket.chat/mp3-encoder lint:fix
yarn workspace @rocket.chat/mp3-encoder typecheck

build bundles the worker with Rollup; start rebuilds on change. The tests encode the WAV files in testdata/ and compare the result with a known hash, so a change to the encoder that alters its output fails them.

License

MIT — see LICENSE.