Raziullah commited on
Commit
57523ff
·
1 Parent(s): 4857a4d

Delete common_voice_extracted.py

Browse files
Files changed (1) hide show
  1. common_voice_extracted.py +0 -169
common_voice_extracted.py DELETED
@@ -1,169 +0,0 @@
1
- import csv
2
- import os
3
- import json
4
-
5
- import datasets
6
- from datasets.utils.py_utils import size_str
7
- from tqdm import tqdm
8
-
9
- from .languages import LANGUAGES
10
- from .release_stats import STATS
11
-
12
-
13
-
14
-
15
-
16
-
17
-
18
- # TODO: change "streaming" to "main" after merge!
19
- _BASE_URL = "https://huggingface.co/datasets/Raziullah/dv_finetune_common_voice_13/tree/main/"
20
-
21
- _AUDIO_URL = _BASE_URL + "audio/{lang}/{split}/{lang}_{split}_{shard_idx}.tar"
22
-
23
- _TRANSCRIPT_URL = _BASE_URL + "transcript/{lang}/{split}.tsv"
24
-
25
- _N_SHARDS_URL = _BASE_URL + "n_shards.json"
26
-
27
-
28
- class CommonVoiceConfig(datasets.BuilderConfig):
29
- """BuilderConfig for CommonVoice."""
30
-
31
- def __init__(self, name, version, **kwargs):
32
- self.language = kwargs.pop("language", None)
33
- self.release_date = kwargs.pop("release_date", None)
34
- self.num_clips = kwargs.pop("num_clips", None)
35
- self.num_speakers = kwargs.pop("num_speakers", None)
36
- self.validated_hr = kwargs.pop("validated_hr", None)
37
- self.total_hr = kwargs.pop("total_hr", None)
38
- self.size_bytes = kwargs.pop("size_bytes", None)
39
- self.size_human = size_str(self.size_bytes)
40
- description = (
41
- f"Common Voice speech to text dataset in {self.language} released on {self.release_date}. "
42
- f"The dataset comprises {self.validated_hr} hours of validated transcribed speech data "
43
- f"out of {self.total_hr} hours in total from {self.num_speakers} speakers. "
44
- f"The dataset contains {self.num_clips} audio clips and has a size of {self.size_human}."
45
- )
46
- super(CommonVoiceConfig, self).__init__(
47
- name=name,
48
- version=datasets.Version(version),
49
- description=description,
50
- **kwargs,
51
- )
52
-
53
-
54
- class CommonVoice(datasets.GeneratorBasedBuilder):
55
- DEFAULT_WRITER_BATCH_SIZE = 1000
56
-
57
- BUILDER_CONFIGS = [
58
- CommonVoiceConfig(
59
- name=lang,
60
- version=STATS["version"],
61
- language=LANGUAGES[lang],
62
- release_date=STATS["date"],
63
- num_clips=lang_stats["clips"],
64
- num_speakers=lang_stats["users"],
65
- validated_hr=float(lang_stats["validHrs"]) if lang_stats["validHrs"] else None,
66
- total_hr=float(lang_stats["totalHrs"]) if lang_stats["totalHrs"] else None,
67
- size_bytes=int(lang_stats["size"]) if lang_stats["size"] else None,
68
- )
69
- for lang, lang_stats in STATS["locales"].items()
70
- ]
71
-
72
- def _info(self):
73
- total_languages = len(STATS["locales"])
74
- total_valid_hours = STATS["totalValidHrs"]
75
- description = (
76
- "Common Voice is Mozilla's initiative to help teach machines how real people speak. "
77
- f"The dataset currently consists of {total_valid_hours} validated hours of speech "
78
- f" in {total_languages} languages, but more voices and languages are always added."
79
- )
80
- features = datasets.Features(
81
- {
82
- "client_id": datasets.Value("string"),
83
- "path": datasets.Value("string"),
84
- "audio": datasets.features.Audio(sampling_rate=48_000),
85
- "sentence": datasets.Value("string"),
86
- "up_votes": datasets.Value("int64"),
87
- "down_votes": datasets.Value("int64"),
88
- "age": datasets.Value("string"),
89
- "gender": datasets.Value("string"),
90
- "accent": datasets.Value("string"),
91
- "locale": datasets.Value("string"),
92
- "segment": datasets.Value("string"),
93
- "variant": datasets.Value("string"),
94
- }
95
- )
96
-
97
- return datasets.DatasetInfo(
98
- description=description,
99
- features=features,
100
- supervised_keys=None,
101
- version=self.config.version,
102
- )
103
-
104
- def _split_generators(self, dl_manager):
105
- lang = self.config.name
106
- n_shards_path = dl_manager.download_and_extract(_N_SHARDS_URL)
107
- with open(n_shards_path, encoding="utf-8") as f:
108
- n_shards = json.load(f)
109
-
110
- audio_urls = {}
111
- splits = ("train", "dev", "test", "other", "invalidated")
112
- for split in splits:
113
- audio_urls[split] = [
114
- _AUDIO_URL.format(lang=lang, split=split, shard_idx=i) for i in range(n_shards[lang][split])
115
- ]
116
- archive_paths = dl_manager.download(audio_urls)
117
- local_extracted_archive_paths = dl_manager.extract(archive_paths) if not dl_manager.is_streaming else {}
118
-
119
- meta_urls = {split: _TRANSCRIPT_URL.format(lang=lang, split=split) for split in splits}
120
- meta_paths = dl_manager.download_and_extract(meta_urls)
121
-
122
- split_generators = []
123
- split_names = {
124
- "train": datasets.Split.TRAIN,
125
- "dev": datasets.Split.VALIDATION,
126
- "test": datasets.Split.TEST,
127
- }
128
- for split in splits:
129
- split_generators.append(
130
- datasets.SplitGenerator(
131
- name=split_names.get(split, split),
132
- gen_kwargs={
133
- "local_extracted_archive_paths": local_extracted_archive_paths.get(split),
134
- "archives": [dl_manager.iter_archive(path) for path in archive_paths.get(split)],
135
- "meta_path": meta_paths[split],
136
- },
137
- ),
138
- )
139
-
140
- return split_generators
141
-
142
- def _generate_examples(self, local_extracted_archive_paths, archives, meta_path):
143
- data_fields = list(self._info().features.keys())
144
- metadata = {}
145
- with open(meta_path, encoding="utf-8") as f:
146
- reader = csv.DictReader(f, delimiter="\t", quoting=csv.QUOTE_NONE)
147
- for row in tqdm(reader, desc="Reading metadata..."):
148
- if not row["path"].endswith(".mp3"):
149
- row["path"] += ".mp3"
150
- # accent -> accents in CV 8.0
151
- if "accents" in row:
152
- row["accent"] = row["accents"]
153
- del row["accents"]
154
- # if data is incomplete, fill with empty values
155
- for field in data_fields:
156
- if field not in row:
157
- row[field] = ""
158
- metadata[row["path"]] = row
159
-
160
- for i, audio_archive in enumerate(archives):
161
- for path, file in audio_archive:
162
- _, filename = os.path.split(path)
163
- if filename in metadata:
164
- result = dict(metadata[filename])
165
- # set the audio feature and the path to the extracted file
166
- path = os.path.join(local_extracted_archive_paths[i], path) if local_extracted_archive_paths else path
167
- result["audio"] = {"path": path, "bytes": file.read()}
168
- result["path"] = path
169
- yield path, result