Commit
·
43d362e
1
Parent(s):
7f218dd
Upload LibriLight.py
Browse files- LibriLight.py +22 -2
LibriLight.py
CHANGED
@@ -2,7 +2,7 @@ import glob
|
|
2 |
import os
|
3 |
|
4 |
import json
|
5 |
-
|
6 |
import datasets
|
7 |
|
8 |
|
@@ -122,6 +122,25 @@ class LibriLight(datasets.GeneratorBasedBuilder):
|
|
122 |
),
|
123 |
]
|
124 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
125 |
def _generate_examples(self, archive_path):
|
126 |
paths = glob.glob(os.path.join(archive_path, "small", "**", "**", "*.flac"))
|
127 |
print(f"archive_path in glob: {archive_path}")
|
@@ -139,4 +158,5 @@ class LibriLight(datasets.GeneratorBasedBuilder):
|
|
139 |
"audio": path,
|
140 |
"speaker_id": speaker_id,
|
141 |
"metadata": metadata,
|
142 |
-
}
|
|
|
|
2 |
import os
|
3 |
|
4 |
import json
|
5 |
+
import torchaudio
|
6 |
import datasets
|
7 |
|
8 |
|
|
|
122 |
),
|
123 |
]
|
124 |
|
125 |
+
def _generate_examples(self, archive_path):
|
126 |
+
"""Generate examples from a LibriLight archive_path."""
|
127 |
+
key = 0
|
128 |
+
visitedPaths = set()
|
129 |
+
for path, f in archive_path:
|
130 |
+
if path.endswith(".flac") or path.endswith(".json"):
|
131 |
+
path_split = path.split("/")
|
132 |
+
suffix = path[-5:] # .flac or .json
|
133 |
+
id = path_split[-1].replace(suffix, "")
|
134 |
+
if id not in visitedPaths:
|
135 |
+
path_flac = id + ".flac"
|
136 |
+
path_json = id + ".json"
|
137 |
+
metadata = json.load(path_json)
|
138 |
+
audioData = torchaudio.load(path_flac)
|
139 |
+
yield key, {"audio": audioData, **metadata}
|
140 |
+
key += 1
|
141 |
+
visitedPaths.add(id)
|
142 |
+
|
143 |
+
"""
|
144 |
def _generate_examples(self, archive_path):
|
145 |
paths = glob.glob(os.path.join(archive_path, "small", "**", "**", "*.flac"))
|
146 |
print(f"archive_path in glob: {archive_path}")
|
|
|
158 |
"audio": path,
|
159 |
"speaker_id": speaker_id,
|
160 |
"metadata": metadata,
|
161 |
+
}
|
162 |
+
"""
|