🚨 Active Supply Chain Attack:node-ipc Package Compromised.Learn More
Socket
Book a DemoSign in
Socket

audio-inspect

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

audio-inspect

Lightweight yet powerful audio analysis library

latest
Source
npmnpm
Version
0.0.8
Version published
Maintainers
1
Created
Source

audio-inspect

TypeScript-first audio analysis library for offline and realtime use.

Install

npm i audio-inspect

Public API

audio-inspect exports only these top-level APIs:

  • load(source, options?)
  • analyze(audio, request)
  • inspect(source, request) (load + analyze convenience)
  • monitor(options) (realtime session)
  • prepareWorklet(context, options?) (optional preload)
  • FEATURES
  • AudioInspectError, isAudioInspectError

Quick Start (Offline)

import { inspect } from 'audio-inspect';

const result = await inspect('audio.mp3', {
  load: { normalize: true, sampleRate: 48000, resampleQuality: 'high' },
  features: {
    rms: { asDB: true },
    spectrum: { fftSize: 2048 }
  }
});

console.log(result.results.rms);
console.log(result.results.spectrum?.frequencies.length);

Decode Once, Analyze Many

import { load, analyze } from 'audio-inspect';

const audio = await load(file);

const pass1 = await analyze(audio, {
  features: { rms: true, peak: true }
});

const pass2 = await analyze(audio, {
  range: { start: 30, end: 45 },
  features: { lufs: true, spectralFeatures: true }
});

Realtime Monitor

import { monitor } from 'audio-inspect';

const session = await monitor({
  context: audioContext,
  source: micStream,
  features: {
    rms: { asDB: true },
    peak: { asDB: true }
  },
  realtimePolicy: 'warn',
  heavyFeatureInterval: 4,
  emit: 'raf'
});

function loop() {
  const frame = session.read();
  if (frame) {
    // frame.sampleIndex is hop-aligned and useful for sync.
    renderMeters(frame.results.rms, frame.results.peak);
  }
  requestAnimationFrame(loop);
}

loop();

Realtime policy options:

  • realtimePolicy: 'warn' | 'allow' | 'strict' (default: 'warn')
  • heavyFeatureInterval (default: 4)

Behavior:

  • 'allow': execute all selected features every hop.
  • 'warn': keep heavy features enabled, but execute them every heavyFeatureInterval frames.
  • 'strict': ignore heavy realtime features and emit REALTIME_POLICY_WARNING.

Dynamic Realtime Features

await session.setFeature('spectrum', { fftSize: 2048 });
await session.setFeature('spectrogram', {
  fftSize: 2048,
  frameSize: 2048,
  hopSize: 512,
  maxFrames: 60
});
await session.removeFeature('rms');
await session.setFeatures({ lufs: true, vad: { method: 'adaptive' } });

Worklet Strategy

monitor() is AudioWorklet-only. If AudioWorklet is unavailable, it throws WORKLET_NOT_SUPPORTED.

Optional preload:

import { prepareWorklet } from 'audio-inspect';

await prepareWorklet(audioContext, {
  moduleUrl: '/core/realtime/processor.js'
});

Node.js Offline Decode

In Node.js, compressed/container decoding requires decoder injection:

import { load } from 'audio-inspect';

const audio = await load(buffer, {
  decoder: {
    name: 'my-decoder',
    async decode(input) {
      // return AudioData
      return decodedAudioData;
    }
  }
});

If decode backend is missing, load() throws DECODE_BACKEND_MISSING.

If sampleRate conversion is requested, high-quality resampling is the default.

  • Browser: uses OfflineAudioContext when available.
  • Node.js: provide load.resampler for high-quality conversion, or set resampleQuality: 'fast' to opt into linear interpolation.

Error Handling

All public failures throw AudioInspectError.

import { isAudioInspectError } from 'audio-inspect';

try {
  // ...
} catch (error) {
  if (isAudioInspectError(error)) {
    console.error(error.code, error.message);
  }
}

Feature Selection Basics

features in analyze, inspect, and monitor supports two forms:

// 1) Object form (recommended when setting options)
features: {
  rms: true,                       // true = default options
  spectrum: { fftSize: 2048 }      // override options
}

// 2) Array form (default options only)
features: ['rms', 'peak', 'lufs']

You can list all available feature IDs with FEATURES:

import { FEATURES } from 'audio-inspect';
console.log(FEATURES);

For option types in TypeScript:

import type { FeatureOptions } from 'audio-inspect';
type LufsOptions = FeatureOptions<'lufs'>;

