-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsegment_transform.py
31 lines (21 loc) · 1.12 KB
/
segment_transform.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import numpy as np
import librosa
# Segment boundaries in sample indices
segment_boundaries_indices = np.array([0, 17, 94, 135, 203, 233, 268, 399, 428, 459, 592, 654, 759, 831, 866, 1015, 1031])
# Hop length and sampling rate
hop_length = int(4096 * 0.75)
sr = 22050
# Convert indices to time frames
segment_boundaries_frames = segment_boundaries_indices * hop_length
# Convert time frames to timestamps
segment_boundaries_timestamps = segment_boundaries_frames / sr
print("Segment boundaries in timestamps (seconds): \n", segment_boundaries_timestamps)
librosa_timestamps = librosa.frames_to_time(segment_boundaries_indices, sr=sr, hop_length=hop_length)
print("\nSegment boundaries in timestamps using librosa (seconds): \n", librosa_timestamps)
samples = librosa.frames_to_samples(segment_boundaries_indices, hop_length=hop_length)
print("\nSegment boundaries in samples using librosa: \n", samples)
time = 25000
frame_number = librosa.time_to_frames(time / 1000, sr=sr, hop_length=hop_length)
print("Frame number: ", frame_number)
time = librosa.frames_to_time(frame_number, sr=sr, hop_length=hop_length)
print("Time: ", time)