Datasets:
Tags:
speech-modeling
License:
Adding bokmaal and nynorsk configs
Browse files
NPSC.py
CHANGED
@@ -82,10 +82,30 @@ class Npsc(datasets.GeneratorBasedBuilder):
|
|
82 |
version=datasets.Version("1.0.0"),
|
83 |
description="NPSC with samples in 16KHz mono mp3)",
|
84 |
),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
85 |
]
|
86 |
|
87 |
def _info(self):
|
88 |
-
sampling_rate = 16_000 if self.config.name
|
89 |
return datasets.DatasetInfo(
|
90 |
description=_DESCRIPTION,
|
91 |
features=datasets.Features(
|
@@ -121,6 +141,8 @@ class Npsc(datasets.GeneratorBasedBuilder):
|
|
121 |
"""Returns SplitGenerators."""
|
122 |
data_urls = {}
|
123 |
config_name = self.config.name
|
|
|
|
|
124 |
for split in ["train", "eval", "test"]:
|
125 |
data_urls[split] = []
|
126 |
for shard in _SHARDS[split]:
|
@@ -154,6 +176,11 @@ class Npsc(datasets.GeneratorBasedBuilder):
|
|
154 |
"""Yields examples."""
|
155 |
data_fields = list(self._info().features.keys())
|
156 |
data_fields.remove("audio")
|
|
|
|
|
|
|
|
|
|
|
157 |
for metadata_path, archive_path in filepaths:
|
158 |
metadata = {}
|
159 |
with open(metadata_path) as metadata_file:
|
@@ -172,4 +199,8 @@ class Npsc(datasets.GeneratorBasedBuilder):
|
|
172 |
audio_bytes = tar.extractfile(audio_file).read()
|
173 |
audio_dict = {"bytes": audio_bytes, "path": audio_file.name}
|
174 |
fields = {key: metadata[metadata_key][key] for key in data_fields}
|
175 |
-
|
|
|
|
|
|
|
|
|
|
82 |
version=datasets.Version("1.0.0"),
|
83 |
description="NPSC with samples in 16KHz mono mp3)",
|
84 |
),
|
85 |
+
NpscConfig(
|
86 |
+
name="48K_mp3_bokmaal",
|
87 |
+
version=datasets.Version("1.0.0"),
|
88 |
+
description="NPSC with Bokmål samples in 48KHz stereo mp3)",
|
89 |
+
),
|
90 |
+
NpscConfig(
|
91 |
+
name="16K_mp3_bokmaal",
|
92 |
+
version=datasets.Version("1.0.0"),
|
93 |
+
description="NPSC with Bokmål samples in 16KHz mono mp3)",
|
94 |
+
),
|
95 |
+
NpscConfig(
|
96 |
+
name="48K_mp3_nynorsk",
|
97 |
+
version=datasets.Version("1.0.0"),
|
98 |
+
description="NPSC with Nynorsk samples in 48KHz stereo mp3)",
|
99 |
+
),
|
100 |
+
NpscConfig(
|
101 |
+
name="16K_mp3_nynorsk",
|
102 |
+
version=datasets.Version("1.0.0"),
|
103 |
+
description="NPSC with Nynorsk samples in 16KHz mono mp3)",
|
104 |
+
),
|
105 |
]
|
106 |
|
107 |
def _info(self):
|
108 |
+
sampling_rate = 16_000 if self.config.name.startswith("16K") else 48_000
|
109 |
return datasets.DatasetInfo(
|
110 |
description=_DESCRIPTION,
|
111 |
features=datasets.Features(
|
|
|
141 |
"""Returns SplitGenerators."""
|
142 |
data_urls = {}
|
143 |
config_name = self.config.name
|
144 |
+
if config_name.endswith("bokmaal") or config_name.endswith("nynorsk"):
|
145 |
+
config_name, *_ = config_name.rsplit("_", 1)
|
146 |
for split in ["train", "eval", "test"]:
|
147 |
data_urls[split] = []
|
148 |
for shard in _SHARDS[split]:
|
|
|
176 |
"""Yields examples."""
|
177 |
data_fields = list(self._info().features.keys())
|
178 |
data_fields.remove("audio")
|
179 |
+
lang_code = None
|
180 |
+
if self.config.name.endswith("bokmaal"):
|
181 |
+
lang_code = "nb-no"
|
182 |
+
elif self.config.name.endswith("nynorsk"):
|
183 |
+
lang_code = "nn-no"
|
184 |
for metadata_path, archive_path in filepaths:
|
185 |
metadata = {}
|
186 |
with open(metadata_path) as metadata_file:
|
|
|
199 |
audio_bytes = tar.extractfile(audio_file).read()
|
200 |
audio_dict = {"bytes": audio_bytes, "path": audio_file.name}
|
201 |
fields = {key: metadata[metadata_key][key] for key in data_fields}
|
202 |
+
if lang_code:
|
203 |
+
if lang_code == fields.get("sentence_language_code", "").lower():
|
204 |
+
yield metadata_key, {"audio": audio_dict, **fields}
|
205 |
+
else:
|
206 |
+
yield metadata_key, {"audio": audio_dict, **fields}
|