I'm a Software Engineer Undergraduate. I'm trying to detect drum strokes(beats) in real-time in python. I used amplitude threshold-based onset detect (beat detect) algorithm but it takes other noises also onsets and it omits some actual beats with low amplitude. Can you have suggestions to optimize my code or another way to solve this?
My guess is that the currently popular and new and likely robust way to solve this detection problem is to feed a sequence of audio fingerprints (such as MFCCs) to an RNN machine learning algorithm that was trained on a large wide range of rhythm tracks mixed with increasing levels of realistic background noise.
Feeding audio stream samples directly to a deeper CNN+RNN ML inference engine might work even better by detecting humanly resolvable beat details that audio fingerprinting misses, but that would be computationally far less efficient and would take a lot longer to train.
Using an adaptive threshold might help you: calculating the mean amplitude over a small moving time window (e.g. 0.5 sec), and setting a threshold as a function of the mean (e.g. 3X). This should detect sudden changes in amplitude (which drum strokes almost always are).