Skip to content

Getting started

Install

bash
npm install dsp-audio-metrics

Requires Node.js >= 18 (native node:test is used in the test suite; the library itself only needs Float64Array and Math, so it runs anywhere ESM runs). There are no runtime dependencies.

As a library

js
import { measure, integratedLufs, truePeakDb } from "dsp-audio-metrics";

// A Float64Array, a plain Array, or a 2-D array of channels all work.
const mono = new Float64Array(48000).map((_, i) =>
  Math.sin((2 * Math.PI * 1000 * i) / 48000),
);

const r = measure(mono, 48000);
console.log(r.integratedLufs); // ≈ -3.01
console.log(r.truePeakDb);     // ≈ 0
console.log(r.loudnessRange);  // ≈ 0 for a constant tone

const t = truePeakDb(mono, 48000); // peak of the >=192 kHz reconstruction

The input can be:

  • a Float64Array / Array<number> — treated as a mono channel, normalized to stereo,
  • a 2-D array of Float64Arrays — treated as individual channels,
  • any sample rate — internally resampled to the 48 kHz measurement grid.

As a CLI

bash
npx dsp-audio-metrics track.wav
npx dsp-audio-metrics --json *.wav
text
track.wav
  duration    3:42.10  (2ch @ 44100 Hz)
  integrated  -14.21 LUFS
  true peak   -6.40 dBTP
  LRA         8.4 LU
  levels      rms -19.8 dB | peak -12.1 dB | crest 7.7 dB
  width       -17.4 dB (avg side/mid)
  balance     sub=3.1% low=11.2% mid=67.0% high=18.7%

--json prints one object per file, suitable for piping into jq or a spreadsheet.

Reading the numbers

  • integratedLufs — the loudness-normalization number; what streaming platforms target.
  • shortTermLufs — 3 s window, refreshed every 100 ms.
  • loudnessRange (LRA) — spread of short-term loudness after discarding quiet/silent blocks.
  • truePeakDb — sample-peak of the oversampled signal, for true-peak limiting.
  • stereoWidthDb — mean side/mid level per block; -Infinity for mono content.
  • bandBalance — percent of energy in sub / low / mid / high bands.

All loudness values use the LUFS unit (== LKFS, they are interchangeable).