danilotpnta
commited on
Commit
·
30362fd
1
Parent(s):
be8df6a
update
Browse files
GTZAN_genre_classification.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
import os
|
2 |
import csv
|
3 |
import datasets
|
|
|
4 |
|
5 |
logger = datasets.logging.get_logger(__name__)
|
6 |
|
@@ -95,6 +96,13 @@ class GTZAN(datasets.GeneratorBasedBuilder):
|
|
95 |
if not os.path.exists(file_path):
|
96 |
logger.error(f"File not found: {file_path}")
|
97 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
98 |
yield id_, {
|
99 |
"id": int(row["id"]),
|
100 |
"genre": row["genre"],
|
@@ -114,5 +122,8 @@ class GTZAN(datasets.GeneratorBasedBuilder):
|
|
114 |
"album_cover_path": album_cover_path,
|
115 |
"key": row["key"],
|
116 |
"filepath": file_path,
|
117 |
-
"audio":
|
|
|
|
|
|
|
118 |
}
|
|
|
1 |
import os
|
2 |
import csv
|
3 |
import datasets
|
4 |
+
import librosa
|
5 |
|
6 |
logger = datasets.logging.get_logger(__name__)
|
7 |
|
|
|
96 |
if not os.path.exists(file_path):
|
97 |
logger.error(f"File not found: {file_path}")
|
98 |
|
99 |
+
# Use librosa to load the audio file
|
100 |
+
try:
|
101 |
+
audio, sr = librosa.load(file_path, sr=44100)
|
102 |
+
except Exception as e:
|
103 |
+
logger.error(f"Error loading audio file {file_path}: {e}")
|
104 |
+
continue
|
105 |
+
|
106 |
yield id_, {
|
107 |
"id": int(row["id"]),
|
108 |
"genre": row["genre"],
|
|
|
122 |
"album_cover_path": album_cover_path,
|
123 |
"key": row["key"],
|
124 |
"filepath": file_path,
|
125 |
+
"audio": {
|
126 |
+
"array": audio,
|
127 |
+
"sampling_rate": sr,
|
128 |
+
},
|
129 |
}
|