|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
""" LibriVox-Indonesia Dataset""" |
|
|
|
import csv |
|
import os |
|
|
|
import datasets |
|
from datasets.utils.py_utils import size_str |
|
|
|
from .languages import LANGUAGES |
|
from .release_stats import STATS |
|
|
|
_CITATION = """\ |
|
""" |
|
|
|
_HOMEPAGE = "https://huggingface.co/indonesian-nlp/librivox-indonesia" |
|
|
|
_LICENSE = "https://creativecommons.org/publicdomain/zero/1.0/" |
|
|
|
_DATA_URL = "https://huggingface.co/datasets/cahya/librivox-indonesia/resolve/main/data" |
|
|
|
|
|
class LibriVoxIndonesiaConfig(datasets.BuilderConfig): |
|
"""BuilderConfig for LibriVoxIndonesia.""" |
|
|
|
def __init__(self, name, version, **kwargs): |
|
self.language = kwargs.pop("language", None) |
|
self.release_date = kwargs.pop("release_date", None) |
|
self.num_clips = kwargs.pop("num_clips", None) |
|
self.num_speakers = kwargs.pop("num_speakers", None) |
|
self.validated_hr = kwargs.pop("validated_hr", None) |
|
self.total_hr = kwargs.pop("total_hr", None) |
|
self.size_bytes = kwargs.pop("size_bytes", None) |
|
self.size_human = size_str(self.size_bytes) |
|
description = ( |
|
f"LibriVox-Indonesia speech to text dataset in {self.language} released on {self.release_date}. " |
|
f"The dataset comprises {self.validated_hr} hours of transcribed speech data" |
|
) |
|
super(LibriVoxIndonesiaConfig, self).__init__( |
|
name=name, |
|
version=datasets.Version(version), |
|
description=description, |
|
**kwargs, |
|
) |
|
|
|
|
|
class LibriVoxIndonesia(datasets.GeneratorBasedBuilder): |
|
DEFAULT_CONFIG_NAME = "all" |
|
|
|
BUILDER_CONFIGS = [ |
|
LibriVoxIndonesiaConfig( |
|
name=lang, |
|
version=STATS["version"], |
|
language=LANGUAGES[lang], |
|
release_date=STATS["date"], |
|
num_clips=lang_stats["clips"], |
|
num_speakers=lang_stats["users"], |
|
total_hr=float(lang_stats["totalHrs"]) if lang_stats["totalHrs"] else None, |
|
size_bytes=int(lang_stats["size"]) if lang_stats["size"] else None, |
|
) |
|
for lang, lang_stats in STATS["locales"].items() |
|
] |
|
|
|
def _info(self): |
|
total_languages = len(STATS["locales"]) |
|
total_hours = self.config.total_hr |
|
description = ( |
|
"LibriVox-Indonesia is a speech dataset generated from LibriVox with only languages from Indonesia." |
|
f"The dataset currently consists of {total_hours} hours of speech " |
|
f" in {total_languages} languages, but more voices and languages are always added." |
|
) |
|
features = datasets.Features( |
|
{ |
|
"path": datasets.Value("string"), |
|
"language": datasets.Value("string"), |
|
"reader": datasets.Value("string"), |
|
"sentence": datasets.Value("string"), |
|
"audio": datasets.features.Audio(sampling_rate=44100) |
|
} |
|
) |
|
|
|
return datasets.DatasetInfo( |
|
description=description, |
|
features=features, |
|
supervised_keys=None, |
|
homepage=_HOMEPAGE, |
|
license=_LICENSE, |
|
citation=_CITATION, |
|
version=self.config.version, |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
"""Returns SplitGenerators.""" |
|
dl_manager.download_config.ignore_url_params = True |
|
audio_train = dl_manager.download(_DATA_URL + "/audio_train.tgz") |
|
local_extracted_archive_train = dl_manager.extract(audio_train) if not dl_manager.is_streaming else None |
|
audio_test = dl_manager.download(_DATA_URL + "/audio_test.tgz") |
|
local_extracted_archive_test = dl_manager.extract(audio_test) if not dl_manager.is_streaming else None |
|
path_to_clips = "librivox-indonesia" |
|
|
|
return [ |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TRAIN, |
|
gen_kwargs={ |
|
"local_extracted_archive": local_extracted_archive_train, |
|
"audio_files": dl_manager.iter_archive(audio_train), |
|
"metadata_path": dl_manager.download_and_extract(_DATA_URL + "/metadata_train.csv.gz"), |
|
"path_to_clips": path_to_clips, |
|
}, |
|
), |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TEST, |
|
gen_kwargs={ |
|
"local_extracted_archive": local_extracted_archive_test, |
|
"audio_files": dl_manager.iter_archive(audio_test), |
|
"metadata_path": dl_manager.download_and_extract(_DATA_URL + "/metadata_test.csv.gz"), |
|
"path_to_clips": path_to_clips, |
|
}, |
|
), |
|
] |
|
|
|
def _generate_examples( |
|
self, |
|
local_extracted_archive, |
|
audio_files, |
|
metadata_path, |
|
path_to_clips, |
|
): |
|
"""Yields examples.""" |
|
print(metadata_path) |
|
data_fields = list(self._info().features.keys()) |
|
metadata = {} |
|
with open(metadata_path, "r", encoding="utf-8") as f: |
|
reader = csv.DictReader(f) |
|
for row in reader: |
|
if self.config.name == "all" or self.config.name == row["language"]: |
|
row["path"] = os.path.join(path_to_clips, row["path"]) |
|
|
|
for field in data_fields: |
|
if field not in row: |
|
row[field] = "" |
|
metadata[row["path"]] = row |
|
id_ = 0 |
|
print("example length = %d" % len(metadata)) |
|
|
|
for path, f in audio_files: |
|
print(path) |
|
if path in metadata: |
|
result = dict(metadata[path]) |
|
|
|
path = os.path.join(local_extracted_archive, path) if local_extracted_archive else path |
|
result["audio"] = {"path": path, "bytes": f.read()} |
|
result["path"] = path |
|
yield id_, result |
|
id_ += 1 |
|
|