librosa.beat.estimate_tempo¶
-
librosa.beat.
estimate_tempo
(onset_envelope, sr=22050, hop_length=512, start_bpm=120, std_bpm=1.0, ac_size=4.0, duration=90.0, offset=0.0)[source]¶ Estimate the tempo (beats per minute) from an onset envelope
Parameters: onset_envelope : np.ndarray [shape=(n,)]
onset strength envelope
sr : number > 0 [scalar]
sampling rate of the time series
hop_length : int > 0 [scalar]
hop length of the time series
start_bpm : float [scalar]
initial guess of the BPM
std_bpm : float > 0 [scalar]
standard deviation of tempo distribution
ac_size : float > 0 [scalar]
length (in seconds) of the auto-correlation window
duration : float > 0 [scalar]
length of signal (in seconds) to use in estimating tempo
offset : float > 0 [scalar]
offset (in seconds) of signal sample to use in estimating tempo
Returns: tempo : float [scalar]
estimated tempo (beats per minute)
See also
Examples
>>> y, sr = librosa.load(librosa.util.example_audio_file()) >>> onset_env = librosa.onset.onset_strength(y, sr=sr) >>> tempo = librosa.beat.estimate_tempo(onset_env, sr=sr) >>> tempo 129.19921875
Plot the estimated tempo against the onset autocorrelation
>>> import matplotlib.pyplot as plt >>> # Compute 2-second windowed autocorrelation >>> hop_length = 512 >>> ac = librosa.autocorrelate(onset_env, 2 * sr // hop_length) >>> # Convert tempo estimate from bpm to frames >>> tempo_frames = (60 * sr / hop_length) / tempo >>> plt.plot(librosa.util.normalize(ac), ... label='Onset autocorrelation') >>> plt.vlines([tempo_frames], 0, 1, ... color='r', alpha=0.75, linestyle='--', ... label='Tempo: {:.2f} BPM'.format(tempo)) >>> librosa.display.time_ticks(librosa.frames_to_time(np.arange(len(ac)), ... sr=sr)) >>> plt.xlabel('Lag') >>> plt.legend() >>> plt.axis('tight')