fast-phase-vocoder
v1.0.1
Published
A pure JavaScript, zero-dependency, transient-preserving phase vocoder for high-quality audio time stretching.
Maintainers
Readme
fast-phase-vocoder
A pure JavaScript, zero-dependency, transient-preserving phase vocoder for high-quality audio time stretching.
Why?
Most web developers looking for high-quality audio time-stretching (changing playback speed without altering pitch) are forced to use heavy WebAssembly (WASM) ports like rubberband-wasm. WASM has boot-time overhead and complicates build pipelines.
This library is a 100% pure JavaScript implementation of a phase vocoder that locks phases on transients (sharp sounds like consonants). This prevents the "metallic" or "echoey" artifacts common in naive JS stretchers.
- Fast: Processes 10 seconds of 24kHz audio in <100ms (100x faster than real-time).
- Zero Dependencies: No WASM, no external NPM packages required.
- Browser & Node: Works perfectly in
AudioContextor raw Float32Arrays.
Installation
npm install fast-phase-vocoderAudio Samples
Listen to the phase vocoder in action. These samples were generated natively using fast-phase-vocoder:
Usage
In the Browser (Web Audio API)
import { retimeAudioBuffer } from 'fast-phase-vocoder';
// Assuming you have an AudioContext and a decoded AudioBuffer
const newSpeed = 1.5; // 1.5x speed
const retimedBuffer = retimeAudioBuffer(audioContext, originalAudioBuffer, newSpeed);
const source = audioContext.createBufferSource();
source.buffer = retimedBuffer;
source.connect(audioContext.destination);
source.start();Raw Float32Array / PCM
import { retimeMonoPcm } from 'fast-phase-vocoder';
const pcm = new Float32Array([...]); // Your raw mono audio data
const sampleRate = 24000;
const newSpeed = 0.8; // Slow down to 80%
const retimedPcm = retimeMonoPcm(pcm, sampleRate, newSpeed);Credits
Mathematical processing (FFT) adapted from HuggingFace Transformers JS.
