Final fix
Browse files- vystadial2016_asr.py +14 -7
vystadial2016_asr.py
CHANGED
@@ -94,32 +94,39 @@ class Vystadial2016ASR(datasets.GeneratorBasedBuilder):
|
|
94 |
},
|
95 |
), ]
|
96 |
|
|
|
97 |
def _generate_examples(self, files, local_extracted_archive):
|
98 |
"""Generate examples from a Vystadial2016 archive_path."""
|
99 |
key = 0
|
100 |
samples = {}
|
101 |
transcripts = {}
|
|
|
|
|
102 |
for path, f in files:
|
103 |
if path.endswith(".wav"):
|
104 |
id_ = path.split('/')[-1][:-4]
|
|
|
105 |
audio_data = f.read()
|
106 |
audio_file = f"{id_}.wav"
|
107 |
audio_file = (
|
108 |
os.path.join(local_extracted_archive, audio_file)
|
109 |
if local_extracted_archive
|
110 |
else audio_file )
|
111 |
-
samples[id_] = {'audio': audio_file, 'bytes': audio_data}
|
112 |
elif path.endswith(".trn"):
|
113 |
id_ = path.split('/')[-1][:-8]
|
|
|
114 |
lines = f.readlines()
|
115 |
if not lines:
|
116 |
continue
|
117 |
line = lines[0].decode("utf-8").strip()
|
118 |
transcripts[id_] = line
|
119 |
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
|
|
|
|
|
94 |
},
|
95 |
), ]
|
96 |
|
97 |
+
def _generate_examples(self, files, local_extracted_archive):
|
98 |
def _generate_examples(self, files, local_extracted_archive):
|
99 |
"""Generate examples from a Vystadial2016 archive_path."""
|
100 |
key = 0
|
101 |
samples = {}
|
102 |
transcripts = {}
|
103 |
+
id_transcripts = b''
|
104 |
+
id_samples = b''
|
105 |
for path, f in files:
|
106 |
if path.endswith(".wav"):
|
107 |
id_ = path.split('/')[-1][:-4]
|
108 |
+
id_samples = bytes(a ^ b for a, b in itertools.zip_longest(id_.encode('utf-8'), id_samples, fillvalue=0))
|
109 |
audio_data = f.read()
|
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 |
+
samples[id_] = {'audio': audio_file, 'bytes': audio_data, 'file': path}
|
116 |
elif path.endswith(".trn"):
|
117 |
id_ = path.split('/')[-1][:-8]
|
118 |
+
id_transcripts = bytes(a ^ b for a, b in itertools.zip_longest(id_.encode('utf-8') , id_transcripts, fillvalue=0))
|
119 |
lines = f.readlines()
|
120 |
if not lines:
|
121 |
continue
|
122 |
line = lines[0].decode("utf-8").strip()
|
123 |
transcripts[id_] = line
|
124 |
|
125 |
+
if (samples and len(samples) == len(transcripts)
|
126 |
+
and id_samples == id_transcripts):
|
127 |
+
for id_, sample in samples.items():
|
128 |
+
audio = {"path": sample["audio"], "bytes": sample["bytes"]}
|
129 |
+
yield key, {'audio': audio, 'file': sample['audio'], 'text': transcripts[id_]}
|
130 |
+
key += 1
|
131 |
+
samples = {}
|
132 |
+
transcripts = {}
|