Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find the tempo of a .wav with aubio?

I'm looking to detect the tempo of an audio file in python 3.6, but I don't really understand the doc about aubio. Would someone please indicate how to extract the tempo with aubio or another library?

like image 904
P G Avatar asked Jan 31 '26 10:01

P G


1 Answers

Updated

This command will give you the tempo estimate of the entire file (available in 0.4.5):

aubio tempo foo.wav

There is a simple demo in aubio's python/demos: demo_bpm_extract.py.

The most important part is the following two lines, which compute the periods between each consecutive beats (np.diff), convert these periods in bpm (60./), and takes the median (np.median) as the most likely bpm candidate for this series of beats:

#!/usr/bin/env python
import numpy as np
bpms = 60./np.diff(beats)
median_bpm = np.median(bpms)

Note how the median is better suited than the mean here, since it will always give an estimate which exists in the original population bpms.

like image 195
piem Avatar answered Feb 02 '26 23:02

piem