Skip to content

Python Metering and Signal Helpers API ​

Level and stereo metering functions, plus signal and framing helpers: pre-emphasis, silence trimming and splitting, framing and padding, peak picking, normalization, and tempogram functions. Feature extraction is on Python Feature Extraction API, the effects functions on Python Effects API, and installation, quick start, and the other API families on the Python API index.

Metering Functions ​

Standalone level, dynamics, and stereo-image meters. Non-finite input is refused. The stereo meters require left and right to be equal length, and sample_rate is required.

python
# Sample-peak in dBFS over the buffer.
def metering_peak_db(samples: Sequence[float] | list[float], sample_rate: int) -> float: ...

# RMS level in dBFS over the buffer.
def metering_rms_db(samples: Sequence[float] | list[float], sample_rate: int) -> float: ...

# Crest factor in dB (peak_db - rms_db); ``None`` for silence.
def metering_crest_factor_db(
    samples: Sequence[float] | list[float],
    sample_rate: int,
) -> float | None: ...

# Crest factor in dB across both channels of a stereo pair; ``None`` for silence.
def metering_crest_factor_db_stereo(
    left: Sequence[float] | list[float],
    right: Sequence[float] | list[float],
    sample_rate: int,
) -> float | None: ...

# DC offset (mean) of the buffer in linear amplitude.
def metering_dc_offset(samples: Sequence[float] | list[float], sample_rate: int) -> float: ...

# Fraction of analysis frames whose RMS is below ``threshold_db``.
def metering_silence_ratio(
    samples: Sequence[float] | list[float],
    sample_rate: int,
    threshold_db: float = -45.0,
    frame_length: int = 1024,
    hop_length: int = 256,
) -> float: ...

# Inter-sample (true) peak in dBFS.
def metering_true_peak_dbtp(
    samples: Sequence[float] | list[float],
    sample_rate: int,
    oversample_factor: int | None = None,
) -> float: ...

# Detect contiguous runs of clipped samples.
def metering_detect_clipping(
    samples: Sequence[float] | list[float],
    sample_rate: int,
    threshold_db: float | None = None,
    min_region_samples: int | None = None,
) -> ClippingReport: ...

# Sliding-window dynamic range for mono audio (high_percentile - low_percentile, in dB).
def metering_dynamic_range(
    samples: Sequence[float] | list[float],
    sample_rate: int,
    window_sec: float | None = None,
    hop_sec: float | None = None,
    low_percentile: float | None = None,
    high_percentile: float | None = None,
) -> DynamicRangeReport: ...

# Uncentered correlation (cosine similarity) between equal-length channels.
def metering_stereo_correlation(
    left: Sequence[float] | list[float],
    right: Sequence[float] | list[float],
    sample_rate: int,
) -> float | None: ...

# Stereo width as ``sqrt(side_energy / mid_energy)``.
def metering_stereo_width(
    left: Sequence[float] | list[float],
    right: Sequence[float] | list[float],
    sample_rate: int,
) -> float | None: ...

# Mid/side point series for a (left, right) stereo pair.
def metering_vectorscope(
    left: Sequence[float] | list[float],
    right: Sequence[float] | list[float],
    sample_rate: int,
    max_points: int | None = None,
) -> VectorscopeReport: ...

# Phase-scope point series plus summary stats for a stereo pair.
def metering_phase_scope(
    left: Sequence[float] | list[float],
    right: Sequence[float] | list[float],
    sample_rate: int,
    max_points: int | None = None,
) -> PhaseScopeReport: ...

# Welch-averaged magnitude / power / dB spectrum over a whole mono buffer.
def metering_spectrum(
    samples: Sequence[float] | list[float],
    sample_rate: int,
    n_fft: int | None = None,
    apply_octave_smoothing: bool = False,
    octave_fraction: int | None = None,
    db_ref: float | None = None,
    db_amin: float | None = None,
) -> SpectrumReport: ...

