Le Viet Hoang
commited on
Commit
·
67e6cc8
1
Parent(s):
296c5a5
fix
Browse files
VBVLSP.py
CHANGED
|
@@ -36,10 +36,10 @@ class CommonVoice(datasets.GeneratorBasedBuilder):
|
|
| 36 |
DEFAULT_WRITER_BATCH_SIZE = 1000
|
| 37 |
|
| 38 |
def _split_generators(self, dl_manager):
|
| 39 |
-
splits = ("train",
|
| 40 |
audio_url = _AUDIO_URL
|
| 41 |
archive_path = dl_manager.download(audio_url)
|
| 42 |
-
local_extracted_archive_path = dl_manager.extract(
|
| 43 |
|
| 44 |
meta_urls = {split: _TRANSCRIPT_URL.format(split=split) for split in splits}
|
| 45 |
meta_paths = dl_manager.download_and_extract(meta_urls)
|
|
@@ -55,8 +55,8 @@ class CommonVoice(datasets.GeneratorBasedBuilder):
|
|
| 55 |
datasets.SplitGenerator(
|
| 56 |
name=split_names.get(split, split),
|
| 57 |
gen_kwargs={
|
| 58 |
-
"
|
| 59 |
-
"
|
| 60 |
"meta_path": meta_paths[split],
|
| 61 |
},
|
| 62 |
),
|
|
@@ -64,7 +64,7 @@ class CommonVoice(datasets.GeneratorBasedBuilder):
|
|
| 64 |
|
| 65 |
return split_generators
|
| 66 |
|
| 67 |
-
def _generate_examples(self,
|
| 68 |
data_fields = list(self._info().features.keys())
|
| 69 |
metadata = {}
|
| 70 |
with open(meta_path, encoding="utf-8") as f:
|
|
@@ -77,7 +77,7 @@ class CommonVoice(datasets.GeneratorBasedBuilder):
|
|
| 77 |
metadata[row["file_path"]] = row
|
| 78 |
|
| 79 |
|
| 80 |
-
for filename, file in
|
| 81 |
_, filename = os.path.split(filename)
|
| 82 |
if filename in metadata:
|
| 83 |
result = dict(metadata[filename])
|
|
@@ -85,6 +85,6 @@ class CommonVoice(datasets.GeneratorBasedBuilder):
|
|
| 85 |
path = os.path.join(local_extracted_archive_path, filename) if local_extracted_archive_path else filename
|
| 86 |
result["audio"] = {"file_path": path, "bytes": file.read()}
|
| 87 |
# set path to None if the audio file doesn't exist locally (i.e. in streaming mode)
|
| 88 |
-
result["file_path"] = path if
|
| 89 |
|
| 90 |
yield path, result
|
|
|
|
| 36 |
DEFAULT_WRITER_BATCH_SIZE = 1000
|
| 37 |
|
| 38 |
def _split_generators(self, dl_manager):
|
| 39 |
+
splits = ("train", "test", "validation")
|
| 40 |
audio_url = _AUDIO_URL
|
| 41 |
archive_path = dl_manager.download(audio_url)
|
| 42 |
+
local_extracted_archive_path = dl_manager.extract(archive_path) if not dl_manager.is_streaming else {}
|
| 43 |
|
| 44 |
meta_urls = {split: _TRANSCRIPT_URL.format(split=split) for split in splits}
|
| 45 |
meta_paths = dl_manager.download_and_extract(meta_urls)
|
|
|
|
| 55 |
datasets.SplitGenerator(
|
| 56 |
name=split_names.get(split, split),
|
| 57 |
gen_kwargs={
|
| 58 |
+
"local_extracted_archive_path": local_extracted_archive_path,
|
| 59 |
+
"archive": dl_manager.iter_archive(archive_path),
|
| 60 |
"meta_path": meta_paths[split],
|
| 61 |
},
|
| 62 |
),
|
|
|
|
| 64 |
|
| 65 |
return split_generators
|
| 66 |
|
| 67 |
+
def _generate_examples(self, local_extracted_archive_path, archive, meta_path):
|
| 68 |
data_fields = list(self._info().features.keys())
|
| 69 |
metadata = {}
|
| 70 |
with open(meta_path, encoding="utf-8") as f:
|
|
|
|
| 77 |
metadata[row["file_path"]] = row
|
| 78 |
|
| 79 |
|
| 80 |
+
for filename, file in archive:
|
| 81 |
_, filename = os.path.split(filename)
|
| 82 |
if filename in metadata:
|
| 83 |
result = dict(metadata[filename])
|
|
|
|
| 85 |
path = os.path.join(local_extracted_archive_path, filename) if local_extracted_archive_path else filename
|
| 86 |
result["audio"] = {"file_path": path, "bytes": file.read()}
|
| 87 |
# set path to None if the audio file doesn't exist locally (i.e. in streaming mode)
|
| 88 |
+
result["file_path"] = path if local_extracted_archive_path else filename
|
| 89 |
|
| 90 |
yield path, result
|