I haven't worked in pygame, or opencv's python bindings, but if either of those have memory leaks, that could be an issue.
Otherwise, that sounds plausible for timing, depending on how you're counting and what your hardware is.
→ time ./beat_tracker.py ~/data/MedleyDB_sample/Audio/LizNelson_Rainfall/LizNelson_Rainfall_MIX.wav beats.csv
Loading /home/bmcfee/data/MedleyDB_sample/Audio/LizNelson_Rainfall/LizNelson_Rainfall_MIX.wav
Tracking beats
Estimated tempo: 129.20 beats per minute
Saving output to beats.csv
done!
13.22user 0.90system 0:13.31elapsed 106%CPU (0avgtext+0avgdata 399924maxresident)k
24inputs+32outputs (1major+81308minor)pagefaults 0swaps
→ soxi ~/data/MedleyDB_sample/Audio/LizNelson_Rainfall/LizNelson_Rainfall_MIX.wav
Input File : '/home/bmcfee/data/MedleyDB_sample/Audio/LizNelson_Rainfall/LizNelson_Rainfall_MIX.wav'
Channels : 2
Sample Rate : 44100
Precision : 16-bit
Duration : 00:04:44.91 = 12564480 samples = 21368.2 CDDA sectors
File Size : 50.3M
Bit Rate : 1.41M
Sample Encoding: 16-bit Signed Integer PCM
Running it through a profiler, most of the time is spent in load and resampling to 22KHz. Factoring out those parts and timing just the beat tracker gives me about 1.5s on average:
In [2]: y, sr = librosa.load('/home/bmcfee/data/MedleyDB_sample/Audio/LizNelson_Rainfall/LizNelson_Rainfall_MIX.wav', sr=22050)
In [3]: %timeit librosa.beat.beat_track(y=y, sr=sr)
1.49 s ± 10.9 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)
Depending on what else you're doing, this could be made more efficient by precomputing spectrograms or onset strength envelopes.
FWIW, my system info is as follows:
In [2]: np.show_config()
lapack_mkl_info:
NOT AVAILABLE
blas_mkl_info:
NOT AVAILABLE
lapack_opt_info:
libraries = ['openblas', 'openblas']
language = c
define_macros = [('HAVE_CBLAS', None)]
library_dirs = ['/home/bmcfee/miniconda/envs/py35/lib']
openblas_info:
libraries = ['openblas', 'openblas']
language = c
define_macros = [('HAVE_CBLAS', None)]
library_dirs = ['/home/bmcfee/miniconda/envs/py35/lib']
openblas_lapack_info:
libraries = ['openblas', 'openblas']
language = c
define_macros = [('HAVE_CBLAS', None)]
library_dirs = ['/home/bmcfee/miniconda/envs/py35/lib']
blis_info:
NOT AVAILABLE
blas_opt_info:
libraries = ['openblas', 'openblas']
language = c
define_macros = [('HAVE_CBLAS', None)]
library_dirs = ['/home/bmcfee/miniconda/envs/py35/lib']
In [2]: librosa.show_versions()
INSTALLED VERSIONS
------------------
python: 3.5.4 | packaged by conda-forge | (default, Nov 4 2017, 10:11:29)
[GCC 4.8.2 20140120 (Red Hat 4.8.2-15)]
librosa: 0.5.1
audioread: installed, no version number available
numpy: 1.13.3
scipy: 1.0.0
sklearn: 0.19.1
joblib: 0.11
decorator: 4.1.2
six: 1.11.0
resampy: 0.2.0
numpydoc: 0.7.0
sphinx: 1.6.5
sphinx_rtd_theme: 0.2.4
sphinxcontrib.versioning: 2.2.1
matplotlib: 2.1.0
numba: 0.35.0+10.g143f70e90
CPU: Intel(R) Core(TM) i7-4600U CPU @ 2.10GHz
→ free -h
total used free shared buff/cache available
Mem: 7.5G 6.0G 447M 186M 1.1G 1.0G