# True single-frame mono magnitude / power / dB spectrum (one Hann-windowed FFT).
def metering_spectrum_frame(
    samples: Sequence[float] | list[float],
    sample_rate: int,
    frame_offset: int = 0,
    n_fft: int | None = None,
    apply_octave_smoothing: bool = False,
    octave_fraction: int | None = None,
    db_ref: float | None = None,
    db_amin: float | None = None,
) -> SpectrumReport: ...
FunctionDescription
metering_peak_dbSample peak (dBFS)
metering_rms_dbRMS level (dBFS)
metering_crest_factor_dbCrest factor, peak − RMS (dB)
metering_crest_factor_db_stereoCrest factor measured across both channels — peak is the larger of the two, RMS is taken over both together
metering_dc_offsetMean (DC) offset, linear amplitude
metering_silence_ratioFraction of analysis frames whose RMS is below threshold_db (defaults: threshold_db=-45.0, frame_length=1024, hop_length=256)
metering_true_peak_dbtpInter-sample (true) peak in dBTP; oversample_factor is a power of two in 1..16, omitted for the default (4)
metering_detect_clippingClipped-sample runs; threshold_db is the level in dBFS a clipped sample reaches, in [-120, 0] (default: the level of a linear 0.999), min_region_samples default 1
metering_dynamic_rangeSliding-window dynamic range. Omit window_sec/hop_sec for the defaults (3 s / 1 s); an explicit 0 is refused. low_percentile/high_percentile are ranks in [0, 1], omitted they are 0.10 / 0.95, and 0.0 requests the minimum-RMS window
metering_stereo_correlationUncentered correlation (cosine similarity), −1..1
metering_stereo_widthMid/side stereo width
metering_vectorscopeMid/side point series; one point per sample unless max_points bounds it, in which case the series is deterministically decimated, keeping the largest-radius sample per bucket (a value at or above the buffer length keeps every sample)
metering_phase_scopePhase-scope (Lissajous) point series plus summary stats; max_points bounds the point cloud the same way, and the summary stats are always computed over the full-resolution signal
metering_spectrumWelch-averaged magnitude/power/dB spectrum over the whole buffer (Hann-windowed, 50%-overlapping n_fft frames; not a single-frame snapshot). Omit n_fft/octave_fraction/db_ref/db_amin for the defaults (2048 / 3 / 1.0 / floor); an explicit 0 is refused
metering_spectrum_frameTrue single-frame spectrum (one Hann-windowed FFT) spanning [frame_offset, frame_offset + n_fft), zero-padded past the end. Omit n_fft/octave_fraction/db_ref/db_amin for the defaults; an explicit 0 is refused

Prefer metering_crest_factor_db_stereo(...) over feeding a downmix to metering_crest_factor_db(...). A 0.5 * (left + right) downmix cancels an out-of-phase pair, which understates RMS and therefore overstates crest factor. An inverted sine pair reads 3.01 dB through the stereo meter, the crest factor of the signal itself, while the downmix is silent and has no crest factor to measure. Unequal channel lengths raise SonareValueError.

Signal and framing helpers ​

These mirror the corresponding librosa functions — see librosa Compatibility for the function each helper matches.

What each helper is for

  • preemphasis / deemphasis — classic one-tap IIR pre-processing that boosts (or undoes) high frequencies.
  • trim_silence / split_silence — trim leading/trailing silence or split on silent gaps.
  • frame_signal / pad_center / fix_length / fix_frames — framing and size-alignment utilities for fixed-frame DSP.
  • peak_pick / vector_normalize — peak detection on 1-D signals (e.g. onset envelopes) and vector-norm normalization.
  • pcen — dynamic range compression for mel spectrograms; features that are robust to gain and background noise.
  • tonnetz — projects chroma into a 6-D harmonic space for chord-relation and modulation analysis.
  • tempogram / plp — time-varying tempo representation from the onset envelope (autocorrelation or mode="cosine"), and the dominant local pulse on top.
  • fourier_tempogram / cyclic_tempogram / tempogram_ratio — the FFT-based tempogram, an octave-folded cyclic tempogram, and tempo-ratio features.
python
# Apply librosa-compatible pre-emphasis; returns a float32 array.
def preemphasis(
    samples: Sequence[float] | list[float],
    coef: float = 0.97,
    zi: float | None = None,
) -> np.ndarray: ...

# Apply inverse pre-emphasis; returns a float32 array.
def deemphasis(
    samples: Sequence[float] | list[float],
    coef: float = 0.97,
    zi: float | None = None,
) -> np.ndarray: ...
FunctionDescription
preemphasisPre-emphasis filter (librosa.effects.preemphasis)
deemphasisInverse pre-emphasis (librosa.effects.deemphasis)
python
# Trim leading/trailing silence and return a :class:`TrimResult`.
def trim_silence(
    samples: Sequence[float] | list[float],
    top_db: float = 60.0,
    frame_length: int = 2048,
    hop_length: int = 512,
) -> TrimResult: ...

# Return non-silent intervals as an int64 array of shape ``(n_intervals, 2)``.
def split_silence(
    samples: Sequence[float] | list[float],
    top_db: float = 60.0,
    frame_length: int = 2048,
    hop_length: int = 512,
) -> np.ndarray: ...

# Return the intervals where any of several takes of one part is sounding.
def split_silence_common(
    signals: Sequence[Sequence[float]],
    top_db: float = 60.0,
    frame_length: int = 2048,
    hop_length: int = 512,
) -> np.ndarray: ...

