|
|
import datasets |
|
|
import csv |
|
|
import os |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_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/resolve/main/dataset" |
|
|
|
|
|
|
|
|
class BeatboxDataset(datasets.GeneratorBasedBuilder): |
|
|
|
|
|
VERSION = datasets.Version("1.0.0") |
|
|
|
|
|
def _info(self): |
|
|
return datasets.DatasetInfo( |
|
|
|
|
|
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, |
|
|
|
|
|
) |
|
|
|
|
|
def _split_generators(self, dl_manager): |
|
|
"""Returns SplitGenerators.""" |
|
|
dl_manager.download_config.ignore_url_params = True |
|
|
|
|
|
audio_path = dl_manager.download(_DATA_URL) |
|
|
local_extracted_archive = dl_manager.extract( |
|
|
audio_path) if not dl_manager.is_streaming else None |
|
|
path_to_clips = "dataset" |
|
|
|
|
|
return [ |
|
|
datasets.SplitGenerator( |
|
|
name=datasets.Split.TRAIN, |
|
|
gen_kwargs={ |
|
|
"local_extracted_archive": |
|
|
local_extracted_archive, |
|
|
"audio_files": |
|
|
dl_manager.iter_archive(audio_path), |
|
|
"metadata_path": |
|
|
dl_manager.download_and_extract( |
|
|
"dataset/metadata_train.csv.gz"), |
|
|
"path_to_clips": |
|
|
path_to_clips, |
|
|
}, |
|
|
), |
|
|
datasets.SplitGenerator( |
|
|
name=datasets.Split.TEST, |
|
|
gen_kwargs={ |
|
|
"local_extracted_archive": |
|
|
local_extracted_archive, |
|
|
"audio_files": |
|
|
dl_manager.iter_archive(audio_path), |
|
|
"metadata_path": |
|
|
dl_manager.download_and_extract( |
|
|
"dataset/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.""" |
|
|
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: |
|
|
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 |
|
|
for path, f in audio_files: |
|
|
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 |
|
|
|