Commit
•
d3e43fb
1
Parent(s):
bc3ee03
Make extensions case-insensitive in timit_asr dataset (#4425)
Browse filesCommit from https://github.com/huggingface/datasets/commit/2f9a6a5bf3e25944b3620c870896dce0c8c0d52f
- timit_asr.py +15 -4
timit_asr.py
CHANGED
@@ -129,14 +129,18 @@ class TimitASR(datasets.GeneratorBasedBuilder):
|
|
129 |
def _generate_examples(self, split, data_dir):
|
130 |
"""Generate examples from TIMIT archive_path based on the test/train csv information."""
|
131 |
# Iterating the contents of the data to extract the relevant information
|
132 |
-
|
|
|
|
|
133 |
|
134 |
# extract transcript
|
135 |
-
|
|
|
136 |
transcript = " ".join(op.readlines()[0].split()[2:]) # first two items are sample number
|
137 |
|
138 |
# extract phonemes
|
139 |
-
|
|
|
140 |
phonemes = [
|
141 |
{
|
142 |
"start": i.split(" ")[0],
|
@@ -147,7 +151,8 @@ class TimitASR(datasets.GeneratorBasedBuilder):
|
|
147 |
]
|
148 |
|
149 |
# extract words
|
150 |
-
|
|
|
151 |
words = [
|
152 |
{
|
153 |
"start": i.split(" ")[0],
|
@@ -175,3 +180,9 @@ class TimitASR(datasets.GeneratorBasedBuilder):
|
|
175 |
}
|
176 |
|
177 |
yield key, example
|
|
|
|
|
|
|
|
|
|
|
|
|
|
129 |
def _generate_examples(self, split, data_dir):
|
130 |
"""Generate examples from TIMIT archive_path based on the test/train csv information."""
|
131 |
# Iterating the contents of the data to extract the relevant information
|
132 |
+
wav_paths = sorted(Path(data_dir).glob(f"**/{split.upper()}/**/*.wav"))
|
133 |
+
wav_paths = wav_paths if wav_paths else sorted(Path(data_dir).glob(f"**/{split.upper()}/**/*.WAV"))
|
134 |
+
for key, wav_path in enumerate(wav_paths):
|
135 |
|
136 |
# extract transcript
|
137 |
+
txt_path = with_case_insensitive_suffix(wav_path, ".txt")
|
138 |
+
with txt_path.open(encoding="utf-8") as op:
|
139 |
transcript = " ".join(op.readlines()[0].split()[2:]) # first two items are sample number
|
140 |
|
141 |
# extract phonemes
|
142 |
+
phn_path = with_case_insensitive_suffix(wav_path, ".phn")
|
143 |
+
with phn_path.open(encoding="utf-8") as op:
|
144 |
phonemes = [
|
145 |
{
|
146 |
"start": i.split(" ")[0],
|
|
|
151 |
]
|
152 |
|
153 |
# extract words
|
154 |
+
wrd_path = with_case_insensitive_suffix(wav_path, ".wrd")
|
155 |
+
with wrd_path.open(encoding="utf-8") as op:
|
156 |
words = [
|
157 |
{
|
158 |
"start": i.split(" ")[0],
|
|
|
180 |
}
|
181 |
|
182 |
yield key, example
|
183 |
+
|
184 |
+
|
185 |
+
def with_case_insensitive_suffix(path: Path, suffix: str):
|
186 |
+
path = path.with_suffix(suffix.lower())
|
187 |
+
path = path if path.exists() else path.with_suffix(suffix.upper())
|
188 |
+
return path
|