comodoro commited on
Commit
00b80a1
1 Parent(s): f207bae

Update vystadial2016_asr.py

Browse files
Files changed (1) hide show
  1. vystadial2016_asr.py +19 -26
vystadial2016_asr.py CHANGED
@@ -96,35 +96,28 @@ class Vystadial2016ASR(datasets.GeneratorBasedBuilder):
96
  def _generate_examples(self, files, local_extracted_archive):
97
  """Generate examples from a Vystadial2016 archive_path."""
98
  key = 0
99
- audio_data = {}
100
- transcripts = []
101
  for path, f in files:
102
  id_ = path.split("/")[-1][:-4]
103
  if path.endswith(".wav"):
104
- audio_data[id_] = f.read()
 
 
 
 
 
 
105
  elif path.endswith(".trs"):
106
- for line in f:
107
- if line:
108
- line = line.decode("utf-8").strip()
109
- id_, transcript = line.split(" ", 1)
110
- audio_file = f"{id_}.wav"
111
- audio_file = (
112
- os.path.join(local_extracted_archive, audio_file)
113
- if local_extracted_archive
114
- else audio_file
115
- )
116
- transcripts.append(
117
- {
118
- "id": id_,
119
- "file": audio_file,
120
- "text": transcript,
121
- }
122
- )
123
- if audio_data and len(audio_data) == len(transcripts):
124
- for transcript in transcripts:
125
- audio = {"path": transcript["file"], "bytes": audio_data[transcript["id"]]}
126
- yield key, {"audio": audio, **transcript}
127
  key += 1
128
- audio_data = {}
129
- transcripts = []
130
 
 
96
  def _generate_examples(self, files, local_extracted_archive):
97
  """Generate examples from a Vystadial2016 archive_path."""
98
  key = 0
99
+ samples = {}
100
+ transcripts = {}
101
  for path, f in files:
102
  id_ = path.split("/")[-1][:-4]
103
  if path.endswith(".wav"):
104
+ audio_data = f.read()
105
+ audio_file = f"{id_}.wav"
106
+ audio_file = (
107
+ os.path.join(local_extracted_archive, audio_file)
108
+ if local_extracted_archive
109
+ else audio_file )
110
+ samples[id_] = {'audio': audio_file, 'bytes': audio_data}
111
  elif path.endswith(".trs"):
112
+ lines = f.readlines()
113
+ if not lines:
114
+ continue
115
+ line = lines[0].decode("utf-8").strip()
116
+ transcripts[id_] = {'text': line}
117
+
118
+ if samples and len(samples) == len(transcripts):
119
+ for id_, sample in samples.items():
120
+ yield key, {"id_": id_, **sample, **transcripts[id_}
 
 
 
 
 
 
 
 
 
 
 
 
121
  key += 1
122
+
 
123