librosax.feature.spectral_flatness

spectral_flatness(*, y: Array | None = None, S: Array | None = None, n_fft: int = 2048, hop_length: int = 512, win_length: int | None = None, window: str = 'hann', center: bool = True, pad_mode: str = 'constant', amin: float = 1e-10, power: float = 2.0) Array[source]

Compute spectral flatness.

Spectral flatness (or tonality coefficient) is a measure to quantify how much noise-like a sound is, as opposed to being tone-like. A high spectral flatness (closer to 1.0) indicates the spectrum is similar to white noise. Users should ensure S is real-valued and non-negative.

Parameters:
  • y – Audio time series. Multichannel is supported.

  • S – (optional) Pre-computed spectrogram magnitude

  • n_fft – FFT window size

  • hop_length – Hop length for STFT

  • win_length – Window length

  • window – Window function

  • center – If True, pad the signal

  • pad_mode – Padding mode

  • amin – Minimum threshold for S (added noise floor for numerical stability)

  • power – Exponent for the magnitude spectrogram (e.g., 1 for energy, 2 for power)

Returns:

Spectral flatness for each frame [shape=(…, 1, t)]

Return type:

jnp.ndarray