Feature Quick Reference

Time / Level

FeatureWhat it doesCommon options
rms, peakLevel measurement (linear or dB)channel, asDB, reference, truePeak, oversamplingFactor, interpolation
zeroCrossingZero-crossing ratechannel
peaksPeak detectioncount, threshold, channel, minDistance
waveformLightweight waveform summaryframesPerSecond, channel, method
rmsAnalysis, peaksAnalysis, waveformAnalysisTypedArray-oriented analysis resultsBase feature options + onProgress
energyShort-time energy over framesframeSize, hopSize, channel, normalized, windowFunction

Frequency / Spectral

FeatureWhat it doesCommon options
fftSingle-frame FFTfftSize, windowFunction, channel, provider, enableProfiling
spectrumBand-limited single-frame spectrumfftSize, minFrequency, maxFrequency, scale, normalization, windowFunction, channel
spectrogramMulti-frame STFT/spectrogram sequencefftSize, frameSize, hopSize, maxFrames, minFrequency, maxFrequency, scale, normalization, windowFunction, channel
spectralFeaturesCentroid/bandwidth/rolloff/flatness and morefftSize, windowFunction, minFrequency, maxFrequency, rolloffThreshold
timeVaryingSpectralFeaturesTime-series version of spectral featuresframeSize, hopSize, numFrames + spectral feature options
spectralEntropySpectral entropyfftSize, windowFunction, minFrequency, maxFrequency
spectralCrestSpectral crest factorfftSize, windowFunction, minFrequency, maxFrequency, asDB

Mel / CQT / MFCC

FeatureWhat it doesCommon options
melSpectrogramMel spectrogramframeSizeMs, hopSizeMs, fftSize, numMelFilters, minFrequency, maxFrequency, preEmphasis, power, logScale
cqtCQT (FFT-based approximation)frameSizeMs, hopSizeMs, fftSize, fMin, binsPerOctave, numBins, preEmphasis, power, logScale
mfccMFCC coefficientsframeSizeMs, hopSizeMs, fftSize, numMelFilters, numMfccCoeffs, minFrequency, maxFrequency, preEmphasis, lifterCoeff
mfccWithDeltaMFCC + delta + delta-deltaAll mfcc options + deltaWindowSize, computeDelta, computeDeltaDelta

Loudness / Voice / Dynamics

FeatureWhat it doesCommon options
lufsIntegrated/momentary/short-term/LRA/true-peak loudnesschannelMode, gated, calculateMomentary, calculateShortTerm, collectSeries, calculateLoudnessRange, calculateTruePeak, truePeakMethod, truePeakOversamplingFactor, truePeakInterpolation
vadVoice activity detectionmethod, frameSizeMs, hopSizeMs, energyThreshold, zcrThresholdLow, zcrThresholdHigh, adaptiveAlpha, noiseFactor, preEmphasis, smoothing
crestFactorCrest factor analysischannel, windowSize, hopSize, method

lufs.truePeakMethod defaults to bs1770 (polyphase FIR). In bs1770 mode, truePeakOversamplingFactor must be 2 or 4. lufs.momentary and lufs.shortTerm are scalar snapshots. For offline frame series, set collectSeries.

Stereo

FeatureWhat it doesCommon options
stereoCorrelation/width/balance/phase/ITD/ILDframeSize, hopSize, calculatePhase, calculateITD, calculateILD, provider, enableProfiling
timeVaryingStereoTime-varying stereo metricswindowSize + stereo options

Presets (Copy/Paste)

1) Lightweight meter

features: {
  rms: { asDB: true },
  peak: { asDB: true, truePeak: true }
}

2) Spectrum visualization

features: {
  spectrogram: {
    fftSize: 2048,
    frameSize: 2048,
    hopSize: 512,
    maxFrames: 120,
    minFrequency: 20,
    maxFrequency: 20000,
    scale: 'dbfs'
  }
}

3) Voice activity detection (VAD)

features: {
  vad: {
    method: 'adaptive',
    frameSizeMs: 25,
    hopSizeMs: 10,
    preEmphasis: true,
    smoothing: true
  }
}

4) Music-oriented bundle

features: {
  lufs: { calculateShortTerm: true, calculateTruePeak: true },
  spectralFeatures: true,
  mfccWithDelta: { numMfccCoeffs: 13, computeDelta: true, computeDeltaDelta: true },
  stereo: { calculatePhase: true }
}

LICENSE

MIT

Keywords

audio

FAQs

Package last updated on 09 Feb 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts