draft for streaming functionality
Browse files- audio_transcription.csv.gz +3 -0
- librivox-indonesia.py +16 -14
audio_transcription.csv.gz
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:92e0830dc9642ed5e92ebbceb7d65e5f6b90979d4bfda451b2d8970506a63791
|
3 |
+
size 207161
|
librivox-indonesia.py
CHANGED
@@ -32,6 +32,7 @@ _HOMEPAGE = "https://huggingface.co/indonesian-nlp/librivox-indonesia"
|
|
32 |
_LICENSE = "https://creativecommons.org/publicdomain/zero/1.0/"
|
33 |
|
34 |
_AUDIO_URL = "https://huggingface.co/datasets/cahya/librivox-indonesia/resolve/main/librivox-indonesia.tgz"
|
|
|
35 |
|
36 |
|
37 |
class LibriVoxIndonesiaConfig(datasets.BuilderConfig):
|
@@ -107,8 +108,10 @@ class LibriVoxIndonesia(datasets.GeneratorBasedBuilder):
|
|
107 |
"""Returns SplitGenerators."""
|
108 |
dl_manager.download_config.ignore_url_params = True
|
109 |
|
110 |
-
|
111 |
-
|
|
|
|
|
112 |
path_to_clips = "librivox-indonesia"
|
113 |
|
114 |
return [
|
@@ -116,8 +119,8 @@ class LibriVoxIndonesia(datasets.GeneratorBasedBuilder):
|
|
116 |
name=datasets.Split.TRAIN,
|
117 |
gen_kwargs={
|
118 |
"local_extracted_archive": local_extracted_archive,
|
119 |
-
"
|
120 |
-
"
|
121 |
"path_to_clips": path_to_clips,
|
122 |
},
|
123 |
),
|
@@ -126,18 +129,16 @@ class LibriVoxIndonesia(datasets.GeneratorBasedBuilder):
|
|
126 |
def _generate_examples(
|
127 |
self,
|
128 |
local_extracted_archive,
|
129 |
-
|
130 |
-
|
131 |
path_to_clips,
|
132 |
):
|
133 |
"""Yields examples."""
|
134 |
data_fields = list(self._info().features.keys())
|
135 |
metadata = {}
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
utterances = csv.DictReader(lines)
|
140 |
-
for row in utterances:
|
141 |
if self.config.name == "all" or self.config.name == row["language"]:
|
142 |
row["path"] = os.path.join(path_to_clips, row["path"])
|
143 |
# if data is incomplete, fill with empty values
|
@@ -145,7 +146,8 @@ class LibriVoxIndonesia(datasets.GeneratorBasedBuilder):
|
|
145 |
if field not in row:
|
146 |
row[field] = ""
|
147 |
metadata[row["path"]] = row
|
148 |
-
|
|
|
149 |
if path in metadata:
|
150 |
result = dict(metadata[path])
|
151 |
# set the audio feature and the path to the extracted file
|
@@ -153,5 +155,5 @@ class LibriVoxIndonesia(datasets.GeneratorBasedBuilder):
|
|
153 |
result["audio"] = {"path": path, "bytes": f.read()}
|
154 |
# set path to None if the audio file doesn't exist locally (i.e. in streaming mode)
|
155 |
result["path"] = path if local_extracted_archive else None
|
156 |
-
|
157 |
-
|
|
|
32 |
_LICENSE = "https://creativecommons.org/publicdomain/zero/1.0/"
|
33 |
|
34 |
_AUDIO_URL = "https://huggingface.co/datasets/cahya/librivox-indonesia/resolve/main/librivox-indonesia.tgz"
|
35 |
+
_METADATA_URL = "https://huggingface.co/datasets/cahya/librivox-indonesia/resolve/main/audio_transcription.csv.gz"
|
36 |
|
37 |
|
38 |
class LibriVoxIndonesiaConfig(datasets.BuilderConfig):
|
|
|
108 |
"""Returns SplitGenerators."""
|
109 |
dl_manager.download_config.ignore_url_params = True
|
110 |
|
111 |
+
audio_path = dl_manager.download(_AUDIO_URL)
|
112 |
+
metadata_path = dl_manager.download_and_extract(_METADATA_URL)
|
113 |
+
local_extracted_archive = dl_manager.extract(audio_path) if not dl_manager.is_streaming else None
|
114 |
+
print("Metadata Path", metadata_path)
|
115 |
path_to_clips = "librivox-indonesia"
|
116 |
|
117 |
return [
|
|
|
119 |
name=datasets.Split.TRAIN,
|
120 |
gen_kwargs={
|
121 |
"local_extracted_archive": local_extracted_archive,
|
122 |
+
"audio_files": dl_manager.iter_archive(audio_path),
|
123 |
+
"metadata_path": metadata_path,
|
124 |
"path_to_clips": path_to_clips,
|
125 |
},
|
126 |
),
|
|
|
129 |
def _generate_examples(
|
130 |
self,
|
131 |
local_extracted_archive,
|
132 |
+
audio_files,
|
133 |
+
metadata_path,
|
134 |
path_to_clips,
|
135 |
):
|
136 |
"""Yields examples."""
|
137 |
data_fields = list(self._info().features.keys())
|
138 |
metadata = {}
|
139 |
+
with open(metadata_path, "r", encoding="utf-8") as f:
|
140 |
+
reader = csv.DictReader(f)
|
141 |
+
for row in reader:
|
|
|
|
|
142 |
if self.config.name == "all" or self.config.name == row["language"]:
|
143 |
row["path"] = os.path.join(path_to_clips, row["path"])
|
144 |
# if data is incomplete, fill with empty values
|
|
|
146 |
if field not in row:
|
147 |
row[field] = ""
|
148 |
metadata[row["path"]] = row
|
149 |
+
id_ = 0
|
150 |
+
for path, f in audio_files:
|
151 |
if path in metadata:
|
152 |
result = dict(metadata[path])
|
153 |
# set the audio feature and the path to the extracted file
|
|
|
155 |
result["audio"] = {"path": path, "bytes": f.read()}
|
156 |
# set path to None if the audio file doesn't exist locally (i.e. in streaming mode)
|
157 |
result["path"] = path if local_extracted_archive else None
|
158 |
+
yield id_, result
|
159 |
+
id_ += 1
|