Speex Resampler
This lib exposes the Speex resampler to Javascript with WebAssembly. It doesn't have any dependancy and support NodeJS or a WebContext. Typescript typings are also provided.
From speex creator, the design goals of the resampler are:
- Very fast algorithm
- SIMD-friendly algorithm
- Low memory requirement
- Good perceptual quality (and not best SNR)
How to use
await SpeexResamplerinitPromise; // will be resolved once the WASM module has been compiled, before this you cannot call the SpeexResampler processChunk method const channels = 2; // minimum is 1, no maximumconst inRate = 44100; // frequency in Hz for the input chunkconst outRate = 44000; // frequency in Hz for the target chunkconst quality = 7; // number from 1 to 10, default to 7, 1 is fast but of bad quality, 10 is slow but best quality// you need a new resampler for every audio stream you want to resample// it keeps data from previous calls to improve the resamplingconst resampler = channels audioTestinRate audioTestoutRate audioTestquality // optionnal; const pcmData = Buffer;const res = await resampler;// res is also a buffer with interleaved signed 16 bits PCM data
You can look at the src/test.ts
for more information.
Test music by https://www.bensound.com