nakkhatra commited on
Commit
4e3d9ff
1 Parent(s): bbb24cb
Files changed (2) hide show
  1. common_voice.py +0 -290
  2. dataset_infos.json +0 -133
common_voice.py DELETED
@@ -1,290 +0,0 @@
1
- # coding=utf-8
2
- # Copyright 2021 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
- """ Common Voice Dataset"""
16
-
17
-
18
- import os
19
-
20
- import datasets
21
- from datasets.tasks import AutomaticSpeechRecognition
22
-
23
-
24
- _DATA_URL = "https://voice-prod-bundler-ee1969a6ce8178826482b88e843c335139bd3fb4.s3.amazonaws.com/cv-corpus-6.1-2020-12-11/{}.tar.gz"
25
-
26
- _CITATION = """\
27
- @inproceedings{commonvoice:2020,
28
- author = {Ardila, R. and Branson, M. and Davis, K. and Henretty, M. and Kohler, M. and Meyer, J. and Morais, R. and Saunders, L. and Tyers, F. M. and Weber, G.},
29
- title = {Common Voice: A Massively-Multilingual Speech Corpus},
30
- booktitle = {Proceedings of the 12th Conference on Language Resources and Evaluation (LREC 2020)},
31
- pages = {4211--4215},
32
- year = 2020
33
- }
34
- """
35
-
36
- _DESCRIPTION = """\
37
- Common Voice is Mozilla's initiative to help teach machines how real people speak.
38
- The dataset currently consists of 7,335 validated hours of speech in 60 languages, but we’re always adding more voices and languages.
39
- """
40
-
41
- _HOMEPAGE = "https://commonvoice.mozilla.org/bn/datasets"
42
-
43
- _LICENSE = "https://github.com/common-voice/common-voice/blob/main/LICENSE"
44
-
45
- _LANGUAGES = {
46
- "bn": {
47
- "Language": "Bengali",
48
- "Date": "2022-04-27",
49
- "Size": "8 GB",
50
- "Version": "bn_399h_2022-04-27",
51
- "Validated_Hr_Total": 56,
52
- "Overall_Hr_Total": 399,
53
- "Number_Of_Voice": 19863,
54
- },
55
- }
56
-
57
-
58
- class CommonVoiceConfig(datasets.BuilderConfig):
59
- """BuilderConfig for CommonVoice."""
60
-
61
- def __init__(self, name, sub_version, **kwargs):
62
- """
63
- Args:
64
- data_dir: `string`, the path to the folder containing the files in the
65
- downloaded .tar
66
- citation: `string`, citation for the data set
67
- url: `string`, url for information about the data set
68
- **kwargs: keyword arguments forwarded to super.
69
- """
70
- self.sub_version = sub_version
71
- self.language = kwargs.pop("language", None)
72
- self.date_of_snapshot = kwargs.pop("date", None)
73
- self.size = kwargs.pop("size", None)
74
- self.validated_hr_total = kwargs.pop("val_hrs", None)
75
- self.total_hr_total = kwargs.pop("total_hrs", None)
76
- self.num_of_voice = kwargs.pop("num_of_voice", None)
77
- description = f"Common Voice speech to text dataset in {self.language} version {self.sub_version} of {self.date_of_snapshot}. The dataset comprises {self.validated_hr_total} of validated transcribed speech data from {self.num_of_voice} speakers. The dataset has a size of {self.size}"
78
- super(CommonVoiceConfig, self).__init__(
79
- name=name,
80
- version=datasets.Version("6.1.0", ""),
81
- description=description,
82
- **kwargs,
83
- )
84
-
85
-
86
- class CommonVoice(datasets.GeneratorBasedBuilder):
87
-
88
- DEFAULT_WRITER_BATCH_SIZE = 1000
89
- BUILDER_CONFIGS = [
90
- CommonVoiceConfig(
91
- name=lang_id,
92
- language=_LANGUAGES[lang_id]["Language"],
93
- sub_version=_LANGUAGES[lang_id]["Version"],
94
- date=_LANGUAGES[lang_id]["Date"],
95
- size=_LANGUAGES[lang_id]["Size"],
96
- val_hrs=_LANGUAGES[lang_id]["Validated_Hr_Total"],
97
- total_hrs=_LANGUAGES[lang_id]["Overall_Hr_Total"],
98
- num_of_voice=_LANGUAGES[lang_id]["Number_Of_Voice"],
99
- )
100
- for lang_id in _LANGUAGES.keys()
101
- ]
102
-
103
- def _info(self):
104
- features = datasets.Features(
105
- {
106
- "client_id": datasets.Value("string"),
107
- "path": datasets.Value("string"),
108
- "audio": datasets.Audio(sampling_rate=48_000),
109
- "sentence": datasets.Value("string"),
110
- "up_votes": datasets.Value("int64"),
111
- "down_votes": datasets.Value("int64"),
112
- "age": datasets.Value("string"),
113
- "gender": datasets.Value("string"),
114
- "accent": datasets.Value("string"),
115
- "locale": datasets.Value("string"),
116
- "segment": datasets.Value("string"),
117
- }
118
- )
119
-
120
- return datasets.DatasetInfo(
121
- description=_DESCRIPTION,
122
- features=features,
123
- supervised_keys=None,
124
- homepage=_HOMEPAGE,
125
- license=_LICENSE,
126
- citation=_CITATION,
127
- task_templates=[
128
- AutomaticSpeechRecognition(
129
- audio_column="audio", transcription_column="sentence"
130
- )
131
- ],
132
- )
133
-
134
- def _split_generators(self, dl_manager):
135
- """Returns SplitGenerators."""
136
- # Download the TAR archive that contains the audio files:
137
- archive_path = dl_manager.download(_DATA_URL.format(self.config.name))
138
-
139
- # First we locate the data using the path within the archive:
140
- path_to_data = "/".join(["cv-corpus-6.1-2020-12-11", self.config.name])
141
- path_to_clips = "/".join([path_to_data, "clips"])
142
- metadata_filepaths = {
143
- split: "/".join([path_to_data, f"{split}.tsv"])
144
- for split in ["train", "test", "dev", "other", "validated", "invalidated"]
145
- }
146
- # (Optional) In non-streaming mode, we can extract the archive locally to have actual local audio files:
147
- local_extracted_archive = (
148
- dl_manager.extract(archive_path) if not dl_manager.is_streaming else None
149
- )
150
-
151
- # To access the audio data from the TAR archives using the download manager,
152
- # we have to use the dl_manager.iter_archive method.
153
- #
154
- # This is because dl_manager.download_and_extract
155
- # doesn't work to stream TAR archives in streaming mode.
156
- # (we have to stream the files of a TAR archive one by one)
157
- #
158
- # The iter_archive method returns an iterable of (path_within_archive, file_obj) for every
159
- # file in the TAR archive.
160
-
161
- return [
162
- datasets.SplitGenerator(
163
- name=datasets.Split.TRAIN,
164
- gen_kwargs={
165
- "local_extracted_archive": local_extracted_archive,
166
- "archive_iterator": dl_manager.iter_archive(
167
- archive_path
168
- ), # use iter_archive here to access the files in the TAR archives
169
- "metadata_filepath": metadata_filepaths["train"],
170
- "path_to_clips": path_to_clips,
171
- },
172
- ),
173
- datasets.SplitGenerator(
174
- name=datasets.Split.TEST,
175
- gen_kwargs={
176
- "local_extracted_archive": local_extracted_archive,
177
- "archive_iterator": dl_manager.iter_archive(
178
- archive_path
179
- ), # use iter_archive here to access the files in the TAR archives
180
- "metadata_filepath": metadata_filepaths["test"],
181
- "path_to_clips": path_to_clips,
182
- },
183
- ),
184
- datasets.SplitGenerator(
185
- name=datasets.Split.VALIDATION,
186
- gen_kwargs={
187
- "local_extracted_archive": local_extracted_archive,
188
- "archive_iterator": dl_manager.iter_archive(
189
- archive_path
190
- ), # use iter_archive here to access the files in the TAR archives
191
- "metadata_filepath": metadata_filepaths["dev"],
192
- "path_to_clips": path_to_clips,
193
- },
194
- ),
195
- datasets.SplitGenerator(
196
- name="other",
197
- gen_kwargs={
198
- "local_extracted_archive": local_extracted_archive,
199
- "archive_iterator": dl_manager.iter_archive(
200
- archive_path
201
- ), # use iter_archive here to access the files in the TAR archives
202
- "metadata_filepath": metadata_filepaths["other"],
203
- "path_to_clips": path_to_clips,
204
- },
205
- ),
206
- datasets.SplitGenerator(
207
- name="validated",
208
- gen_kwargs={
209
- "local_extracted_archive": local_extracted_archive,
210
- "archive_iterator": dl_manager.iter_archive(
211
- archive_path
212
- ), # use iter_archive here to access the files in the TAR archives
213
- "metadata_filepath": metadata_filepaths["validated"],
214
- "path_to_clips": path_to_clips,
215
- },
216
- ),
217
- datasets.SplitGenerator(
218
- name="invalidated",
219
- gen_kwargs={
220
- "local_extracted_archive": local_extracted_archive,
221
- "archive_iterator": dl_manager.iter_archive(
222
- archive_path
223
- ), # use iter_archive here to access the files in the TAR archives
224
- "metadata_filepath": metadata_filepaths["invalidated"],
225
- "path_to_clips": path_to_clips,
226
- },
227
- ),
228
- ]
229
-
230
- def _generate_examples(
231
- self,
232
- local_extracted_archive,
233
- archive_iterator,
234
- metadata_filepath,
235
- path_to_clips,
236
- ):
237
- """Yields examples."""
238
- data_fields = list(self._info().features.keys())
239
-
240
- # audio is not a header of the csv files
241
- data_fields.remove("audio")
242
- path_idx = data_fields.index("path")
243
-
244
- all_field_values = {}
245
- metadata_found = False
246
- # Here we iterate over all the files within the TAR archive:
247
- for path, f in archive_iterator:
248
- # Parse the metadata CSV file
249
- if path == metadata_filepath:
250
- metadata_found = True
251
- lines = f.readlines()
252
- headline = lines[0].decode("utf-8")
253
-
254
- column_names = headline.strip().split("\t")
255
- assert (
256
- column_names == data_fields
257
- ), f"The file should have {data_fields} as column names, but has {column_names}"
258
- for line in lines[1:]:
259
- field_values = line.decode("utf-8").strip().split("\t")
260
- # set full path for mp3 audio file
261
- audio_path = "/".join([path_to_clips, field_values[path_idx]])
262
- all_field_values[audio_path] = field_values
263
- # Else, read the audio file and yield an example
264
- elif path.startswith(path_to_clips):
265
- assert metadata_found, "Found audio clips before the metadata TSV file."
266
- if not all_field_values:
267
- break
268
- if path in all_field_values:
269
- # retrieve the metadata corresponding to this audio file
270
- field_values = all_field_values[path]
271
-
272
- # if data is incomplete, fill with empty values
273
- if len(field_values) < len(data_fields):
274
- field_values += (len(data_fields) - len(field_values)) * ["''"]
275
-
276
- result = {
277
- key: value for key, value in zip(data_fields, field_values)
278
- }
279
-
280
- # set audio feature
281
- path = (
282
- os.path.join(local_extracted_archive, path)
283
- if local_extracted_archive
284
- else path
285
- )
286
- result["audio"] = {"path": path, "bytes": f.read()}
287
- # set path to None if the audio file doesn't exist locally (i.e. in streaming mode)
288
- result["path"] = path if local_extracted_archive else None
289
-
290
- yield path, result
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
dataset_infos.json DELETED
@@ -1,133 +0,0 @@
1
- {
2
- "bn": {
3
- "description": "Common Voice is Mozilla's initiative to help teach machines how real people speak.\nThe dataset currently consists of 7,335 validated hours of speech in 60 languages, but we\u2019re always adding more voices and languages.\n",
4
- "citation": "@inproceedings{commonvoice:2020,\n author = {Samiul Alam, Asif Sushmit, Zaowad Abdullah, Md. Shahrin Nakkhatra, Md. N. Ansary, Syed Mobassir Hossen, Tahsin Reasat, L. and Tyers, F. M. and Weber, G.},\n title = {Common Voice: A Massively-Multilingual Speech Corpus},\n booktitle = {Proceedings of the 12th Conference on Language Resources and Evaluation (LREC 2020)},\n pages = {4211--4215},\n year = 2020\n}\n",
5
- "homepage": "https://commonvoice.mozilla.org/bn/datasets",
6
- "license": "https://github.com/common-voice/common-voice/blob/main/LICENSE",
7
- "features": {
8
- "client_id": {
9
- "dtype": "string",
10
- "id": null,
11
- "_type": "Value"
12
- },
13
- "path": {
14
- "dtype": "string",
15
- "id": null,
16
- "_type": "Value"
17
- },
18
- "audio": {
19
- "sampling_rate": 48000,
20
- "mono": true,
21
- "decode": true,
22
- "id": null,
23
- "_type": "Audio"
24
- },
25
- "sentence": {
26
- "dtype": "string",
27
- "id": null,
28
- "_type": "Value"
29
- },
30
- "up_votes": {
31
- "dtype": "int64",
32
- "id": null,
33
- "_type": "Value"
34
- },
35
- "down_votes": {
36
- "dtype": "int64",
37
- "id": null,
38
- "_type": "Value"
39
- },
40
- "age": {
41
- "dtype": "string",
42
- "id": null,
43
- "_type": "Value"
44
- },
45
- "gender": {
46
- "dtype": "string",
47
- "id": null,
48
- "_type": "Value"
49
- },
50
- "accent": {
51
- "dtype": "string",
52
- "id": null,
53
- "_type": "Value"
54
- },
55
- "locale": {
56
- "dtype": "string",
57
- "id": null,
58
- "_type": "Value"
59
- },
60
- "segment": {
61
- "dtype": "string",
62
- "id": null,
63
- "_type": "Value"
64
- }
65
- },
66
- "post_processed": null,
67
- "supervised_keys": null,
68
- "task_templates": [
69
- {
70
- "task": "automatic-speech-recognition",
71
- "audio_file_path_column": "path",
72
- "transcription_column": "sentence"
73
- }
74
- ],
75
- "builder_name": "common_voice",
76
- "config_name": "en",
77
- "version": {
78
- "version_str": "6.1.0",
79
- "description": "",
80
- "major": 6,
81
- "minor": 1,
82
- "patch": 0
83
- },
84
- "splits": {
85
- "train": {
86
- "name": "train",
87
- "num_bytes": 26088826658,
88
- "num_examples": 564337,
89
- "dataset_name": "common_voice"
90
- },
91
- "test": {
92
- "name": "test",
93
- "num_bytes": 758718688,
94
- "num_examples": 16164,
95
- "dataset_name": "common_voice"
96
- },
97
- "validation": {
98
- "name": "validation",
99
- "num_bytes": 795638801,
100
- "num_examples": 16164,
101
- "dataset_name": "common_voice"
102
- },
103
- "other": {
104
- "name": "other",
105
- "num_bytes": 5796244022,
106
- "num_examples": 169895,
107
- "dataset_name": "common_voice"
108
- },
109
- "validated": {
110
- "name": "validated",
111
- "num_bytes": 48425872575,
112
- "num_examples": 1224864,
113
- "dataset_name": "common_voice"
114
- },
115
- "invalidated": {
116
- "name": "invalidated",
117
- "num_bytes": 9122973965,
118
- "num_examples": 189562,
119
- "dataset_name": "common_voice"
120
- }
121
- },
122
- "download_checksums": {
123
- "https://voice-prod-bundler-ee1969a6ce8178826482b88e843c335139bd3fb4.s3.amazonaws.com/cv-corpus-6.1-2020-12-11/en.tar.gz": {
124
- "num_bytes": 60613063630,
125
- "checksum": "0f8fdfc4fe715738be94ee49c4fb63d5f1608d2e6a43a2bed80f6cb871171c36"
126
- }
127
- },
128
- "download_size": 60613063630,
129
- "post_processing_size": null,
130
- "dataset_size": 90988274709,
131
- "size_in_bytes": 151601338339
132
- }
133
- }