JavaScript/TypeScript Feature Extraction API
Every function over audio takes either (samples, sampleRate, options?) or one request object ({ samples, sampleRate, ...options }). sampleRate has no default and is required, and a key a request does not declare is refused with a TypeError. The blocks on this page are taken from the type declarations of the WASM package (@libraz/libsonare); the Node package declares the same fields. Both packages accept intervals as Int32Array | ArrayLike<number> for remix and remixAlignedIntervals. A function with no positional form says so ("request form only"). Matrix2D is { data: Float32Array, rows: number, cols: number }, row-major, so a matrix of nBins bins by nFrames frames has rows = nBins and cols = nFrames.
Stem separation and aligned remixing are on Stems and Remix API; pitch detection and the note and struck-sound calls are on Pitch and Notes API.
Feature Extraction
stft(samples, sampleRate, options?) Medium
Compute the Short-Time Fourier Transform. For what the frames, bins and window size mean, see Spectrogram and STFT.
function stft(request: StftRequest): StftResult
function stft(
samples: Float32Array,
sampleRate: number,
options?: OptionsOf<StftRequest>,
): StftResult
interface StftRequest {
samples: Float32Array; // Mono audio samples.
sampleRate: number; // Sample rate of `samples` in Hz.
nFft?: number; // FFT size. Default 2048.
hopLength?: number; // Hop in samples. Default 512.
db?: boolean; // When true the result also carries `db`, the magnitude in decibels. Default false.
phase?: boolean; // When true the result also carries `phase` in radians. Default false.
}
interface StftResult {
nFft: number; // FFT size in samples.
hopLength: number; // Hop length in samples of the analysis.
sampleRate: number; // Sample rate in Hz of the analysed audio.
magnitude: Matrix2D; // Rows are `nFft / 2 + 1` bins, cols are frames.
power: Matrix2D; // Rows are `nFft / 2 + 1` bins, cols are frames.
db?: Matrix2D; // Magnitude in decibels, rows are bins and cols are frames; present only when `db` was requested.
phase?: Matrix2D; // Phase in radians, rows are bins and cols are frames; present only when `phase` was requested.
}melSpectrogram(samples, sampleRate, options?) Medium
Compute a Mel spectrogram, a frequency representation spaced to match human pitch perception. See Mel, MFCC and timbre. To paint the result on a canvas from a file a visitor picks, follow Draw a Mel Spectrogram in the Browser.
function melSpectrogram(request: MelSpectrogramRequest): MelSpectrogramResult
function melSpectrogram(
samples: Float32Array,
sampleRate: number,
options?: OptionsOf<MelSpectrogramRequest>,
): MelSpectrogramResult
interface MelSpectrogramRequest {
samples: Float32Array; // Mono audio samples.
sampleRate: number; // Sample rate of `samples` in Hz.
nFft?: number; // FFT size. Default 2048.
hopLength?: number; // Hop in samples. Default 512.
nMels?: number; // Mel bands. Default 128.
fminHz?: number; // Lowest band edge in Hz. Default 0.
fmaxHz?: number; // Highest band edge in Hz. Omit to use Nyquist; a supplied value must be positive and at most Nyquist.
htk?: boolean; // Use the HTK mel formula instead of Slaney. Default `false`.
}
interface MelSpectrogramResult {
sampleRate: number; // Sample rate in Hz of the analysed audio.
hopLength: number; // Hop length in samples of the analysis.
nFft: number; // FFT size of the source STFT.
fminHz: number; // Lower Mel band edge in Hz as applied.
fmaxHz: number; // Upper Mel band edge in Hz as applied: the Nyquist when the request left it at 0.
htk: boolean; // `true` for the HTK Mel formula, `false` for Slaney.
power: Matrix2D; // Linear power; rows are mel bands, cols are frames.
db: Matrix2D; // The dB form of `power`; rows are mel bands, cols are frames.
}The result carries the parameters of its forward transform, so they can be handed to the inverse helpers unchanged: melToStft({ power: mel.power, sampleRate: mel.sampleRate, nFft: mel.nFft, fminHz: mel.fminHz, fmaxHz: mel.fmaxHz, htk: mel.htk }) (see Inverse Features). power and db are Matrix2D ({ data, rows, cols }), so the band and frame counts are rows and cols.
melFrequencies(request) and melFilterbank(request)
The mel scale itself, without any audio. melFrequencies returns points in Hz evenly spaced on the mel scale, both ends included, which is what labels the rows of a mel spectrogram: band r of an nMels-band spectrogram rises from point r of melFrequencies({ nMels: nMels + 2, fminHz, fmaxHz, htk }), peaks at point r + 1 and falls to point r + 2. Its fmaxHz defaults to 11025 Hz, since it takes no sample rate, so pass the Nyquist when matching a spectrogram's defaults. melFilterbank returns the filters as a matrix, rows = bands and cols = the nFft / 2 + 1 FFT bins, for applying the bank to a power spectrum of your own. Draw a Mel Spectrogram in the Browser labels its rows this way.
function melFrequencies(request: MelFrequenciesRequest): Float32Array
interface MelFrequenciesRequest {
nMels?: number; // Number of points, at least 1. Default 128.
fminHz?: number; // First point in Hz. Default 0.
fmaxHz?: number; // Last point in Hz; greater than `fminHz`. Default 11025.
htk?: boolean; // HTK mel formula instead of Slaney. Default false.
}
function melFilterbank(request: MelFilterbankRequest): Matrix2D
interface MelFilterbankRequest {
sampleRate: number; // Sample rate in Hz the spectrum was taken at.
nFft: number; // FFT size; the filterbank spans its `nFft / 2 + 1` bins.
nMels?: number; // Number of bands, in [1, 4096]. Default 128.
fminHz?: number; // Lower edge of the lowest band in Hz. Default 0.
fmaxHz?: number; // Upper edge of the highest band in Hz. Absent means the Nyquist; when given it must be greater than 0 and at most the Nyquist.
htk?: boolean; // HTK mel formula instead of Slaney. Default false.
norm?: MelNorm; // Band weighting. Default `'slaney'`.
}mfcc(samples, sampleRate, options?) Medium
Use a finite, nonnegative lifter for forward and inverse MFCC. Zero disables liftering. Inverse MFCC also refuses a negative value that rounds to zero in float32.
Compute MFCC (Mel-Frequency Cepstral Coefficients), a compact representation of the spectral envelope. See Mel, MFCC and timbre.
function mfcc(request: MfccRequest): MfccResult
function mfcc(
samples: Float32Array,
sampleRate: number,
options?: OptionsOf<MfccRequest>,
): MfccResult
interface MfccRequest {
samples: Float32Array; // Mono audio samples.
sampleRate: number; // Sample rate of `samples` in Hz.
nFft?: number; // FFT size. Default 2048.
hopLength?: number; // Hop in samples. Default 512.
nMels?: number; // Mel bands. Default 128.
fminHz?: number; // Lowest band edge in Hz. Default 0.
fmaxHz?: number; // Highest band edge in Hz. Omit to use Nyquist; a supplied value must be positive and at most Nyquist.
htk?: boolean; // Use the HTK mel formula instead of Slaney. Default `false`.
nMfcc?: number; // Coefficients kept. Default 20.
lifter?: number; // Finite, nonnegative cepstral lifter. Zero means no liftering.
}
interface MfccResult {
sampleRate: number; // Sample rate in Hz of the analysed audio.
hopLength: number; // Hop length in samples of the analysis.
nFft: number; // FFT size in samples of the source STFT.
nMels: number; // Mel bands the coefficients were taken from.
fminHz: number; // Lower Mel band edge in Hz as applied.
fmaxHz: number; // Upper Mel band edge in Hz as applied: the Nyquist when the request left it at 0.
htk: boolean; // `true` for the HTK Mel formula, `false` for Slaney.
lifter: number; // Cepstral lifter applied to the coefficients; 0 means none.
coefficients: Matrix2D; // Rows are coefficients, cols are frames.
}Set fminHz/fmaxHz to bound the Mel band edges, and pass htk: true to use the HTK Mel formula instead of Slaney. lifter matches librosa's lifter argument (cepstral/sinusoidal liftering that de-emphasizes higher cepstral coefficients); 0 disables liftering. The inverse helpers (melToStft, melToAudio, mfccToMel, mfccToAudio) take matching fminHz/fmaxHz/htk fields, which the forward result carries, so a round-trip stays consistent when you pass them on.
chroma(samples, sampleRate, options?) Medium
Compute a chromagram (pitch class distribution). Maps all frequencies to 12 pitch classes (C, C#, D, ..., B). See Chroma features.
function chroma(request: ChromaRequest): ChromaResult
function chroma(
samples: Float32Array,
sampleRate: number,
options?: OptionsOf<ChromaRequest>,
): ChromaResult
interface ChromaRequest {
samples: Float32Array; // Mono audio samples.
sampleRate: number; // Sample rate of `samples` in Hz.
nFft?: number; // FFT size. Default 2048.
hopLength?: number; // Hop in samples. Default 512.
}
interface ChromaResult {
sampleRate: number; // Sample rate in Hz of the analysed audio.
hopLength: number; // Hop length in samples of the analysis.
features: Matrix2D; // Rows are chroma bins, cols are frames.
meanEnergy: number[]; // Mean energy of each chroma bin over all frames.
}Spectral Features
function spectralCentroid(request: SpectralCentroidRequest): Float32Array
function spectralCentroid(
samples: Float32Array,
sampleRate: number,
options?: OptionsOf<SpectralCentroidRequest>,
): Float32Array
interface SpectralCentroidRequest {
samples: Float32Array; // Mono audio samples.
sampleRate: number; // Sample rate of `samples` in Hz.
nFft?: number; // FFT size. Default 2048.
hopLength?: number; // Hop in samples. Default 512.
}
function spectralBandwidth(request: SpectralBandwidthRequest): Float32Array
function spectralBandwidth(
samples: Float32Array,
sampleRate: number,
options?: OptionsOf<SpectralBandwidthRequest>,
): Float32Array
interface SpectralBandwidthRequest {
samples: Float32Array; // Mono audio samples.
sampleRate: number; // Sample rate of `samples` in Hz.
nFft?: number; // FFT size. Default 2048.
hopLength?: number; // Hop in samples. Default 512.
p?: number; // Norm exponent. Default 2.
}
function spectralRolloff(request: SpectralRolloffRequest): Float32Array
function spectralRolloff(
samples: Float32Array,
sampleRate: number,
options?: OptionsOf<SpectralRolloffRequest>,
): Float32Array
interface SpectralRolloffRequest {
samples: Float32Array; // Mono audio samples.
sampleRate: number; // Sample rate of `samples` in Hz.
nFft?: number; // FFT size. Default 2048.
hopLength?: number; // Hop in samples. Default 512.
rollPercent?: number; // Energy fraction below the rolloff frequency. Default 0.85.
}
function spectralFlatness(request: SpectralFlatnessRequest): Float32Array
function spectralFlatness(
samples: Float32Array,
sampleRate: number,
options?: OptionsOf<SpectralFlatnessRequest>,
): Float32Array
interface SpectralFlatnessRequest {
samples: Float32Array; // Mono audio samples.
sampleRate: number; // Sample rate of `samples` in Hz.
nFft?: number; // FFT size. Default 2048.
hopLength?: number; // Hop in samples. Default 512.
}
function spectralContrast(request: SpectralContrastRequest): Matrix2D
function spectralContrast(
samples: Float32Array,
sampleRate: number,
options?: OptionsOf<SpectralContrastRequest>,
): Matrix2D
interface SpectralContrastRequest {
samples: Float32Array; // Mono audio samples.
sampleRate: number; // Sample rate of `samples` in Hz.
nFft?: number; // FFT size. Default 2048.
hopLength?: number; // Hop in samples. Default 512.
nBands?: number; // Contrast bands above the lowest. Default 6.
fminHz?: number; // Upper edge of the lowest band, in Hz. Default 200.
quantile?: number; // Quantile separating peaks from valleys. Default 0.02.
}
function polyFeatures(request: PolyFeaturesRequest): Matrix2D
function polyFeatures(
samples: Float32Array,
sampleRate: number,
options?: OptionsOf<PolyFeaturesRequest>,
): Matrix2D
interface PolyFeaturesRequest {
samples: Float32Array; // Mono audio samples.
sampleRate: number; // Sample rate of `samples` in Hz.
nFft?: number; // FFT size. Default 2048.
hopLength?: number; // Hop in samples. Default 512.
order?: number; // Polynomial order. Default 1.
}
function zeroCrossingRate(request: ZeroCrossingRateRequest): Float32Array
function zeroCrossingRate(
samples: Float32Array,
sampleRate: number,
options?: OptionsOf<ZeroCrossingRateRequest>,
): Float32Array
interface ZeroCrossingRateRequest {
samples: Float32Array; // Mono audio samples.
sampleRate: number; // Sample rate of `samples` in Hz.
frameLength?: number; // Frame length in samples. Default 2048.
hopLength?: number; // Hop in samples. Default 512.
}
function zeroCrossings(request: ZeroCrossingsRequest): Int32Array
function zeroCrossings(
samples: Float32Array,
sampleRate: number,
options?: OptionsOf<ZeroCrossingsRequest>,
): Int32Array
interface ZeroCrossingsRequest {
samples: Float32Array; // Mono audio samples.
sampleRate: number; // Audio sample rate in Hz, an integer in [8000, 384000]; required for the shared call shape, not read by the computation.
threshold?: number; // Magnitude below which a sample counts as zero. Default 1e-10.
refMagnitude?: boolean; // Scale `threshold` by the maximum absolute sample. Default `false`.
pad?: boolean; // Report index 0 as a crossing when the input has samples. Default `true`.
zeroPos?: boolean; // Treat the sign of zero as positive. Default `true`.
}
function rmsEnergy(request: RmsEnergyRequest): Float32Array
function rmsEnergy(
samples: Float32Array,
sampleRate: number,
options?: OptionsOf<RmsEnergyRequest>,
): Float32Array
interface RmsEnergyRequest {
samples: Float32Array; // Mono audio samples.
sampleRate: number; // Sample rate of `samples` in Hz.
frameLength?: number; // Frame length in samples. Default 2048.
hopLength?: number; // Hop in samples. Default 512.
}biquadFilter(request)
Filters mono audio with a Butterworth high-pass or low-pass (order 2 or 4), or a band-pass or notch biquad. It is request form only. type picks the response, and a frequency field the type does not read must be omitted: cutoffHz for highPass / lowPass, centerHz and bandwidthHz for bandPass / notch. zeroPhase: true runs the filter forward and backward for no phase shift. The result has the input's length.
function biquadFilter(request: BiquadFilterRequest): Float32Array
interface BiquadFilterRequest {
samples: Float32Array; // Mono audio samples.
sampleRate: number; // Sample rate in Hz, an integer in `[8000, 384000]`; there is no default.
type: BiquadFilterType; // Filter response.
order?: number; // 2, or 4 for `highPass` / `lowPass` (a two-section cascade). Default 2.
zeroPhase?: boolean; // Run the filter forward and backward for zero phase shift. Default `false`.
cutoffHz?: number; // Corner in Hz inside `(0, sampleRate / 2)`; `highPass` / `lowPass` only.
centerHz?: number; // Center in Hz inside `(0, sampleRate / 2)`; `bandPass` / `notch` only.
bandwidthHz?: number; // Bandwidth in Hz, above 0; `bandPass` / `notch` only.
}Waveform Peaks WASM/Node
Per-channel min/max buckets for drawing a waveform overview without shipping the full sample array to the UI. Both functions take one channels array (one Float32Array per channel, equal lengths) and are request form only. samplesPerBucket sets the bucket width (default 512); waveformPeakPyramid returns one report per zoom level.
function waveformPeaks(request: WaveformPeaksRequest): WaveformPeaksReport
function waveformPeakPyramid(request: WaveformPeakPyramidRequest): WaveformPeaksReport[]
interface WaveformPeaksRequest {
channels: Float32Array[]; // One `Float32Array` per channel, equal lengths.
samplesPerBucket?: number; // Bucket width in samples. Default 512.
}
interface WaveformPeakPyramidRequest {
channels: Float32Array[]; // One `Float32Array` per channel, equal lengths.
samplesPerBucketLevels?: number[]; // Bucket widths in samples, one per zoom level. Default [512, 1024, 2048, 4096].
}
interface WaveformPeaksReport {
min: Float32Array[]; // Per-channel bucket minima: `min[c]` holds `bucketCount` values.
max: Float32Array[]; // Per-channel bucket maxima: `max[c]` holds `bucketCount` values.
bucketCount: number; // Number of buckets per channel.
samplesPerBucket: number; // Bucket width in samples.
}CQT, VQT, NNLS chroma, inverse features, and loudness
These functions are not just "more features"; they solve different modeling problems:
| Need | Use | Why |
|---|---|---|
| Log-frequency pitch representation | cqt(...), pseudoCqt(...), hybridCqt(...) | Constant-Q bins align well with musical pitch over octaves; pseudo/hybrid variants trade accuracy and speed across bins. |
| Variable bandwidth pitch representation | vqt(...) | Like CQT, but with a bandwidth offset for low-frequency stability. Omit gamma for the automatic ERB-derived bandwidth; gamma: 0 is equivalent to CQT. A negative or non-finite gamma, NaN included, throws RangeError, so leave it out rather than passing NaN. |
| Chord-friendly chroma | chromaCqt(...), nnlsChroma(...), chromaCens(...), bassChroma(...) | Constant-Q, NNLS, CENS, and low-register chroma variants can be cleaner for chord or bass-register work than plain STFT chroma. |
| Spectral shape detail | spectralContrast(...), polyFeatures(...), zeroCrossings(...), onsetStrengthMulti(...) | Librosa-compatible contrast bands, polynomial coefficients, zero-crossing indices, and multi-band onset strength. |
| Pitch/tuning offset | pitchTuning(...), estimateTuning(...) | Estimate the global tuning offset, in cents, from detected frequencies (pitchTuning({ frequencies }), request form only) or directly from audio (estimateTuning); at 12 bins per octave the value lies in [-50, 50), the unit of the analysis options' tuningCents; tuningToReferenceHz(...) and referenceHzToTuning(...) convert it to and from a reference pitch in Hz. |
| Decomposition and remixing | decompose(...), decomposeStems(...), decomposeStemsLinked(...), nnFilter(...), remix(...), remixAlignedIntervals(...), phaseVocoder(...), hpss({ ..., withResidual: true }) | NMF factorization, selectable NMF initialization, mono and linked multichannel stem output, nearest-neighbor filtering, interval remixing, channel-consistent cut points, time scaling, and HPSS residual output. |
| Reconstruct approximate audio/features | melToStft, melToAudio, mfccToMel, mfccToAudio, cqtToAudio, vqtToAudio | Griffin-Lim based inverse paths for visualization, debugging, and feature round-trips. CQT/VQT inputs are magnitude matrices. |
| Delivery loudness measurements | lufs, lufsMultichannel, momentaryLufs, shortTermLufs, ebur128LoudnessRangeLu | ITU-R BS.1770 / EBU R128 style loudness values, including multichannel integrated loudness and LRA (loudness range: how much the loudness varies over the program). See LUFS. |
const cqtResult = cqt(samples, sampleRate, { hopLength: 512, fminHz: 32.7, nBins: 84, binsPerOctave: 12 });
const vqtResult = vqt({ samples, sampleRate, hopLength: 512, fminHz: 32.7, nBins: 84, binsPerOctave: 12 });
const pseudo = pseudoCqt(samples, sampleRate);
const hybrid = hybridCqt(samples, sampleRate);
const cqtChroma = chromaCqt(samples, sampleRate);
const nnls = nnlsChroma(samples, sampleRate, { hopLength: 512 }); // a Matrix2D
const cens = chromaCens(samples, sampleRate);
const bass = bassChroma(samples, sampleRate);
const loudness = lufs(samples, sampleRate);
const contrast = spectralContrast(samples, sampleRate);
const poly = polyFeatures(samples, sampleRate);
const crossings = zeroCrossings(samples, sampleRate);
const onsetBands = onsetStrengthMulti(samples, sampleRate);
const tuning = estimateTuning(samples, sampleRate);
const offset = pitchTuning({ frequencies: pitch.f0 });
const { w, h } = decompose({ s: spectrogram, nComponents: 8 }); // spectrogram is a Matrix2D
const warmStarted = decompose({ s: spectrogram, nComponents: 8, nIter: 50, beta: 2.0, init: 'nndsvd' });
const filtered = nnFilter({ s: spectrogram });
const remixed = remix(samples, sampleRate, { intervals: Int32Array.from([0, sampleRate, sampleRate, 2 * sampleRate]) });
const stretched = phaseVocoder(samples, sampleRate, { speedRatio: 1.5 });
const hpssResidual = hpss({ samples, sampleRate, withResidual: true });
const multichannel = lufsMultichannel({ channels: [left, right], sampleRate });
const lra = ebur128LoudnessRangeLu(samples, sampleRate);
const reconstructed = melToAudio({ power: mel.power, sampleRate: mel.sampleRate, nFft: mel.nFft, hopLength: mel.hopLength, fminHz: mel.fminHz, fmaxHz: mel.fmaxHz, htk: mel.htk });
const cqtPreview = cqtToAudio({ magnitude: cqtResult.magnitude, sampleRate, hopLength: 512, fminHz: 32.7, binsPerOctave: 12 });
const vqtPreview = vqtToAudio({
magnitude: vqtResult.magnitude,
sampleRate,
hopLength: 512,
fminHz: 32.7,
binsPerOctave: 12,
nIter: 32,
});chromaCqt(samples, sampleRate, { hopLength?, nChroma?, binsPerOctave? }) is the direct librosa.feature.chroma_cqt equivalent (log-frequency / constant-Q pitch folding; chromaCens takes the same options, bassChroma takes hopLength and nChroma), while nnlsChroma(samples, sampleRate, options?) is a distinct note-activation chroma built on NNLS (non-negative least squares) that suppresses harmonic leakage, which is often cleaner for chord or bass-register work. It returns a Matrix2D, and its options are enableStftBlend, stftBlendWeight, stftBlendNFft and hopLength (default 512).
The request interfaces of the constant-Q family and its siblings:
Each request extends { samples: Float32Array; sampleRate: number }. cqt, vqt, pseudoCqt, hybridCqt, chromaCens, chromaCqt, bassChroma, nnlsChroma, onsetStrengthMulti, estimateTuning, phaseVocoder, lufs, momentaryLufs and shortTermLufs each take either the request or (samples, sampleRate, options?); phaseVocoder's options are required (speedRatio). pitchTuning, decompose, nnFilter and lufsMultichannel take the request form only. lufs(...) always returns integratedLufs; momentary and short-term readings are absent unless a complete 400 ms or 3 s window fits, Max-M and Max-S are absent if their windows do not fit, and loudnessRangeLu is absent for silence or when no 3 s block passes the gates. Check these optional readings before using them.
interface CqtRequest extends SampleInput {
hopLength?: number; // Hop length in samples; default 512.
fminHz?: number; // Lowest bin frequency in Hz; default 32.70319566257483 (C1).
nBins?: number; // Number of frequency bins; default 84.
binsPerOctave?: number; // Bins per octave; default 12.
filterScale?: number; // Filter length scale factor, finite and greater than 0; default 1 (librosa's).
}
interface VqtRequest extends CqtRequest {
gamma?: number; // Bandwidth offset; omit for the automatic ERB-derived value, 0 is equivalent to CQT.
}
interface PseudoCqtRequest extends CqtRequest {}
interface HybridCqtRequest extends CqtRequest {}
interface ChromaCensRequest {
samples: Float32Array; // Mono audio samples.
sampleRate: number; // Sample rate of `samples` in Hz.
hopLength?: number; // Hop in samples. Default 512.
nChroma?: number; // Chroma bins. Default 12.
binsPerOctave?: number; // Constant-Q bins per octave; a multiple of `nChroma`. Default 36.
}
interface ChromaCqtRequest {
samples: Float32Array; // Mono audio samples.
sampleRate: number; // Sample rate of `samples` in Hz.
hopLength?: number; // Hop in samples. Default 512.
nChroma?: number; // Chroma bins. Default 12.
binsPerOctave?: number; // Constant-Q bins per octave; a multiple of `nChroma`. Default 36.
}
interface BassChromaRequest {
samples: Float32Array; // Mono audio samples.
sampleRate: number; // Sample rate of `samples` in Hz.
hopLength?: number; // Hop in samples. Default 512.
nChroma?: number; // Chroma bins. Default 12.
}
interface NnlsChromaRequest extends SampleInput {
enableStftBlend?: boolean; // Blend an STFT chroma into the NNLS chroma. Default `true`.
stftBlendWeight?: number; // Weight of the blended STFT chroma. Default `0.55`.
stftBlendNFft?: number; // FFT size in samples of the blended STFT chroma. Default `4096`.
hopLength?: number; // Hop length in samples. Default `512`.
}
interface OnsetStrengthRequest extends SampleInput {
nFft?: number; // FFT size in samples. Default `2048`.
hopLength?: number; // Hop length in samples. Default `512`.
nMels?: number; // Mel bands the flux is taken over. Default `128`.
}
interface OnsetStrengthMultiRequest extends OnsetStrengthRequest {
nBands?: number; // Number of onset bands; default 3.
}
interface EstimateTuningRequest {
samples: Float32Array; // Mono audio samples.
sampleRate: number; // Sample rate of `samples` in Hz.
resolution?: number; // Resolution of the search, as a fraction of a bin. Default 0.01.
binsPerOctave?: number; // Bins per octave the offset is measured in. Default 12.
nFft?: number; // FFT size. Default 2048.
hopLength?: number; // Hop in samples. Default 512.
}
interface PitchTuningRequest {
frequencies: Float32Array; // Frequencies in Hz to estimate the tuning offset from.
resolution?: number; // Resolution of the search, as a fraction of a bin. Default 0.01.
binsPerOctave?: number; // Bins per octave the offset is measured in. Default 12.
}
interface DecomposeRequest {
s: Matrix2D; // Non-negative spectrogram: rows are features, cols are frames.
nComponents: number; // Number of NMF components, a positive integer.
nIter?: number; // Multiplicative-update iterations, a positive integer. Default 50.
beta?: number; // Beta divergence: 2 = Frobenius (default), 1 = Kullback-Leibler.
init?: NmfInit; // Initialisation, `'random'` (default, deterministic seed) or `'nndsvd'`.
}
interface DecomposeResult {
w: Matrix2D; // Component matrix: rows are features, cols are components.
h: Matrix2D; // Activation matrix: rows are components, cols are frames.
}
interface NnFilterRequest {
s: Matrix2D; // Spectrogram to filter: rows are features, cols are frames.
aggregate?: NnFilterAggregate; // Neighbour aggregation. Default `'mean'`.
k?: number; // Neighbours per frame, a positive integer. Default 7.
width?: number; // Frames either side of a frame excluded from its neighbours, a non-negative integer. Default 1.
}
interface PhaseVocoderRequest {
samples: Float32Array; // Mono audio samples.
sampleRate: number; // Sample rate in Hz, an integer in `[8000, 384000]`; there is no default.
speedRatio: number; // Playback speed as a ratio, finite: above 1 is faster and shorter, below 1 slower and longer, the opposite sense of a note's `stretchRatio`. Required.
nFft?: number; // FFT size: an even integer in `[4, 2147483646]`. Default 2048.
hopLength?: number; // Hop in samples, in `(0, nFft / 2]`. Default `nFft / 4`, rounded down.
}
interface LufsMultichannelRequest {
channels: Float32Array[]; // One `Float32Array` per channel, equal lengths.
sampleRate: number; // Sample rate of the channels in Hz. Required.
}
interface CqtResult {
hopLength: number; // Hop length in samples.
sampleRate: number; // Sample rate in Hz.
magnitude: Matrix2D; // Rows are CQT bins, cols are frames.
frequencies: Float32Array; // Center frequency (Hz) of each of the `nBins` bins.
gamma: number; // Bandwidth offset in Hz the transform ran with: for `vqt`, the resolved value (the ERB-derived one when `gamma` was omitted); 0 for the three constant-Q transforms.
}
interface LufsResult {
integratedLufs: number; // Integrated loudness over the whole signal, in LUFS. `-Infinity` when nothing passes the gate. Never absent: the integrated measurement clamps to the input.
momentaryLufs?: number; // Final complete 400 ms window, not Max-M. `-Infinity` for zero energy; absent when the signal is shorter than one window.
shortTermLufs?: number; // Final complete 3 s window, not Max-S. `-Infinity` for zero energy; absent when the signal is shorter than one window (a 1 s signal has no short-term reading).
maxMomentaryLufs?: number; // Maximum 400 ms window (EBU R128 Max-M). `-Infinity` for zero energy; absent when the signal is shorter than one window.
maxShortTermLufs?: number; // Maximum 3 s window (EBU R128 Max-S). `-Infinity` for zero energy; absent when the signal is shorter than one window.
loudnessRangeLu?: number; // Loudness range in LU. Absent for silence and when no 3 s block passes the gates: a spread, not a level, so never `-Infinity`.
}Closest CLI equivalents. All of these exist in both the Python and the C++ CLI.
sonare nnls-chroma song.wav
sonare lufs song.wav --json
sonare cqt song.wav
sonare vqt song.wav
sonare mel-to-audio song.wav -o mel-preview.wavInverse reconstruction
The WASM build ships the inverse reconstruction helpers, so you can go from a mel spectrogram or MFCC matrix back to a spectrum or audio entirely in the browser. The processing flow, the round-trip recipe and the CLI equivalents (sonare mel-to-audio, sonare mfcc-to-audio) are on Inverse Features.
| Function | Returns | Notes |
|---|---|---|
melToStft({ power, sampleRate?, nFft?, fminHz?, fmaxHz?, htk? }) | Matrix2D of magnitudes (rows are bins, cols are frames) | Pseudo-inverse of the mel filterbank |
melToAudio({ power, sampleRate?, nFft?, hopLength?, fminHz?, fmaxHz?, nIter?, htk? }) | Float32Array | Griffin-Lim audio synthesis |
mfccToMel({ coefficients, nMels?, lifter? }) | Matrix2D of mel power (rows are mel bands, cols are frames) | Inverse DCT back to a mel spectrogram; pass the forward MFCC lifter |
mfccToAudio({ coefficients, nMels?, sampleRate?, nFft?, hopLength?, fminHz?, fmaxHz?, nIter?, htk?, lifter? }) | Float32Array | MFCC → mel → audio in one call; pass the forward MFCC lifter |
Lossy round-trip. These reconstruct magnitude and estimate phase with Griffin-Lim, so the output is an approximation — fine for sonification, audition, and visualization, not for bit-exact recovery. See Inverse Features for the processing flow and caveats.