librosa.feature.rmse¶
- librosa.feature.rmse(y=None, S=None, n_fft=2048, hop_length=512)¶
Compute root-mean-square (RMS) energy for each frame.
Parameters: y : np.ndarray [shape=(n,)] or None
audio time series
S : np.ndarray [shape=(d, t)] or None
(optional) spectrogram magnitude
n_fft : int > 0 [scalar]
FFT window size
hop_length : int > 0 [scalar]
hop length for STFT. See librosa.core.stft for details.
Returns: rms : np.ndarray [shape=(1, t)]
RMS value for each frame
Examples
>>> y, sr = librosa.load(librosa.util.example_audio_file()) >>> librosa.feature.rmse(y=y) array([[ 0. , 0.056, ..., 0. , 0. ]], dtype=float32)
Or from spectrogram input
>>> S, phase = librosa.magphase(librosa.stft(y)) >>> rms = librosa.feature.rmse(S=S)
>>> import matplotlib.pyplot as plt >>> plt.figure() >>> plt.subplot(2, 1, 1) >>> plt.semilogy(rms.T, label='RMS Energy') >>> plt.xticks([]) >>> plt.xlim([0, rms.shape[-1]]) >>> plt.legend(loc='best') >>> plt.subplot(2, 1, 2) >>> librosa.display.specshow(librosa.logamplitude(S**2, ref_power=np.max), ... y_axis='log', x_axis='time') >>> plt.title('log Power spectrogram') >>> plt.tight_layout()