Skip to content

sapphi-red/web-noise-suppressor

Repository files navigation

@sapphi-red/web-noise-suppressor

npm version CI

Noise suppressor nodes for Web Audio API.

Demo

This package provides three noise suppression nodes.

This package requires AudioWorklet to work.

Install

npm i @sapphi-red/web-noise-suppressor # yarn add @sapphi-red/web-noise-suppressor

Usage

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.