import os import datasets from datasets.tasks import AudioClassification # Once upload a new piano brand, please register its name here _NAMES = ["intro", "chorus", "verse", "pre-chorus", "post-chorus", "bridge"] _DBNAME = os.path.basename(__file__).split('.')[0] _HOMEPAGE = "https://huggingface.co/datasets/ccmusic-database/" + _DBNAME _CITATION = """\ @dataset{zhaorui_liu_2021_5676893, author = {Zhaorui Liu, Monan Zhou, Shenyang Xu and Zijin Li}, title = {{Music Data Sharing Platform for Computational Musicology Research (CCMUSIC DATASET)}}, month = nov, year = 2021, publisher = {Zenodo}, version = {1.1}, doi = {10.5281/zenodo.5676893}, url = {https://doi.org/10.5281/zenodo.5676893} } """ _DESCRIPTION = """\ This database contains 300 pop songs (.mp3 format, downloaded from NetEase Cloud Music), as well as a structure annotation file (.txt format) for each song. The song structure is labeled as follows: intro, chorus, verse, pre-chorus, post-chorus, bridge, ending. """ _URL = _HOMEPAGE + "/resolve/main/data/labels.zip" class piano_sound_quality(datasets.GeneratorBasedBuilder): def _info(self): return datasets.DatasetInfo( description=_DESCRIPTION, features=datasets.Features( { "time": datasets.Value('time32'), "audio": datasets.Value('binary'), "label": datasets.features.ClassLabel(names=_NAMES), } ), supervised_keys=("time", "label"), homepage=_HOMEPAGE, license="mit", citation=_CITATION, task_templates=[ AudioClassification( task="audio-classification", audio_column="time", label_column="label", ) ], ) def _split_generators(self, dl_manager): data_files = dl_manager.download_and_extract(_URL) return [ datasets.SplitGenerator( name=datasets.Split.TRAIN, gen_kwargs={ "files": dl_manager.iter_files([data_files]), }, ) ] def _generate_examples(self, files): for i, path in enumerate(files): file_name = os.path.basename(path) if file_name.endswith(".wav"): yield i, { "time": 0, "audio": path, "label": 0, }