Getting started with Decibri

Decibri captures audio and exposes it as a standard stream. Install, create a Decibri instance, and start reading PCM chunks. This page walks the Node.js workflow end-to-end; for browser usage see the Browser API, and for the command-line tool see CLI API.

Install

$ npm install decibri

Pre-built binaries are included for Windows x64, macOS arm64, and Linux x64/arm64. No build tools or system audio libraries are needed.

Quick start

Capture microphone audio and log the buffer size of each chunk:

const Decibri = require('decibri');
const mic = new Decibri({ sampleRate: 16000, channels: 1 });

mic.on('data', (chunk) => {
  // chunk is a Buffer of 16-bit PCM audio
  console.log(`Received ${chunk.length} bytes`);
});

// Stop after 5 seconds
setTimeout(() => mic.stop(), 5000);

Each chunk contains 100 ms of audio by default (1,600 frames at 16 kHz). The output format is 16-bit signed integer PCM, little-endian, which is the standard input expected by most speech engines.

Record audio to a file

Because decibri exposes a standard Node.js Readable stream, you can pipe audio directly to a file:

const Decibri = require('decibri');
const fs = require('fs');

const mic = new Decibri({ sampleRate: 44100, channels: 2 });
mic.pipe(fs.createWriteStream('capture.raw'));

Select a microphone

List available input devices and choose one by index or name:

const Decibri = require('decibri');

// List all input devices
const devices = Decibri.devices();
console.log(devices);

// Select by index
const mic = new Decibri({ device: 2, sampleRate: 16000, channels: 1 });

// Or select by name substring (case-insensitive)
const mic2 = new Decibri({ device: 'USB', sampleRate: 16000, channels: 1 });

Voice activity detection

Enable the built-in VAD to receive 'speech' and 'silence' events based on RMS energy thresholding:

const mic = new Decibri({
  sampleRate: 16000,
  channels: 1,
  vad: true,
  vadThreshold: 0.01,
  vadHoldoff: 300,
});

mic.on('speech', () => console.log('Speech detected'));
mic.on('silence', () => console.log('Silence detected'));

For more accurate detection in noisy environments, use the built-in Silero VAD (see below).

Silero voice activity detection

Decibri bundles the Silero VAD v5 ONNX model for ML-based speech detection. Set vadMode: 'silero' for more accurate detection than energy-based VAD, especially in noisy environments. The model runs locally in Rust via ONNX Runtime with no cloud API needed.

const mic = new Decibri({
  sampleRate: 16000,
  channels: 1,
  vad: true,
  vadMode: 'silero',
});

mic.on('speech', () => console.log('Speech detected'));
mic.on('silence', () => console.log('Silence detected'));

When vadMode is 'silero', the default vadThreshold changes from 0.01 to 0.5 (probability scale 0.0–1.0). You can override this by setting vadThreshold explicitly.

The bundled model is auto-resolved from the package. If you need a custom model, pass modelPath pointing to your .onnx file.

Audio output

DecibriOutput is a standard Node.js Writable stream for speaker playback. It uses the same native audio backend as capture.

const Decibri = require('decibri');
const { DecibriOutput } = Decibri;

const speaker = new DecibriOutput({ sampleRate: 16000, channels: 1 });
speaker.write(pcmBuffer);
speaker.end(); // plays all remaining audio, then emits 'finish'

The sampleRate, channels, and format options must match the audio data you are writing. Use speaker.stop() to immediately stop playback and discard remaining audio, or speaker.end() to drain the buffer and play everything.

Full duplex

Capture and playback simultaneously using standard Node.js pipe:

const Decibri = require('decibri');
const { DecibriOutput } = Decibri;

const mic = new Decibri({ sampleRate: 16000, channels: 1 });
const speaker = new DecibriOutput({ sampleRate: 16000, channels: 1 });
mic.pipe(speaker); // hear yourself in real time

Platform support

Pre-built binaries ship inside the npm package. No build tools, no compilation, no post-install downloads.

Platform Architecture Audio backend
Windows 11 x64 WASAPI
macOS arm64 (Apple Silicon) CoreAudio
Linux x64 ALSA
Linux arm64 ALSA

If no pre-built binary is available for your platform, installation will fail. There is no source build fallback.