Datasets:

Modalities:
Audio
Text
Languages:
English
ArXiv:
Libraries:
Datasets
License:
patrickvonplaten commited on
Commit
d3bb592
1 Parent(s): 466f219
Files changed (1) hide show
  1. ami-ihm-kaldi-chunked.py +31 -52
ami-ihm-kaldi-chunked.py CHANGED
@@ -280,10 +280,6 @@ class AMIConfig(datasets.BuilderConfig):
280
  def __init__(self, name, *args, **kwargs):
281
  """BuilderConfig for AMI"""
282
  super().__init__(name=name, *args, **kwargs)
283
- if name not in {"dev", "test"}:
284
- self.subsets_to_download = _SUBSETS[: _SUBSETS.index(name) + 1]
285
- else:
286
- self.subsets_to_download = (name,)
287
 
288
 
289
  class AMI(datasets.GeneratorBasedBuilder):
@@ -331,9 +327,9 @@ class AMI(datasets.GeneratorBasedBuilder):
331
  )
332
 
333
  def _split_generators(self, dl_manager):
334
- train_audio_files = [_AUDIO_ARCHIVE_URL.format(subset=self.name, split="train", _id=m) for m in _TRAIN_SAMPLE_IDS]
335
- dev_audio_files = [_AUDIO_ARCHIVE_URL.format(subset=self.name, split="dev", _id=m) for m in _VALIDATION_SAMPLE_IDS]
336
- eval_audio_files = [_AUDIO_ARCHIVE_URL.format(subset=self.name, split="eval", _id=m) for m in _EVAL_SAMPLE_IDS]
337
 
338
  train_audio_archives = dl_manager.download_and_extract(train_audio_files)
339
  dev_audio_archives = dl_manager.download_and_extract(dev_audio_files)
@@ -343,61 +339,44 @@ class AMI(datasets.GeneratorBasedBuilder):
343
  dev_annotation = dl_manager.download_and_extract(_ANNOTATIONS_ARCHIVE_URL.format(split="dev"))
344
  eval_annotation = dl_manager.download_and_extract(_ANNOTATIONS_ARCHIVE_URL.format(split="eval"))
345
 
346
- import ipdb; ipdb.set_trace()
347
-
348
  return [
349
  datasets.SplitGenerator(
350
  name=datasets.Split.TRAIN,
351
- gen_kwargs={"audio": train_audio_archives, "annotation": train_annotation},
352
  ),
353
  datasets.SplitGenerator(
354
  name=datasets.Split.VALIDATION,
355
- gen_kwargs={"audio": dev_audio_archives, "annotation": dev_annotation},
356
  ),
357
  datasets.SplitGenerator(
358
  name=datasets.Split.TEST,
359
- gen_kwargs={"audio": eval_audio_archives, "annotation": eval_annotation},
360
  ),
361
  ]
362
 
363
- def _generate_examples(self, audio, annotation):
364
- import ipdb; ipdb.set_trace()
365
- # assert len(audio_archives_iterators) == len(meta_paths)
366
- # if local_audio_archives_paths:
367
- # assert len(audio_archives_iterators) == len(local_audio_archives_paths)
368
- #
369
- # for i, (meta_path, audio_archive_iterator) in enumerate(
370
- # zip(meta_paths, audio_archives_iterators)
371
- # ):
372
- # meta_dict = dict()
373
- # with open(meta_path) as csvfile:
374
- # meta_csv = csv.DictReader(csvfile)
375
- # for line in meta_csv:
376
- # meta_dict[line["sid"]] = line
377
- #
378
- # for audio_path_in_archive, audio_file in audio_archive_iterator:
379
- # `audio_path_in_archive` is like "dev_chunks_0000/YOU1000000029_S0000095.wav"
380
- # audio_filename = os.path.split(audio_path_in_archive)[1]
381
- # audio_id = audio_filename.split(".wav")[0]
382
- # audio_meta = meta_dict[audio_id]
383
- # audio_meta["segment_id"] = audio_meta.pop("sid")
384
- # audio_meta["original_full_path"] = audio_meta.pop("path")
385
- # audio_meta["text"] = audio_meta.pop("text_tn")
386
- # audio_meta["audio_id"] = audio_meta.pop("aid")
387
- # if not audio_meta["category"]:
388
- # audio_meta["category"] = "N/A"
389
- #
390
- # path = (
391
- # os.path.join(local_audio_archives_paths[i], audio_path_in_archive)
392
- # if local_audio_archives_paths
393
- # else audio_path_in_archive
394
- # )
395
 
