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

@puresignal/fetch-stream-audio

v0.2.3

Published

Low-latency streaming audio playback using Fetch, Streams, and Web Audio APIs

Readme

@puresignal/fetch-stream-audio

Low-latency streaming audio playback using the Fetch, Streams, and Web Audio APIs.

Traditional decodeAudioData() requires the complete file before playback. This library decodes audio chunk-by-chunk as it streams in, enabling real-time playback over slow or throttled connections.

Supports Opus (WebAssembly decoder, WASM inlined) and WAV (JavaScript decoder).

Install

npm install @puresignal/fetch-stream-audio

Usage

The player requires an external AudioContext and exposes connect() / disconnect() so it behaves like a standard Web Audio node.

import { AudioStreamPlayer } from '@puresignal/fetch-stream-audio';
import opusWorkerUrl from '@puresignal/fetch-stream-audio/worker-decoder-opus?url';

const audioCtx = new AudioContext({ latencyHint: 'interactive' });

const player = new AudioStreamPlayer(
  audioCtx,
  'https://example.com/audio.opus',
  1024 * 2,  // read buffer size in bytes
  'OPUS',    // or 'PCM' for WAV
  { opusWorkerUrl }
);

player.connect(audioCtx.destination);

player.onUpdateState = (state) => {
  console.log(state);
};

player.start();
// player.close() to stop playback

The ?url import suffix is supported by Vite, webpack 5, and other modern bundlers. It gives you a resolved URL to the worker file without executing it.

The Opus worker has its WebAssembly binary inlined, so no extra files need to be copied or served — just the ?url import and you're done.

Routing through Web Audio nodes

Because the player exposes connect(), you can route audio through gain nodes, analysers, or any other Web Audio processing:

const gain = audioCtx.createGain();
gain.gain.value = 0.5;

player.connect(gain);
gain.connect(audioCtx.destination);

player.start();

WAV streaming

import { AudioStreamPlayer } from '@puresignal/fetch-stream-audio';
import wavWorkerUrl from '@puresignal/fetch-stream-audio/worker-decoder-wav?url';

const audioCtx = new AudioContext({ latencyHint: 'interactive' });

const player = new AudioStreamPlayer(
  audioCtx,
  'https://example.com/audio.wav',
  1024 * 16,  // WAV needs a larger buffer to prevent skipping
  'PCM',
  { wavWorkerUrl }
);

player.connect(audioCtx.destination);

Script-tag / CDN (no bundler)

If you are not using a bundler, host the worker files and pass URLs explicitly:

const audioCtx = new AudioContext({ latencyHint: 'interactive' });

const player = new AudioStreamPlayer(audioCtx, url, 1024 * 2, 'OPUS', {
  opusWorkerUrl: '/assets/worker-decoder-opus.js'
});

player.connect(audioCtx.destination);

AudioContext lifecycle

The player does not own the AudioContext — you create it, you manage it. This means:

  • Call audioCtx.suspend() / audioCtx.resume() yourself to pause/resume playback
  • Call audioCtx.close() when you're done with all audio in your app
  • The player's close() method stops streaming and releases internal resources, but leaves the context intact so you can call start() again

State updates

Each onUpdateState callback receives a partial state object — only the properties that changed. Accumulate them to get the full picture:

const state = {};

player.onUpdateState = (partial) => {
  Object.assign(state, partial);
  // state.bytesRead, state.abCreated, state.latency, etc.
};

| Property | Type | Description | | -------- | ---- | ----------- | | bytesRead | number | Bytes downloaded so far | | bytesTotal | number | Total file size in bytes | | dlRate | number | Download rate in kbps | | latency | number | Initial latency in ms | | abCreated | number | AudioBuffers created | | abEnded | number | AudioBuffers finished playing | | abRemaining | number | AudioBuffers queued for playback | | skips | number | Audio skips (caused by slow download) | | error | string | Error message if something failed |

Published files

| File | Description | | ---- | ----------- | | dist/index.mjs | ESM library entry | | dist/index.cjs | CJS library entry | | dist/index.d.ts | TypeScript declarations | | dist/worker-decoder-opus.js | Bundled Opus decoder worker (WASM inlined) | | dist/worker-decoder-wav.js | Bundled WAV decoder worker |

Demo

A live demo with throttled bandwidth testing is available in the main repository.

License

Fork of AnthumChris/fetch-stream-audio.