mnansary commited on
Commit
a837170
·
1 Parent(s): 3557026
Files changed (1) hide show
  1. cvbn.py +30 -64
cvbn.py CHANGED
@@ -178,27 +178,27 @@ class CommonVoice(datasets.GeneratorBasedBuilder):
178
  gen_kwargs={
179
  "local_extracted_archive": local_extracted_archive,
180
  "archive_iterator": dl_manager.iter_archive(archive_path),
181
- "metadata_filepath": os.path.join(train_tsv,"train.tsv"),
182
  "path_to_clips": path_to_clips,
183
  "mode":"train",
184
  },
185
  ),
186
- datasets.SplitGenerator(
187
- name=datasets.Split.TEST,
188
- gen_kwargs={
189
- "local_extracted_archive": local_extracted_archive,
190
- "archive_iterator": dl_manager.iter_archive(archive_path),
191
- "metadata_filepath": "/".join([path_to_data, "test.tsv"]) if path_to_data else "test.tsv",
192
- "path_to_clips": path_to_clips,
193
- "mode":"test",
194
- },
195
- ),
196
  datasets.SplitGenerator(
197
  name=datasets.Split.VALIDATION,
198
  gen_kwargs={
199
  "local_extracted_archive": local_extracted_archive,
200
  "archive_iterator": dl_manager.iter_archive(archive_path),
201
- "metadata_filepath": os.path.join(dev_tsv,"dev.tsv"),
202
  "path_to_clips": path_to_clips,
203
  "mode":"dev",
204
  },
@@ -216,44 +216,10 @@ class CommonVoice(datasets.GeneratorBasedBuilder):
216
  """Yields examples."""
217
  data_fields = list(self._info().features.keys())
218
  metadata = {}
219
- metadata_found = False
220
- if mode in ["test"]:
221
- for path, f in archive_iterator:
222
- if path == metadata_filepath:
223
- metadata_found = True
224
- lines = (line.decode("utf-8") for line in f)
225
- reader = csv.DictReader(lines, delimiter="\t", quoting=csv.QUOTE_NONE)
226
- for row in reader:
227
- # set absolute path for mp3 audio file
228
- if not row["path"].endswith(".mp3"):
229
- row["path"] += ".mp3"
230
- row["path"] = os.path.join(path_to_clips, row["path"])
231
- # accent -> accents in CV 8.0
232
- if "accents" in row:
233
- row["accent"] = row["accents"]
234
- del row["accents"]
235
- # if data is incomplete, fill with empty values
236
- for field in data_fields:
237
- if field not in row:
238
- row[field] = ""
239
- metadata[row["path"]] = row
240
- elif path.startswith(path_to_clips):
241
- assert metadata_found, "Found audio clips before the metadata TSV file."
242
- if not metadata:
243
- break
244
- if path in metadata:
245
- result = metadata[path]
246
- # set the audio feature and the path to the extracted file
247
- path = os.path.join(local_extracted_archive, path) if local_extracted_archive else path
248
- result["audio"] = {"path": path, "bytes": f.read()}
249
- # set path to None if the audio file doesn't exist locally (i.e. in streaming mode)
250
- result["path"] = path if local_extracted_archive else None
251
-
252
- yield path, result
253
- else:
254
- metadata_found = True
255
- with open(metadata_filepath, "rb") as file_obj:
256
- lines = (line.decode("utf-8") for line in file_obj)
257
  reader = csv.DictReader(lines, delimiter="\t", quoting=csv.QUOTE_NONE)
258
  for row in reader:
259
  # set absolute path for mp3 audio file
@@ -269,17 +235,17 @@ class CommonVoice(datasets.GeneratorBasedBuilder):
269
  if field not in row:
270
  row[field] = ""
271
  metadata[row["path"]] = row
272
- for path, f in archive_iterator:
273
- if path.startswith(path_to_clips):
274
- assert metadata_found, "Found audio clips before the metadata TSV file."
275
- if not metadata:
276
- break
277
- if path in metadata:
278
- result = metadata[path]
279
- # set the audio feature and the path to the extracted file
280
- path = os.path.join(local_extracted_archive, path) if local_extracted_archive else path
281
- result["audio"] = {"path": path, "bytes": f.read()}
282
- # set path to None if the audio file doesn't exist locally (i.e. in streaming mode)
283
- result["path"] = path if local_extracted_archive else None
284
-
285
- yield path, result
 
178
  gen_kwargs={
179
  "local_extracted_archive": local_extracted_archive,
180
  "archive_iterator": dl_manager.iter_archive(archive_path),
181
+ "metadata_filepath": dl_manager.iter_archive(train_tsv),
182
  "path_to_clips": path_to_clips,
183
  "mode":"train",
184
  },
185
  ),
186
+ # datasets.SplitGenerator(
187
+ # name=datasets.Split.TEST,
188
+ # gen_kwargs={
189
+ # "local_extracted_archive": local_extracted_archive,
190
+ # "archive_iterator": dl_manager.iter_archive(archive_path),
191
+ # "metadata_filepath": "/".join([path_to_data, "test.tsv"]) if path_to_data else "test.tsv",
192
+ # "path_to_clips": path_to_clips,
193
+ # "mode":"test",
194
+ # },
195
+ # ),
196
  datasets.SplitGenerator(
197
  name=datasets.Split.VALIDATION,
198
  gen_kwargs={
199
  "local_extracted_archive": local_extracted_archive,
200
  "archive_iterator": dl_manager.iter_archive(archive_path),
201
+ "metadata_filepath": dl_manager.iter_archive(dev_tsv),
202
  "path_to_clips": path_to_clips,
203
  "mode":"dev",
204
  },
 
216
  """Yields examples."""
217
  data_fields = list(self._info().features.keys())
218
  metadata = {}
219
+ metadata_found = True
220
+ for path, f in metadata_filepath:
221
+ if f"{mode}.tsv" in path:
222
+ lines = (line.decode("utf-8") for line in f)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
223
  reader = csv.DictReader(lines, delimiter="\t", quoting=csv.QUOTE_NONE)
224
  for row in reader:
225
  # set absolute path for mp3 audio file
 
235
  if field not in row:
236
  row[field] = ""
237
  metadata[row["path"]] = row
238
+ for path, f in archive_iterator:
239
+ if path.startswith(path_to_clips):
240
+ assert metadata_found, "Found audio clips before the metadata TSV file."
241
+ if not metadata:
242
+ break
243
+ if path in metadata:
244
+ result = metadata[path]
245
+ # set the audio feature and the path to the extracted file
246
+ path = os.path.join(local_extracted_archive, path) if local_extracted_archive else path
247
+ result["audio"] = {"path": path, "bytes": f.read()}
248
+ # set path to None if the audio file doesn't exist locally (i.e. in streaming mode)
249
+ result["path"] = path if local_extracted_archive else None
250
+
251
+ yield path, result