File size: 4,448 Bytes
99b9f80
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
278c343
99b9f80
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
93db6d2
 
 
 
 
99b9f80
 
 
93db6d2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
99b9f80
 
93db6d2
99b9f80
93db6d2
99b9f80
93db6d2
 
99b9f80
 
 
93db6d2
99b9f80
 
 
 
 
 
 
 
 
 
 
 
 
 
 
93db6d2
 
 
 
 
 
99b9f80
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
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/resolve/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 = 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"])
                # 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