-
Notifications
You must be signed in to change notification settings - Fork 1
/
save_data.py
51 lines (40 loc) · 1.56 KB
/
save_data.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env python3
import librosa
import librosa.display
from os import walk
from matplotlib import pyplot as plt
import pickle
other_songs_paths = []
top_of_the_pops_paths = []
progressive_paths = []
for (directory, _, filenames) in walk('Dataset/Not_Progressive_Rock/Other_Songs/'):
for filename in filenames:
other_songs_paths.append('/'.join([directory, filename]))
for (directory, _, filenames) in walk('Dataset/Not_Progressive_Rock/Top_Of_The_Pops/'):
for filename in filenames:
top_of_the_pops_paths.append('/'.join([directory, filename]))
for (directory, _, filenames) in walk('Dataset/Progressive_Rock_Songs'):
for filename in filenames:
progressive_paths.append('/'.join([directory, filename]))
SR = 22050
other_songs_data = []
top_of_the_pops_data = []
progressive_data = []
for path in other_songs_paths:
x, sr = librosa.load(path, sr=SR)
other_songs_data.append(x)
print(f'Loaded {path} with duration {len(x)/sr}')
for path in top_of_the_pops_paths:
x, sr = librosa.load(path, sr=SR)
top_of_the_pops_data.append(x)
print(f'Loaded {path} with duration {len(x)/sr}')
for path in progressive_paths:
x, sr = librosa.load(path, sr=SR)
progressive_data.append(x)
print(f'Loaded {path} with duration {len(x) / sr}')
with open('other_songs.pkl', 'wb') as f:
pickle.dump(other_songs_data, f)
with open('top_of_the_pops.pkl', 'wb') as f:
pickle.dump(top_of_the_pops_data, f)
with open('progressive.pkl', 'wb') as f:
pickle.dump(progressive_data, f)