Noise suppressor nodes for Web Audio API.
This package provides three noise suppression nodes.
- NoiseGateWorkletNode: A simple noise gate implementation
- RnnoiseWorkletNode: Based on xiph/rnnoise
- Using shiguredo/rnnoise-wasm
- SpeexWorkletNode: Based on xiph/speexdsp's
preprocess
function
This package requires AudioWorklet to work.
npm i @sapphi-red/web-noise-suppressor # yarn add @sapphi-red/web-noise-suppressor
This section is written only for vite users.
import { SpeexWorkletNode, loadSpeex } from '@sapphi-red/web-noise-suppressor'
import speexWorkletPath from '@sapphi-red/web-noise-suppressor/speexWorklet.js?url'
import speexWasmPath from '@sapphi-red/web-noise-suppressor/speex.wasm?url' // you can use `vite-plugin-static-copy` instead of this
const ctx = new AudioContext()
const speexWasmBinary = await loadSpeex({ url: speexWasmPath })
await ctx.audioWorklet.addModule(speexWorkletPath)
const stream = await navigator.mediaDevices.getUserMedia({
audio: true
})
const source = ctx.createMediaStreamSource(stream)
const speex = new SpeexWorkletNode(ctx, {
wasmBinary: speexWasmBinary,
maxChannels: 2
})
source.connect(speex)
speex.connect(ctx.destination)
For more details, see demo source code.