Update vystadial2016_asr.py
Browse files- 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 |
-
|
100 |
-
transcripts =
|
101 |
for path, f in files:
|
102 |
id_ = path.split("/")[-1][:-4]
|
103 |
if path.endswith(".wav"):
|
104 |
-
audio_data
|
|
|
|
|
|
|
|
|
|
|
|
|
105 |
elif path.endswith(".trs"):
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
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 |
-
|
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 |
|