Beat Detection

487 views
Skip to first unread message

David Wang

unread,
Aug 3, 2016, 4:26:43 PM8/3/16
to librosa
Hi, I am currently trying to make a rhythm game in Python using Librosa for beat detection. I looked at the csv file Librosa returned and noticed that the intervals between all the notes were approximately the same, and don't match the mp3 that I loaded in. Is the beat_track based on actual beats or a consistent rhythm that is played throughout the song? If there is a feature to measure spikes/beats (that fit the song), how would I get them? Thanks. 

    # Load the file
    print('Loading  ', input_file)
    y, sr = librosa.load(input_file)

    tempo, beat_frames = librosa.beat.beat_track(y=y, sr=sr)

    print('Estimated tempo: {:.2f} beats per minute'.format(tempo))

    # 4. Convert the frame indices of beat events into timestamps
    beat_times = librosa.frames_to_time(beat_frames, sr=sr)

Brian McFee

unread,
Aug 4, 2016, 10:19:23 AM8/4/16
to librosa
Is there any chance you can post an example of this?  Or describe the input audio somehow (i.e., instrumentation, tempo, style, etc.)?  That would help considerably.

The code snippet you pasted below seems okay to me.

The output of beat_track is based on both the estimated tempo and the position of detected note onsets.  It should be pretty robust to slight deviations from the global tempo.  If you're finding that the detected beats are too rigidly spaced, you could try lowering the "tightness" parameter as described in the documentation.

I'm not sure what you mean by "measure spikes/beats", but perhaps the onset strength envelope is what you're looking for?  This function is used internally from the beat tracker, but you can also call it directly to get a feel for what librosa thinks is going on with your audio.  Note, however, that the default settings for onset_strength are a little different from those used by beat_track; if you want to exactly recover what the beat tracker is doing, you'll need to apply the parameters as set in beat_track.

I hope that helps!
Reply all
Reply to author
Forward
0 new messages