Web Audio API for Node.js with WASM and SIMD optimizations
High-performance, browser-compatible Web Audio API for Node.js. Perfect for audio processing, sound generation, game audio, and music production.
⭐ Features
✨ Web Audio API Support
Core audio nodes (Oscillator, Gain, BiquadFilter, BufferSource)
AudioParam automation with scheduling
OfflineAudioContext for fast non-realtime rendering
AudioContext for real-time playback
5 audio formats via WASM decoders (MP3, WAV, FLAC, OGG, AAC) - see WASM Audio Decoders
High-quality resampling - Speex resampler with SIMD (same as Firefox uses)
Automatic sample rate detection - matches system audio device
🚀 High Performance
WASM with SIMD optimizations - beats Rust implementation in 90% of benchmarks (55/61)
~2,600x faster than realtime offline rendering
Fast resampling - Speex quality level 1 (200-850x realtime for common sample rates)
Sample-accurate timing - all audio timing managed in WASM using sample counters
Zero JavaScript overhead in audio rendering - JS only handles I/O through SDL
🎮 Perfect for Games
Procedural sound effect generation
Mix multiple audio sources
Low-latency playback with SDL2
📦 Installation
npm install webaudio-node
Requirements
Node.js 22+
No build step required - uses pre-compiled WASM
🎵 CLI Usage
Play audio files directly from the command line:
# Play any supported audio filenpx webaudio-node music.mp3# Or after global installnpm install -g webaudio-nodewebaudio-node sound.wav
Supported formats: MP3, WAV, FLAC, OGG, AAC
🎤 Microphone Effects
Transform your voice in real-time with built-in effects:
# Add reverb to your microphonewebaudio-node --reverb# Auto-tune your voice (vocoder-style effect)webaudio-node --auto-tune# Show all optionswebaudio-node --help
Press Ctrl+C to stop the effect and close the microphone.
🚀 Quick Start
Simple Beep
import { AudioContext } from 'webaudio-node';const ctx = new AudioContext();// Create 440Hz oscillatorconst osc = ctx.createOscillator();osc.frequency.value = 440;osc.connect(ctx.destination);// Play for 1 secondawait ctx.resume();osc.start();setTimeout(() => { osc.stop(); ctx.close();}, 1000);
import { readFileSync } from 'fs';const ctx = new AudioContext();const audioData = readFileSync('./audio.mp3');// Decode MP3/WAV/OGGconst buffer = await ctx.decodeAudioData(audioData.buffer);console.log(buffer.duration); // secondsconsole.log(buffer.numberOfChannels); // 1 or 2console.log(buffer.sampleRate); // Hz// Get audio dataconst channelData = buffer.getChannelData(0);
Note: Audio decoding is currently synchronous (blocks the event loop) but very fast with WASM. Most files decode in milliseconds. For non-blocking decoding in the future, see Threading Plan.
# Testingnpm test # Run test suitenpm run test:coverage # Run tests with coverage report# Linting & Formattingnpm run lint # Check code stylenpm run lint:fix # Auto-fix linting issuesnpm run format # Format code with Prettiernpm run format:check # Check formatting# Benchmarksnpm run benchmark # Run performance benchmarksnpm run benchmark:docs # Generate benchmark documentation