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-apiVerified import paths — ran on the pinned version, not inferred.
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.
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).
Always include `await ctx.resume()` after creating a new `AudioContext` instance to ensure audio processing begins.
If you intend to use real-time audio output, ensure `audio-speaker` is installed as a dependency: `npm install audio-speaker`.
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).
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`).Add `await ctx.resume()` immediately after creating your `AudioContext` instance: `const ctx = new AudioContext(); await ctx.resume();`
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);`