Node.js
Getting Started API Reference
Integrations
Speech-to-Text Keyword Spotting Voice Activity Detection
Back to decibri.dev

Getting Started

decibri is a native Node.js addon for cross-platform microphone audio capture. It wraps PortAudio with pre-built binaries, so there is nothing to install, compile, or configure. Just install the package and start streaming audio.

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, see the Sherpa-ONNX Silero VAD integration.

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, decibri falls back to compiling from source.

Next steps