Martha-987 commited on
Commit
55df8fe
·
1 Parent(s): b128721

Upload vivos.py

Browse files
Files changed (1) hide show
  1. vivos.py +143 -0
vivos.py ADDED
@@ -0,0 +1,143 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ import datasets
17
+
18
+
19
+ _CITATION = """\
20
+ @inproceedings{luong-vu-2016-non,
21
+ title = "A non-expert {K}aldi recipe for {V}ietnamese Speech Recognition System",
22
+ author = "Luong, Hieu-Thi and
23
+ Vu, Hai-Quan",
24
+ booktitle = "Proceedings of the Third International Workshop on Worldwide Language Service Infrastructure and Second Workshop on Open Infrastructures and Analysis Frameworks for Human Language Technologies ({WLSI}/{OIAF}4{HLT}2016)",
25
+ month = dec,
26
+ year = "2016",
27
+ address = "Osaka, Japan",
28
+ publisher = "The COLING 2016 Organizing Committee",
29
+ url = "https://aclanthology.org/W16-5207",
30
+ pages = "51--55",
31
+ }
32
+ """
33
+
34
+ _DESCRIPTION = """\
35
+ VIVOS is a free Vietnamese speech corpus consisting of 15 hours of recording speech prepared for
36
+ Vietnamese Automatic Speech Recognition task.
37
+ The corpus was prepared by AILAB, a computer science lab of VNUHCM - University of Science, with Prof. Vu Hai Quan is the head of.
38
+ We publish this corpus in hope to attract more scientists to solve Vietnamese speech recognition problems.
39
+ """
40
+
41
+ _HOMEPAGE = "https://doi.org/10.5281/zenodo.7068130"
42
+
43
+ _LICENSE = "CC BY-NC-SA 4.0"
44
+
45
+ _DATA_URL = "https://zenodo.org/record/7068130/files/vivos.tar.gz"
46
+
47
+ _PROMPTS_URLS = {
48
+ "train": "https://s3.amazonaws.com/datasets.huggingface.co/vivos/train/prompts.txt",
49
+ "test": "https://s3.amazonaws.com/datasets.huggingface.co/vivos/test/prompts.txt",
50
+ }
51
+
52
+
53
+ class VivosDataset(datasets.GeneratorBasedBuilder):
54
+ """VIVOS is a free Vietnamese speech corpus consisting of 15 hours of recording speech prepared for
55
+ Vietnamese Automatic Speech Recognition task."""
56
+
57
+ VERSION = datasets.Version("1.1.0")
58
+
59
+ # This is an example of a dataset with multiple configurations.
60
+ # If you don't want/need to define several sub-sets in your dataset,
61
+ # just remove the BUILDER_CONFIG_CLASS and the BUILDER_CONFIGS attributes.
62
+
63
+ # If you need to make complex sub-parts in the datasets with configurable options
64
+ # You can create your own builder configuration class to store attribute, inheriting from datasets.BuilderConfig
65
+ # BUILDER_CONFIG_CLASS = MyBuilderConfig
66
+
67
+ def _info(self):
68
+ return datasets.DatasetInfo(
69
+ # This is the description that will appear on the datasets page.
70
+ description=_DESCRIPTION,
71
+ features=datasets.Features(
72
+ {
73
+ "speaker_id": datasets.Value("string"),
74
+ "path": datasets.Value("string"),
75
+ "audio": datasets.Audio(sampling_rate=16_000),
76
+ "sentence": datasets.Value("string"),
77
+ }
78
+ ),
79
+ supervised_keys=None,
80
+ homepage=_HOMEPAGE,
81
+ license=_LICENSE,
82
+ citation=_CITATION,
83
+ )
84
+
85
+ def _split_generators(self, dl_manager):
86
+ """Returns SplitGenerators."""
87
+ # If several configurations are possible (listed in BUILDER_CONFIGS), the configuration selected by the user is in self.config.name
88
+
89
+ # dl_manager is a datasets.download.DownloadManager that can be used to download and extract URLs
90
+ # It can accept any type or nested list/dict and will give back the same structure with the url replaced with path to local files.
91
+ # By default the archives will be extracted and a path to a cached folder where they are extracted is returned instead of the archive
92
+ prompts_paths = dl_manager.download(_PROMPTS_URLS)
93
+ archive = dl_manager.download(_DATA_URL)
94
+ train_dir = "vivos/train"
95
+ test_dir = "vivos/test"
96
+
97
+ return [
98
+ datasets.SplitGenerator(
99
+ name=datasets.Split.TRAIN,
100
+ # These kwargs will be passed to _generate_examples
101
+ gen_kwargs={
102
+ "prompts_path": prompts_paths["train"],
103
+ "path_to_clips": train_dir + "/waves",
104
+ "audio_files": dl_manager.iter_archive(archive),
105
+ },
106
+ ),
107
+ datasets.SplitGenerator(
108
+ name=datasets.Split.TEST,
109
+ # These kwargs will be passed to _generate_examples
110
+ gen_kwargs={
111
+ "prompts_path": prompts_paths["test"],
112
+ "path_to_clips": test_dir + "/waves",
113
+ "audio_files": dl_manager.iter_archive(archive),
114
+ },
115
+ ),
116
+ ]
117
+
118
+ def _generate_examples(self, prompts_path, path_to_clips, audio_files):
119
+ """Yields examples as (key, example) tuples."""
120
+ # This method handles input defined in _split_generators to yield (key, example) tuples from the dataset.
121
+ # The `key` is here for legacy reason (tfds) and is not important in itself.
122
+ examples = {}
123
+ with open(prompts_path, encoding="utf-8") as f:
124
+ for row in f:
125
+ data = row.strip().split(" ", 1)
126
+ speaker_id = data[0].split("_")[0]
127
+ audio_path = "/".join([path_to_clips, speaker_id, data[0] + ".wav"])
128
+ examples[audio_path] = {
129
+ "speaker_id": speaker_id,
130
+ "path": audio_path,
131
+ "sentence": data[1],
132
+ }
133
+ inside_clips_dir = False
134
+ id_ = 0
135
+ for path, f in audio_files:
136
+ if path.startswith(path_to_clips):
137
+ inside_clips_dir = True
138
+ if path in examples:
139
+ audio = {"path": path, "bytes": f.read()}
140
+ yield id_, {**examples[path], "audio": audio}
141
+ id_ += 1
142
+ elif inside_clips_dir:
143
+ break