A beat detector in Python