API Reference

Complete reference for the decibri-web browser API. For installation and basic usage, see Getting Started.

Constructor

new Decibri(options?)

Creates a new capture instance. Does not start capture. Call start() to begin.

import { Decibri } from 'decibri-web';
const mic = new Decibri(options?);
Option Type Default Description
sampleRate number 16000 Target sample rate in Hz (1,000 to 384,000)
channels number 1 Number of channels (browsers reliably support 1)
framesPerBuffer number 1600 Frames per chunk. 1,600 at 16 kHz = 100 ms chunks (64 to 65,536)
device string system default deviceId string from Decibri.devices()
format 'int16' | 'float32' 'int16' Sample encoding format
vad boolean false Enable voice activity detection
vadThreshold number 0.01 RMS energy threshold for speech detection (0 to 1)
vadHoldoff number 300 Milliseconds of sub-threshold audio before 'silence' is emitted
echoCancellation boolean true Browser echo cancellation. Set false for music/tuner apps
noiseSuppression boolean true Browser noise suppression. Set false for raw signal
workletUrl string (inline Blob URL) URL for AudioWorklet processor file. Override if CSP blocks blob: URLs

Methods

mic.start()

Returns Promise<void>. Requests microphone permission and begins capture. Must be called from a user gesture in Safari. No-op if already started. Rejects with a clear error on permission denial.

mic.stop()

Stops capture and releases all resources (tracks, context, nodes). Safe to call anytime, including before start() or multiple times. Emits 'end' then 'close'.

Properties

mic.isOpen

boolean (read-only). Returns true while actively capturing audio.

Static methods

Decibri.devices()

Returns Promise<DeviceInfo[]>. Lists available audio input devices. Labels may be empty before microphone permission is granted.

const devices = await Decibri.devices();
console.log(devices);
// [
//   { deviceId: 'abc123', label: 'Built-in Microphone', groupId: 'g1' },
//   ...
// ]

Decibri.version()

Returns version information for decibri-web.

Decibri.version();
// { decibriWeb: '0.1.0' }

Events

Event Payload Description
'data' Int16Array or Float32Array Audio chunk. Format depends on format option. Emitted ~10 times/sec at default settings.
'error' Error Permission denied, worklet load failure, AudioContext creation failure.
'end' (none) Emitted after stop().
'close' (none) Emitted after stop(), after 'end'.
'speech' (none) VAD: RMS energy crossed threshold. Requires vad: true.
'silence' (none) VAD: sub-threshold audio for vadHoldoff ms. Requires vad: true.

Types

// DeviceInfo
{
  deviceId: string,
  label: string,
  groupId: string,
}

// VersionInfo
{
  decibriWeb: string,
}

Differences from decibri (Node.js)

Feature Node.js decibri decibri-web Notes
Class name Decibri Decibri Identical
Constructor Sync, capture starts on read Sync, requires await start() Browser needs async permission
'data' payload Buffer Int16Array / Float32Array Different types, same PCM data
devices() Sync Async (returns Promise) Browser API is async
device option Number index or name substring String deviceId only Browser uses opaque device IDs
version() { decibri, portaudio } { decibriWeb } Different runtime info
echoCancellation N/A boolean (default true) Browser-only option
noiseSuppression N/A boolean (default true) Browser-only option
'backpressure' event Available Not available No browser equivalent
pipe() / streams Full Readable stream Not available Browser has no Node streams
sampleRate Any (PortAudio resamples) Any (AudioWorklet resamples) Same behavior
format 'int16' or 'float32' 'int16' or 'float32' Identical
VAD (speech/silence) RMS-based RMS-based (same algorithm) Identical