Speeding up numpy-based pitch detection with scipy

1 minute read Published:

Tiny follow-up to yesterday's post - discovered that scipy.correlate is faster than numpy.correlate.

Follow-up to yesterday.

First, I removed the youtube-dl components of the program to just accept a filesystem path to transcribe. Baseline benchmark:

$ hyperfine --min-runs 10 './transcribe.py /home/sevagh/repos/transcribe/"Guitar Tuning Standard EADGBE-bKS_m7JObxg.m4a"' -w 1
Benchmark #1: ./transcribe.py /home/sevagh/repos/transcribe/"Guitar Tuning Standard EADGBE-bKS_m7JObxg.m4a"

  Time (mean ± σ):      6.803 s ±  0.131 s    [User: 10.412 s, System: 0.434 s]

  Range (min … max):    6.672 s …  7.070 s

~7s, compared to yesterday’s ~10s, gained from stripping out the download of the file.

After replacing numpy.correlate with scipy.correlate, the time is reduced down to ~3s:

$ hyperfine --min-runs 10 './transcribe.py /home/sevagh/repos/transcribe/"Guitar Tuning Standard EADGBE-bKS_m7JObxg.m4a"' -w 1 --capture-output
Benchmark #1: ./transcribe.py /home/sevagh/repos/transcribe/"Guitar Tuning Standard EADGBE-bKS_m7JObxg.m4a"

  Time (mean ± σ):      3.073 s ±  0.586 s    [User: 2.758 s, System: 0.205 s]

  Range (min … max):    2.460 s …  4.191 s