Accurate metronome with Python

Problem

The build-in time / timer libraries in Python fluctuate.

If you try to build a metronome at 60 BPM and imagine using the timer with a sleep time of 60 milliseconds, you will quickly find out that it will be triggered somewhere between 59.50 – 60.50 milliseconds.

Such a fluctuating metronome is not usable for a musician as a metronome.

Reason

Your code doesn’t access the hardware directly and goes through a lot of layers. Therefore, the moment of the actual trigger depends on many factors out of control.

So, is there no hope to build an accurate metronome with Python?

Solution

In my Guitar Training Remote Python project, I have solved this issue with a very simple but effective approach.

I have pre-recorded metronome clicks in various speeds, and saved them as .mp3 files within my project structure.

Whenever the user starts the metronome in a certain speed, I simply playback the corresponding .mp3 file.

Easy enough, eh?


Posted

in

, ,

by

Tags:

Comments

Leave a comment