HugoLaurencon HF staff commited on
Commit
29bc121
1 Parent(s): 2543b30

new generate_examples method

Browse files
Files changed (1) hide show
  1. libri_light.py +19 -22
libri_light.py CHANGED
@@ -17,6 +17,9 @@
17
  """Libri-Light audio dataset."""
18
 
19
 
 
 
 
20
  import json
21
 
22
  import datasets
@@ -147,25 +150,19 @@ class LibriLight(datasets.GeneratorBasedBuilder):
147
  ),
148
  ]
149
 
150
- def _generate_examples(self, files, local_extracted_archive):
151
- """Generate examples from a Libri-Light archive_path."""
152
- key = 0
153
- for path, f in files:
154
- if path.endswith(".flac"):
155
- path_split = path.split("/")
156
- audio_file = path_split[-1]
157
- id_ = audio_file.replace(".flac", "")
158
- file = path if local_extracted_archive else audio_file
159
- audio = {"path": file, "bytes": f.read()}
160
- speaker_id = int(path_split[-3])
161
- #path_json = path.replace(".flac", ".json")
162
- #with open(path_json) as json_file:
163
- # metadata = json.load(json_file)
164
- yield key, {
165
- "id": id_,
166
- "file": file,
167
- "audio": audio,
168
- "speaker_id": speaker_id,
169
- # "metadata": metadata,
170
- }
171
- key += 1
 
17
  """Libri-Light audio dataset."""
18
 
19
 
20
+ import glob
21
+ import os
22
+
23
  import json
24
 
25
  import datasets
 
150
  ),
151
  ]
152
 
153
+ def _generate_examples(self, archive_path):
154
+ paths = glob.glob(os.path.join(archive_path, "**", "**", "*.flac"))
155
+ for key, path in enumerate(paths):
156
+ path_split = path.split("/")
157
+ id_ = path_split[-1].replace(".flac", "")
158
+ speaker_id = int(path_split[-3])
159
+ #path_json = path.replace(".flac", ".json")
160
+ #with open(path_json) as json_file:
161
+ # metadata = json.load(json_file)
162
+ yield key, {
163
+ "id": id_,
164
+ "file": path,
165
+ "audio": path,
166
+ "speaker_id": speaker_id,
167
+ # "metadata": metadata,
168
+ }