mnansary commited on
Commit
1fa7dbe
·
1 Parent(s): 7b4f9cb
Files changed (2) hide show
  1. .gitignore +2 -0
  2. cvbn.py +18 -56
.gitignore ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ debug.ipynb
2
+ train.tsv
cvbn.py CHANGED
@@ -178,7 +178,6 @@ class CommonVoice(datasets.GeneratorBasedBuilder):
178
  "archive_iterator": dl_manager.iter_archive(archive_path),
179
  "metadata_filepath": os.path.join(train_tsv,"train.tsv"),
180
  "path_to_clips": path_to_clips,
181
- "mode":"train",
182
  },
183
  ),
184
  datasets.SplitGenerator(
@@ -188,7 +187,6 @@ class CommonVoice(datasets.GeneratorBasedBuilder):
188
  "archive_iterator": dl_manager.iter_archive(archive_path),
189
  "metadata_filepath": "/".join([path_to_data, "test.tsv"]) if path_to_data else "test.tsv",
190
  "path_to_clips": path_to_clips,
191
- "mode":"test",
192
  },
193
  ),
194
  datasets.SplitGenerator(
@@ -198,7 +196,6 @@ class CommonVoice(datasets.GeneratorBasedBuilder):
198
  "archive_iterator": dl_manager.iter_archive(archive_path),
199
  "metadata_filepath": "/".join([path_to_data, "dev.tsv"]) if path_to_data else "dev.tsv",
200
  "path_to_clips": path_to_clips,
201
- "mode":"dev",
202
  },
203
  ),
204
  ]
@@ -208,50 +205,15 @@ class CommonVoice(datasets.GeneratorBasedBuilder):
208
  local_extracted_archive,
209
  archive_iterator,
210
  metadata_filepath,
211
- path_to_clips,
212
- mode
213
  ):
214
  """Yields examples."""
215
  data_fields = list(self._info().features.keys())
216
  metadata = {}
217
  metadata_found = False
218
- if mode in ["dev","test"]:
219
- for path, f in archive_iterator:
220
- if path == metadata_filepath:
221
- metadata_found = True
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
226
- if not row["path"].endswith(".mp3"):
227
- row["path"] += ".mp3"
228
- row["path"] = os.path.join(path_to_clips, row["path"])
229
- # accent -> accents in CV 8.0
230
- if "accents" in row:
231
- row["accent"] = row["accents"]
232
- del row["accents"]
233
- # if data is incomplete, fill with empty values
234
- for field in data_fields:
235
- if field not in row:
236
- row[field] = ""
237
- metadata[row["path"]] = row
238
- elif path.startswith(path_to_clips):
239
- assert metadata_found, "Found audio clips before the metadata TSV file."
240
- if not metadata:
241
- break
242
- if path in metadata:
243
- result = metadata[path]
244
- # set the audio feature and the path to the extracted file
245
- path = os.path.join(local_extracted_archive, path) if local_extracted_archive else path
246
- result["audio"] = {"path": path, "bytes": f.read()}
247
- # set path to None if the audio file doesn't exist locally (i.e. in streaming mode)
248
- result["path"] = path if local_extracted_archive else None
249
-
250
- yield path, result
251
- else:
252
- metadata_found = True
253
- with open(metadata_filepath, "rb") as file_obj:
254
- lines = (line.decode("utf-8") for line in file_obj)
255
  reader = csv.DictReader(lines, delimiter="\t", quoting=csv.QUOTE_NONE)
256
  for row in reader:
257
  # set absolute path for mp3 audio file
@@ -267,17 +229,17 @@ class CommonVoice(datasets.GeneratorBasedBuilder):
267
  if field not in row:
268
  row[field] = ""
269
  metadata[row["path"]] = row
270
- for path, f in archive_iterator:
271
- if path.startswith(path_to_clips):
272
- assert metadata_found, "Found audio clips before the metadata TSV file."
273
- if not metadata:
274
- break
275
- if path in metadata:
276
- result = metadata[path]
277
- # set the audio feature and the path to the extracted file
278
- path = os.path.join(local_extracted_archive, path) if local_extracted_archive else path
279
- result["audio"] = {"path": path, "bytes": f.read()}
280
- # set path to None if the audio file doesn't exist locally (i.e. in streaming mode)
281
- result["path"] = path if local_extracted_archive else None
282
-
283
- yield path, result
 
178
  "archive_iterator": dl_manager.iter_archive(archive_path),
179
  "metadata_filepath": os.path.join(train_tsv,"train.tsv"),
180
  "path_to_clips": path_to_clips,
 
181
  },
182
  ),
183
  datasets.SplitGenerator(
 
187
  "archive_iterator": dl_manager.iter_archive(archive_path),
188
  "metadata_filepath": "/".join([path_to_data, "test.tsv"]) if path_to_data else "test.tsv",
189
  "path_to_clips": path_to_clips,
 
190
  },
191
  ),
192
  datasets.SplitGenerator(
 
196
  "archive_iterator": dl_manager.iter_archive(archive_path),
197
  "metadata_filepath": "/".join([path_to_data, "dev.tsv"]) if path_to_data else "dev.tsv",
198
  "path_to_clips": path_to_clips,
 
199
  },
200
  ),
201
  ]
 
205
  local_extracted_archive,
206
  archive_iterator,
207
  metadata_filepath,
208
+ path_to_clips
 
209
  ):
210
  """Yields examples."""
211
  data_fields = list(self._info().features.keys())
212
  metadata = {}
213
  metadata_found = False
214
+ metadata_found = True
215
+ with open(metadata_filepath, "rb") as file_obj:
216
+ lines = (line.decode("utf-8") for line in file_obj)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
217
  reader = csv.DictReader(lines, delimiter="\t", quoting=csv.QUOTE_NONE)
218
  for row in reader:
219
  # set absolute path for mp3 audio file
 
229
  if field not in row:
230
  row[field] = ""
231
  metadata[row["path"]] = row
232
+ for path, f in archive_iterator:
233
+ if path.startswith(path_to_clips):
234
+ assert metadata_found, "Found audio clips before the metadata TSV file."
235
+ if not metadata:
236
+ break
237
+ if path in metadata:
238
+ result = metadata[path]
239
+ # set the audio feature and the path to the extracted file
240
+ path = os.path.join(local_extracted_archive, path) if local_extracted_archive else path
241
+ result["audio"] = {"path": path, "bytes": f.read()}
242
+ # set path to None if the audio file doesn't exist locally (i.e. in streaming mode)
243
+ result["path"] = path if local_extracted_archive else None
244
+
245
+ yield path, result