# Return what :func:`split_silence_common` returns, plus why.
def split_silence_common_with_report(
    signals: Sequence[Sequence[float]],
    top_db: float = 60.0,
    frame_length: int = 2048,
    hop_length: int = 512,
) -> SplitSilenceCommonWithReportResult: ...
FunctionDescription
trim_silencelibrosa.effects.trim — returns a TrimResult (.audio, .start_sample, .end_sample; it does not unpack)
split_silencelibrosa.effects.split — non-silent intervals as sample pairs
split_silence_commonThe cut points several takes of one part agree are silent. signals is one sequence of sequences, so the signal count and per-signal lengths cannot disagree
split_silence_common_with_reportThe same cut points plus a report with silence_ceiling_db, max_signal_intervals and min_signal_intervals
python
# Slice a signal into frames.
def frame_signal(
    samples: Sequence[float] | list[float],
    frame_length: int,
    hop_length: int,
) -> np.ndarray: ...

# Pad an array by centering it within target size; returns a float32 array.
def pad_center(
    values: Sequence[float] | list[float],
    target_size: int,
    pad_value: float = 0.0,
) -> np.ndarray: ...

# Crop or pad an array to exact length; returns a float32 array.
def fix_length(
    values: Sequence[float] | list[float],
    target_size: int,
    pad_value: float = 0.0,
) -> np.ndarray: ...

# Adjust frame indices to fit within bounds; returns an int32 array.
def fix_frames(
    frames: Sequence[int] | list[int],
    x_min: int = 0,
    x_max: int | None = None,
    pad: bool = True,
) -> np.ndarray: ...

# Pick peaks using librosa.util.peak_pick-compatible parameters.
def peak_pick(
    values: Sequence[float] | list[float],
    pre_max: int,
    post_max: int,
    pre_avg: int,
    post_avg: int,
    delta: float,
    wait: int,
) -> np.ndarray: ...

# Normalize a vector (float32 array) by its maximum magnitude, L1, L2 or power norm.
def vector_normalize(
    values: Sequence[float] | list[float],
    norm: NormType = 'max',
    threshold: float = 0.0,
) -> np.ndarray: ...
FunctionDescription
frame_signallibrosa.util.frame; returns shape (frame_length, n_frames)
pad_centerlibrosa.util.pad_center
fix_lengthlibrosa.util.fix_length
fix_frameslibrosa.util.fix_frames. x_max is the inclusive upper bound; omit it (None) for no upper bound — -1 is refused
peak_picklibrosa.util.peak_pick — returns peak indices
vector_normalizelibrosa.util.normalize. norm: "max" (default), "l1", "l2" or "power"
python
# Apply per-channel energy normalization to a spectrogram.
def pcen(
    values: npt.ArrayLike,
    sr: int = 22050,
    hop_length: int = 512,
    time_constant: float = 0.4,
    gain: float = 0.98,
    bias: float = 2.0,
    power: float = 0.5,
    eps: float = 1e-06,
) -> np.ndarray: ...

# Compute Tonnetz from a chromagram.
def tonnetz(chromagram: npt.ArrayLike) -> np.ndarray: ...
FunctionDescription
pcenlibrosa.pcen — input is a mel spectrogram of shape (n_bins, n_frames)
tonnetzlibrosa.feature.tonnetz — input (n_chroma, n_frames), returns (6, n_frames)
python
# Compute a tempogram as a float32 array of shape ``(win_length, n_frames)``.
def tempogram(
    onset_envelope: Sequence[float] | list[float],
    sr: int = 22050,
    hop_length: int = 512,
    win_length: int = 384,
    center: bool = True,
    norm: bool = True,
    mode: TempogramMode = 'autocorrelation',
) -> np.ndarray: ...

# Compute the Fourier (FFT-based) tempogram magnitude.
def fourier_tempogram(
    onset_envelope: Sequence[float] | list[float],
    sr: int = 22050,
    hop_length: int = 512,
    win_length: int = 384,
    center: bool = True,
) -> np.ndarray: ...

# Compute a cyclic tempogram as a float32 array of shape ``(n_bins, n_frames)``.
def cyclic_tempogram(
    onset_envelope: Sequence[float] | list[float],
    sample_rate: int,
    hop_length: int = 512,
    win_length: int = 384,
    bpm_min: float = 60.0,
    n_bins: int = 60,
) -> np.ndarray: ...

# Aggregate tempogram magnitudes at integer ratios of a reference tempo.
def tempogram_ratio(
    tempogram: npt.ArrayLike,
    sr: int = 22050,
    hop_length: int = 512,
    factors: Sequence[float] | list[float] | None = None,
) -> np.ndarray: ...

# Compute predominant local pulse from an onset envelope (float32, one value per frame).
def plp(
    onset_envelope: Sequence[float] | list[float],
    sr: int = 22050,
    hop_length: int = 512,
    tempo_min: float | None = None,
    tempo_max: float | None = None,
    win_length: int = 384,
) -> np.ndarray: ...
FunctionDescription
tempogramlibrosa.feature.tempogram. mode: "autocorrelation" (default) or "cosine"
fourier_tempogramFFT-based tempogram — STFT of the onset envelope
cyclic_tempogramOctave-folded cyclic tempogram
tempogram_ratioTempo-ratio features from a tempogram
plplibrosa.beat.plp — predominant local pulse