librosa.envelope#

librosa.envelope(y, *, frame_length=2048, hop_length=512, kind='max', mode='reflect', center=True, percentile=100.0, axis=-1)[source]#

Compute a time-domain amplitude envelope using 1D filtering operations.

Parameters:
ynp.ndarray

Audio time series. Multi-channel is supported.

frame_lengthint > 0

The size of the filtering window in samples.

hop_lengthint > 0

The number of samples to advance between decimated output samples.

kindstr

The type of filtering operation: - 'max' : maximum filter - 'max_abs': maximum of absolute value - 'min' : minimum filter - 'median' : median filter - 'percentile' : percentile filter (using percentile argument)

modestr

Padding mode passed to scipy.ndimage filter functions (e.g. 'reflect', 'constant', 'nearest', 'mirror', 'wrap').

centerbool

If True, the filtering window is centered on each sample. If False, the window is left-aligned.

percentilefloat

Percentile value (between 0 and 100) used when kind='percentile'.

axisint

Axis along which to compute the envelope.

Returns:
y_envnp.ndarray

Decimated amplitude envelope computed along axis.

Raises:
ParameterShapeError
  • If y is not valid audio.

ParameterValueError
  • If frame_length or hop_length are not positive integers.

  • If kind is unrecognized.

Notes

This function caches at level 20.

Examples

>>> y, sr = librosa.loadx("trumpet")
>>> env = librosa.envelope(y, frame_length=2048, hop_length=512, kind="max")
>>> env.shape
(230,)