Update test1.py
Browse files
test1.py
CHANGED
|
@@ -1,94 +1,92 @@
|
|
| 1 |
-
import datasets
|
| 2 |
-
|
| 3 |
-
_DATA_URL = "data/vivos_noisy.tar.gz"
|
| 4 |
-
|
| 5 |
-
_PROMPTS_URLS = {
|
| 6 |
-
"train": "data/train_prompts.txt.gz",
|
| 7 |
-
"test": "data/test_prompts.txt.gz",
|
| 8 |
-
}
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
class VivosNoisyDataset(datasets.GeneratorBasedBuilder):
|
| 12 |
-
"""VIVOS NOISY is a Vietnamese speech corpus with added noise, based on the original VIVOS dataset.
|
| 13 |
-
This corpus is prepared for Vietnamese Automatic Speech Recognition task under noisy environments."""
|
| 14 |
-
|
| 15 |
-
VERSION = datasets.Version("1.1.0")
|
| 16 |
-
|
| 17 |
-
def _info(self):
|
| 18 |
-
return datasets.DatasetInfo(
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
"
|
| 24 |
-
"
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
"
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
"
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
"
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
id_ += 1
|
| 93 |
-
elif inside_clips_dir:
|
| 94 |
break
|
|
|
|
| 1 |
+
import datasets
|
| 2 |
+
|
| 3 |
+
_DATA_URL = "data/vivos_noisy.tar.gz"
|
| 4 |
+
|
| 5 |
+
_PROMPTS_URLS = {
|
| 6 |
+
"train": "data/train_prompts.txt.gz",
|
| 7 |
+
"test": "data/test_prompts.txt.gz",
|
| 8 |
+
}
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
class VivosNoisyDataset(datasets.GeneratorBasedBuilder):
|
| 12 |
+
"""VIVOS NOISY is a Vietnamese speech corpus with added noise, based on the original VIVOS dataset.
|
| 13 |
+
This corpus is prepared for Vietnamese Automatic Speech Recognition task under noisy environments."""
|
| 14 |
+
|
| 15 |
+
VERSION = datasets.Version("1.1.0")
|
| 16 |
+
|
| 17 |
+
def _info(self):
|
| 18 |
+
return datasets.DatasetInfo(
|
| 19 |
+
features=datasets.Features(
|
| 20 |
+
{
|
| 21 |
+
"speaker_id": datasets.Value("string"),
|
| 22 |
+
"path": datasets.Value("string"),
|
| 23 |
+
"audio": datasets.Audio(sampling_rate=16_000),
|
| 24 |
+
"sentence": datasets.Value("string"),
|
| 25 |
+
}
|
| 26 |
+
),
|
| 27 |
+
supervised_keys=None,
|
| 28 |
+
)
|
| 29 |
+
|
| 30 |
+
def _split_generators(self, dl_manager):
|
| 31 |
+
prompts_paths = dl_manager.download_and_extract(_PROMPTS_URLS)
|
| 32 |
+
archive = dl_manager.download(_DATA_URL)
|
| 33 |
+
train_dir = "vivos_noisy/train"
|
| 34 |
+
test_dir = "vivos_noisy/test"
|
| 35 |
+
|
| 36 |
+
return [
|
| 37 |
+
datasets.SplitGenerator(
|
| 38 |
+
name=datasets.Split.TRAIN,
|
| 39 |
+
# These kwargs will be passed to _generate_examples
|
| 40 |
+
gen_kwargs={
|
| 41 |
+
"prompts_path": prompts_paths["train"],
|
| 42 |
+
"path_to_clips": train_dir + "/waves",
|
| 43 |
+
"audio_files": dl_manager.iter_archive(archive),
|
| 44 |
+
},
|
| 45 |
+
),
|
| 46 |
+
datasets.SplitGenerator(
|
| 47 |
+
name=datasets.Split.TEST,
|
| 48 |
+
# These kwargs will be passed to _generate_examples
|
| 49 |
+
gen_kwargs={
|
| 50 |
+
"prompts_path": prompts_paths["test"],
|
| 51 |
+
"path_to_clips": test_dir + "/waves",
|
| 52 |
+
"audio_files": dl_manager.iter_archive(archive),
|
| 53 |
+
},
|
| 54 |
+
),
|
| 55 |
+
]
|
| 56 |
+
|
| 57 |
+
def _generate_examples(self, prompts_path, path_to_clips, audio_files):
|
| 58 |
+
"""Yields examples as (key, example) tuples."""
|
| 59 |
+
# This method handles input defined in _split_generators to yield (key, example) tuples from the dataset.
|
| 60 |
+
# The `key` is here for legacy reason (tfds) and is not important in itself.
|
| 61 |
+
examples = {}
|
| 62 |
+
with open(prompts_path, encoding="utf-8") as f:
|
| 63 |
+
for row in f:
|
| 64 |
+
data = row.strip().split(" ", 1)
|
| 65 |
+
# Extract speaker_id from the full filename
|
| 66 |
+
# For example: VIVOS_NOISY_VIVOSDEV01_R002_001 -> VIVOS_NOISY_VIVOSDEV01
|
| 67 |
+
filename_parts = data[0].split("_")
|
| 68 |
+
if len(filename_parts) >= 3:
|
| 69 |
+
# Join the first 3 parts to get the speaker_id (VIVOS_NOISY_VIVOSDEV01)
|
| 70 |
+
speaker_id = "_".join(filename_parts[:3])
|
| 71 |
+
else:
|
| 72 |
+
# Fallback if the naming convention is different
|
| 73 |
+
speaker_id = filename_parts[0]
|
| 74 |
+
|
| 75 |
+
audio_path = "/".join([path_to_clips, speaker_id, data[0] + ".wav"])
|
| 76 |
+
examples[audio_path] = {
|
| 77 |
+
"speaker_id": speaker_id,
|
| 78 |
+
"path": audio_path,
|
| 79 |
+
"sentence": data[1],
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
inside_clips_dir = False
|
| 83 |
+
id_ = 0
|
| 84 |
+
for path, f in audio_files:
|
| 85 |
+
if path.startswith(path_to_clips):
|
| 86 |
+
inside_clips_dir = True
|
| 87 |
+
if path in examples:
|
| 88 |
+
audio = {"path": path, "bytes": f.read()}
|
| 89 |
+
yield id_, {**examples[path], "audio": audio}
|
| 90 |
+
id_ += 1
|
| 91 |
+
elif inside_clips_dir:
|
|
|
|
|
|
|
| 92 |
break
|