Registry / http-networking / web-audio-api

web-audio-api

JSON →
library0.5.0jsnpmunverified

The `web-audio-api` package provides a 100% compliant, portable implementation of the W3C Web Audio API specification for Node.js environments. It currently stands at version 1.3.3 and aims for a stable, consistent release cadence, often aligning with updates to its underlying digital signal processing dependencies. Key differentiators include its complete WPT (Web Platform Tests) conformance, enabling server-side audio generation, CI/CD audio testing without requiring physical speakers, and the ability to run existing Web Audio API libraries like Tone.js directly in Node.js. It supports all 26 audio node types, sample-accurate scheduling, AudioWorklets, and full AudioParam automation. It can output in real-time via the `speaker` package or render to `Float32Array` buffers for offline processing.

npm install web-audio-api
INSTALL
IMPORT
SIG · WEB-AUDIO-API
W
web-audio-api
http-networkingjavascriptv0.5.0
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18–226 runs
build_error
glibc
node 18–226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

AudioContext
✓ import { AudioContext } from 'web-audio-api'
✗ const { AudioContext } = require('web-audio-api')
ESM-only since v1.0.0. Use `import` statement for Node.js modules.
OfflineAudioContext
✓ import { OfflineAudioContext } from 'web-audio-api'
✗ const OfflineAudioContext = require('web-audio-api').OfflineAudioContext
ESM-only. Used for rendering audio to a buffer without real-time output.
Polyfill
✓ import 'web-audio-api/polyfill'
✗ require('web-audio-api/polyfill')
This import extends the global `AudioContext` and `OfflineAudioContext` for browser environments. Not typically needed for Node.js usage.

Demonstrates creating an AudioContext, an oscillator, connecting it to the destination via a gain node, playing a tone, and stopping it, closing the context cleanly.

import { AudioContext } from 'web-audio-api'; const ctx = new AudioContext(); // Ensure the context is running; important for some environments. // In a browser environment, this might be triggered by user interaction. // In Node.js, we explicitly resume. await ctx.resume(); const osc = ctx.createOscillator(); osc.type = 'sine'; // Default is 'sine', but good to be explicit osc.frequency.value = 440; // A4 note const gainNode = ctx.createGain(); gainNode.gain.value = 0.5; // Half volume osc.connect(gainNode); gainNode.connect(ctx.destination); osc.start(); console.log('Playing A440 for 2 seconds...'); // Stop after 2 seconds setTimeout(() => { osc.stop(); ctx.close(); // Important to release resources, especially in Node.js console.log('Audio stopped and context closed.'); }, 2000);
Debug
Known issues
breakingThe package moved to be ESM-only for its main entry point, requiring `import` statements instead of `require()`. This was a major shift for Node.js users.
fix
Migrate CommonJS `require()` calls to ES module `import` statements. Ensure your Node.js project is configured for ESM (e.g., `"type": "module"` in `package.json` or using `.mjs` file extensions).
affects: >=1.0.0
gotchaThe `AudioContext` in Node.js requires an explicit `ctx.resume()` call to start processing audio, similar to how browsers often gate audio playback on user interaction. Failing to call `resume()` will result in no sound.
fix
Always include `await ctx.resume()` after creating a new `AudioContext` instance to ensure audio processing begins.
affects: >=1.0.0
gotchaFor real-time audio output, `web-audio-api` automatically detects and uses the `speaker` package. If `speaker` is not installed, it will fall back to other output mechanisms or fail to produce real-time sound.
fix
If you intend to use real-time audio output, ensure `audio-speaker` is installed as a dependency: `npm install audio-speaker`.
affects: >=1.0.0
breakingInternal DSP implementations for `BiquadFilterNode`, `PeriodicWave`, and `WaveShaperNode` were refactored to delegate coefficient math and wavetable synthesis to external `digital-filter` and `periodic-function` libraries.
fix
This is primarily an internal change and generally not breaking for users consuming the public API. However, if you were relying on specific internal implementation details (which is not recommended), you might need to adjust. Ensure `digital-filter` and `periodic-function` are installed if not already (they are listed as dependencies).
affects: >=1.3.0
Errors
Common errors & fixes
Error [ERR_REQUIRE_ESM]: require() of ES Module ...web-audio-api/index.js from ... not supported.
Attempting to `require()` the `web-audio-api` package in a CommonJS module context, but the package is now ESM-only.
fix
Change your import statement from `const { AudioContext } = require('web-audio-api')` to `import { AudioContext } from 'web-audio-api'`. Ensure your Node.js project is configured for ESM (e.g., add `"type": "module"` to your `package.json` or rename files to `.mjs`).
AudioContext.destination.connect: The destination is not yet initialized or ready.
The `AudioContext` was created but `ctx.resume()` was not called, preventing the audio graph from starting.
fix
Add `await ctx.resume()` immediately after creating your `AudioContext` instance: `const ctx = new AudioContext(); await ctx.resume();`
TypeError: Cannot read properties of undefined (reading 'connect')
Often happens when an `AudioNode` is not correctly connected or if `ctx.destination` is not available, which can be an symptom of the `AudioContext` not being resumed.
fix
Verify that `await ctx.resume()` has been called on the `AudioContext` and that all `AudioNode` connections are correctly chained, e.g., `osc.connect(gainNode); gainNode.connect(ctx.destination);`
Upgrade
Version history
0.5.0latest on npm
Audit
Dependencies
audio-speakeroptionalProvides real-time audio output functionality for `AudioContext`. Automatically detected if present.
digital-filterrequiredUsed for biquad filter coefficients and half-band FIR derivation.
periodic-functionrequiredUsed for wavetable synthesis in `PeriodicWave`.
Agent activity
14 hits · last 30 days
node
12
OpenAI (training)
1
Resources
web-audio-api — npm install web-audio-api · libregistry