Last active
January 24, 2025 09:02
-
-
Save mayakerostasia/93fef01cda6cce72a63702aa25e00eb4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# # Beat tracking example | |
import multiprocessing | |
import librosa | |
import xml.etree.ElementTree as ET | |
def get_beat_times(file_path): | |
# 2. Load the audio as a waveform `y` | |
# Store the sampling rate as `sr` | |
y, sr = librosa.load(file_path) | |
# 3. Run the default beat tracker | |
tempo, beat_frames = librosa.beat.beat_track(y=y, sr=sr) | |
print('Estimated tempo: {} 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) | |
return beat_times[0::64][0:6] | |
def write_cue_points(track): | |
marks = track.findall('POSITION_MARK') | |
location = track.get('Location').replace("file://localhost/","").replace("%20"," ") | |
if location.startswith("C"): | |
return None | |
else: | |
cue_times = get_beat_times(location) | |
for time in cue_times: | |
print(time) | |
ET.SubElement(track, 'POSITION_MARK', {'Name': '', 'Type': '0', 'Start': str(time), 'Num': "-1"}) | |
# Read XML File | |
tree = ET.parse('rekordbox-test.xml') | |
def main(): | |
tracks = tree.findall('COLLECTION/TRACK') | |
print(tracks) | |
pool = multiprocessing.Pool(20) | |
complete = pool.map(write_cue_points, [track for track in tracks]) | |
tree.write('rekordbox-test-out.xml') | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment