For programmatic access, use the beat_this.inference module. The File2Beats class handles model loading, audio pre-processing, and beat prediction.
Inference with Files
from beat_this.inference import File2Beats
# Initialize the tracker
# checkpoint_path: name of the model (e.g., 'final0')
# device: 'cuda' or 'cpu'
# dbn: boolean, whether to use DBN postprocessing
file2beats = File2Beats(checkpoint_path="final0", device="cuda", dbn=False)
# Predict beats and downbeats
audio_path = "path/to/audio.file"
beats, downbeats = file2beats(audio_path)
Saving Results
You can save the predicted beats to a .beats file (compatible with Sonic Visualizer) using save_beat_tsv:
from beat_this.utils import save_beat_tsv
outpath = "path/to/output.beats"
save_beat_tsv(beats, downbeats, outpath)
Other Inference Classes
Audio2Beats: Use this if you already have an audio tensor loaded (requires passing the tensor and sample rate).Audio2Frames: Provides framewise logits.Spect2Frames: Provides spectrogram inputs.
from beat_this.inference import File2Beats
file2beats = File2Beats(checkpoint_path="final0", device="cuda", dbn=False)
beats, downbeats = file2beats("path/to/audio.file")