396
- # yield audio_id, {
397
- # "audio": {"path": path, "bytes": audio_file.read()},
398
- # **{
399
- # feature: value
400
- # for feature, value in audio_meta.items()
401
- # if feature in self.info.features
402
- # },
403
- # }
 
280
  def __init__(self, name, *args, **kwargs):
281
  """BuilderConfig for AMI"""
282
  super().__init__(name=name, *args, **kwargs)
 
 
 
 
283
 
284
 
285
  class AMI(datasets.GeneratorBasedBuilder):
 
327
  )
328
 
329
  def _split_generators(self, dl_manager):
330
+ train_audio_files = {m: _AUDIO_ARCHIVE_URL.format(subset=self.config.name, split="train", _id=m) for m in _TRAIN_SAMPLE_IDS}
331
+ dev_audio_files = {m: _AUDIO_ARCHIVE_URL.format(subset=self.config.name, split="dev", _id=m) for m in _VALIDATION_SAMPLE_IDS}
332
+ eval_audio_files = {m: _AUDIO_ARCHIVE_URL.format(subset=self.config.name, split="eval", _id=m) for m in _EVAL_SAMPLE_IDS}
333
 
334
  train_audio_archives = dl_manager.download_and_extract(train_audio_files)
335
  dev_audio_archives = dl_manager.download_and_extract(dev_audio_files)
 
339
  dev_annotation = dl_manager.download_and_extract(_ANNOTATIONS_ARCHIVE_URL.format(split="dev"))
340
  eval_annotation = dl_manager.download_and_extract(_ANNOTATIONS_ARCHIVE_URL.format(split="eval"))
341
 
 
 
342
  return [
343
  datasets.SplitGenerator(
344
  name=datasets.Split.TRAIN,
345
+ gen_kwargs={"audio": train_audio_archives, "annotation": train_annotation, "split": "train"},
346
  ),
347
  datasets.SplitGenerator(
348
  name=datasets.Split.VALIDATION,
349
+ gen_kwargs={"audio": dev_audio_archives, "annotation": dev_annotation, "split": "dev"},
350
  ),
351
  datasets.SplitGenerator(
352
  name=datasets.Split.TEST,
353
+ gen_kwargs={"audio": eval_audio_archives, "annotation": eval_annotation, "split": "eval"},
354
  ),
355
  ]
356
 
357
+ def _generate_examples(self, audio, annotation, split):
358
+ # open annotation file
359
+ with open(annotation, "r", encoding="utf-8") as f:
360
+ transcriptions = {}
361
+ for line in f.readlines():
362
+ line_items = line.strip().split()
363
+ _id = line_items[0]
364
+ text = " ".join(line_items[1:])
365
+ _, segment_id, microphone_id, speaker_id, begin_time, end_time = _id.split("_")
366
+
367
+ transcriptions[_id] = {
368
+ "audio_id": _id,
369
+ "segment_id": segment_id,
370
+ "text": text,
371
+ "begin_time": int(begin_time) / 100,
372
+ "end_time": int(end_time) / 100,
373
+ "microphone_id": microphone_id,
374
+ "speaker_id": speaker_id,
375
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
376
 
377
+ for _audio_id, (transcription_id, result) in enumerate(transcriptions.items()):
378
+ folder_id = result["segment_id"]
379
+ file_name = "_".join([split, transcription_id.lower()]) + ".wav"
380
+ audio_file = os.path.join(audio[folder_id], folder_id, file_name)
381
+ result["audio"] = audio_file
382
+ yield _audio_id, result