Datasets:
License:
import datasets | |
import csv | |
import os | |
# For a future citation perhaps? | |
# _CITATION = """\ | |
# @inproceedings{luong-vu-2016-non, | |
# title = "A non-expert {K}aldi recipe for {V}ietnamese Speech Recognition System", | |
# author = "Luong, Hieu-Thi and | |
# Vu, Hai-Quan", | |
# booktitle = "Proceedings of the Third International Workshop on Worldwide Language Service Infrastructure and Second Workshop on Open Infrastructures and Analysis Frameworks for Human Language Technologies ({WLSI}/{OIAF}4{HLT}2016)", | |
# month = dec, | |
# year = "2016", | |
# address = "Osaka, Japan", | |
# publisher = "The COLING 2016 Organizing Committee", | |
# url = "https://aclanthology.org/W16-5207", | |
# pages = "51--55", | |
# } | |
# """ | |
_DESCRIPTION = """\ | |
Dataset consisting of isolated beatbox samples , | |
reimplementation of the dataset from the following | |
paper: BaDumTss: Multi-task Learning for Beatbox Transcription | |
""" | |
_HOMEPAGE = "https://doi.org/10.1007/978-3-031-05981-0_14" | |
_LICENSE = "MIT" | |
_DATA_URL = "https://huggingface.co/datasets/maxardito/beatbox/tree/main/dataset/" | |
class BeatboxDataset(datasets.GeneratorBasedBuilder): | |
VERSION = datasets.Version("1.0.0") | |
def _info(self): | |
return datasets.DatasetInfo( | |
# This is the description that will appear on the datasets page. | |
description=_DESCRIPTION, | |
features=datasets.Features({ | |
"path": | |
datasets.Value("string"), | |
"class": | |
datasets.Value("string"), | |
"audio": | |
datasets.Audio(sampling_rate=16_000), | |
}), | |
supervised_keys=None, | |
homepage=_HOMEPAGE, | |
license=_LICENSE, | |
# citation=_CITATION, | |
) | |
def _split_generators(self, dl_manager): | |
"""Returns SplitGenerators.""" | |
dl_manager.download_config.ignore_url_params = True | |
audio_path = {} | |
local_extracted_archive = {} | |
metadata_path = {} | |
split_type = { | |
"train": datasets.Split.TRAIN, | |
"test": datasets.Split.TEST | |
} | |
for split in split_type: | |
audio_path[split] = dl_manager.download( | |
f"{_DATA_URL}/audio_{split}.tgz") | |
local_extracted_archive[split] = dl_manager.extract( | |
audio_path[split]) if not dl_manager.is_streaming else None | |
metadata_path[split] = dl_manager.download_and_extract( | |
f"{_DATA_URL}/metadata_{split}.csv.gz") | |
path_to_clips = "beatbox" | |
return [ | |
datasets.SplitGenerator( | |
name=split_type[split], | |
gen_kwargs={ | |
"local_extracted_archive": | |
local_extracted_archive[split], | |
"audio_files": | |
dl_manager.iter_archive(audio_path[split]), | |
"metadata_path": | |
dl_manager.download_and_extract(metadata_path[split]), | |
"path_to_clips": | |
path_to_clips, | |
}, | |
) for split in split_type | |
] | |
def _generate_examples( | |
self, | |
local_extracted_archive, | |
audio_files, | |
metadata_path, | |
path_to_clips, | |
): | |
"""Yields examples.""" | |
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"]) | |
# if data is incomplete, fill with empty values | |
for field in data_fields: | |
if field not in row: | |
row[field] = "" | |
metadata[row["path"]] = row | |
id_ = 0 | |
for path, f in audio_files: | |
if path in metadata: | |
result = dict(metadata[path]) | |
# set the audio feature and the path to the extracted file | |
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 | |