[Update] Update
Browse files- custom_common_voice.py +76 -44
- dataset_infos.json +2 -2
custom_common_voice.py
CHANGED
@@ -20,6 +20,11 @@ from datasets.tasks import AutomaticSpeechRecognition
|
|
20 |
|
21 |
|
22 |
_DATA_URL = "https://drive.google.com/uc?export=download&id=18ssh3gjpsMmjBfaIhcCwrfJMAvsdLGaI"
|
|
|
|
|
|
|
|
|
|
|
23 |
|
24 |
_DESCRIPTION = """\
|
25 |
Common Voice is Mozilla's initiative to help teach machines how real people speak.
|
@@ -88,9 +93,9 @@ class CustomCommonVoice(datasets.GeneratorBasedBuilder):
|
|
88 |
features = datasets.Features(
|
89 |
{
|
90 |
"file_path": datasets.Value("string"),
|
91 |
-
"audio": datasets.Audio(sampling_rate=16_000),
|
92 |
"script": datasets.Value("string"),
|
93 |
-
"duration": datasets.Value("float16")
|
|
|
94 |
}
|
95 |
)
|
96 |
|
@@ -105,6 +110,7 @@ class CustomCommonVoice(datasets.GeneratorBasedBuilder):
|
|
105 |
|
106 |
def _split_generators(self, dl_manager):
|
107 |
"""Returns SplitGenerators."""
|
|
|
108 |
archive = dl_manager.download(_DATA_URL)
|
109 |
path_to_data = "data_1"
|
110 |
path_to_clips = path_to_data + "/" + "audio"
|
@@ -114,24 +120,24 @@ class CustomCommonVoice(datasets.GeneratorBasedBuilder):
|
|
114 |
datasets.SplitGenerator(
|
115 |
name=datasets.Split.TRAIN,
|
116 |
gen_kwargs={
|
117 |
-
"
|
118 |
-
"
|
119 |
"path_to_clips": path_to_clips,
|
120 |
},
|
121 |
),
|
122 |
datasets.SplitGenerator(
|
123 |
name=datasets.Split.TEST,
|
124 |
gen_kwargs={
|
125 |
-
"
|
126 |
-
"
|
127 |
"path_to_clips": path_to_clips,
|
128 |
},
|
129 |
),
|
130 |
datasets.SplitGenerator(
|
131 |
name=datasets.Split.VALIDATION,
|
132 |
gen_kwargs={
|
133 |
-
"
|
134 |
-
"
|
135 |
"path_to_clips": path_to_clips,
|
136 |
},
|
137 |
),
|
@@ -153,45 +159,71 @@ class CustomCommonVoice(datasets.GeneratorBasedBuilder):
|
|
153 |
# ),
|
154 |
]
|
155 |
|
156 |
-
def _generate_examples(self,
|
157 |
"""Yields examples."""
|
158 |
data_fields = list(self._info().features.keys())
|
159 |
|
160 |
# audio is not a header of the csv files
|
161 |
data_fields.remove("audio")
|
162 |
path_idx = data_fields.index("file_path")
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
if path in
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
|
22 |
_DATA_URL = "https://drive.google.com/uc?export=download&id=18ssh3gjpsMmjBfaIhcCwrfJMAvsdLGaI"
|
23 |
+
_PROMPTS_URLS = {
|
24 |
+
"train": "https://drive.google.com/uc?export=download&id=1fHl3UuM73AGdTmOuTSRRSDnDxPiNBZas",
|
25 |
+
"test": "https://drive.google.com/uc?export=download&id=1MoBJsfIvjfSnYXApiIqtnMV3z0u0o2UZ",
|
26 |
+
"val": "https://drive.google.com/uc?export=download&id=1V8M437ncD6ogE-e56OipMPuuFqLgEt5g",
|
27 |
+
}
|
28 |
|
29 |
_DESCRIPTION = """\
|
30 |
Common Voice is Mozilla's initiative to help teach machines how real people speak.
|
|
|
93 |
features = datasets.Features(
|
94 |
{
|
95 |
"file_path": datasets.Value("string"),
|
|
|
96 |
"script": datasets.Value("string"),
|
97 |
+
"duration": datasets.Value("float16"),
|
98 |
+
"audio": datasets.Audio(sampling_rate=16_000),
|
99 |
}
|
100 |
)
|
101 |
|
|
|
110 |
|
111 |
def _split_generators(self, dl_manager):
|
112 |
"""Returns SplitGenerators."""
|
113 |
+
tsv_files = dl_manager.download(_PROMPTS_URLS)
|
114 |
archive = dl_manager.download(_DATA_URL)
|
115 |
path_to_data = "data_1"
|
116 |
path_to_clips = path_to_data + "/" + "audio"
|
|
|
120 |
datasets.SplitGenerator(
|
121 |
name=datasets.Split.TRAIN,
|
122 |
gen_kwargs={
|
123 |
+
"tsv_files": tsv_files["train"],
|
124 |
+
"audio_files": dl_manager.iter_archive(archive),
|
125 |
"path_to_clips": path_to_clips,
|
126 |
},
|
127 |
),
|
128 |
datasets.SplitGenerator(
|
129 |
name=datasets.Split.TEST,
|
130 |
gen_kwargs={
|
131 |
+
"tsv_files": tsv_files["test"],
|
132 |
+
"audio_files": dl_manager.iter_archive(archive),
|
133 |
"path_to_clips": path_to_clips,
|
134 |
},
|
135 |
),
|
136 |
datasets.SplitGenerator(
|
137 |
name=datasets.Split.VALIDATION,
|
138 |
gen_kwargs={
|
139 |
+
"tsv_files": tsv_files["val"],
|
140 |
+
"audio_files": dl_manager.iter_archive(archive),
|
141 |
"path_to_clips": path_to_clips,
|
142 |
},
|
143 |
),
|
|
|
159 |
# ),
|
160 |
]
|
161 |
|
162 |
+
def _generate_examples(self, tsv_files, audio_files, path_to_clips):
|
163 |
"""Yields examples."""
|
164 |
data_fields = list(self._info().features.keys())
|
165 |
|
166 |
# audio is not a header of the csv files
|
167 |
data_fields.remove("audio")
|
168 |
path_idx = data_fields.index("file_path")
|
169 |
+
script_idx = data_fields.index("script")
|
170 |
+
duration_idx = data_fields.index("duration")
|
171 |
+
examples = {}
|
172 |
+
|
173 |
+
with open(tsv_files, encoding="utf-8") as f:
|
174 |
+
lines = f.readlines()
|
175 |
+
for line in lines[1:]:
|
176 |
+
field_values = line.strip().split("\t")
|
177 |
+
# set full path for mp3 audio file
|
178 |
+
audio_path = path_to_clips + "/" + field_values[path_idx]
|
179 |
+
script = field_values[script_idx]
|
180 |
+
duration = field_values[duration_idx]
|
181 |
+
examples[audio_path] = {
|
182 |
+
"file_path": audio_path,
|
183 |
+
"script": script,
|
184 |
+
"duration": duration,
|
185 |
+
}
|
186 |
+
|
187 |
+
inside_clips_dir = False
|
188 |
+
for path, f in audio_files:
|
189 |
+
if path.startswith(path_to_clips):
|
190 |
+
inside_clips_dir = True
|
191 |
+
if path in examples:
|
192 |
+
audio = {"path": path, "bytes": f.read()}
|
193 |
+
yield path, {**examples[path], "audio": audio}
|
194 |
+
elif "custom_common_voice.tsv" in path:
|
195 |
+
continue
|
196 |
+
elif inside_clips_dir:
|
197 |
+
break
|
198 |
+
|
199 |
+
# for path, f in tsv_files:
|
200 |
+
# if path == filepath:
|
201 |
+
# metadata_found = True
|
202 |
+
# lines = f.readlines()
|
203 |
+
# headline = lines[0]
|
204 |
+
# column_names = headline.strip().split("\t")
|
205 |
+
# assert (
|
206 |
+
# column_names == data_fields
|
207 |
+
# ), f"The file should have {data_fields} as column names, but has {column_names}"
|
208 |
+
# for line in lines[1:]:
|
209 |
+
# field_values = line.strip().split("\t")
|
210 |
+
# # set full path for mp3 audio file
|
211 |
+
# audio_path = path_to_clips + "/" + field_values[path_idx]
|
212 |
+
# all_field_values[audio_path] = field_values
|
213 |
+
# elif path.startswith(path_to_clips):
|
214 |
+
# assert metadata_found, "Found audio clips before the metadata TSV file."
|
215 |
+
# if not all_field_values:
|
216 |
+
# break
|
217 |
+
# if path in all_field_values:
|
218 |
+
# field_values = all_field_values[path]
|
219 |
+
#
|
220 |
+
# # if data is incomplete, fill with empty values
|
221 |
+
# if len(field_values) < len(data_fields):
|
222 |
+
# field_values += (len(data_fields) - len(field_values)) * ["''"]
|
223 |
+
#
|
224 |
+
# result = {key: value for key, value in zip(data_fields, field_values)}
|
225 |
+
#
|
226 |
+
# # set audio feature
|
227 |
+
# result["audio"] = {"path": path, "bytes": f.read()}
|
228 |
+
#
|
229 |
+
# yield path, result
|
dataset_infos.json
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:1c1212eec1244b86866c405471bd61fdf16ce43e8e52b3a1c3d6ed60278542e0
|
3 |
+
size 1659
|