|
from pathlib import Path |
|
|
|
import datasets |
|
import pandas as pd |
|
|
|
_CITATION = """\ |
|
@misc{, |
|
author = "", |
|
title = "", |
|
url = "", |
|
publisher = "", |
|
year = "" |
|
} |
|
""" |
|
|
|
|
|
_DESCRIPTION = """\ |
|
The BanglaBeats dataset comprises 16,170 3-second audio tracks extracted from 1,617 distinct Bengali songs, spanning genres such as adhunik, folk, hiphop, islamic, indie, metal, pop, and rock. |
|
""" |
|
|
|
_HOMEPAGE = "" |
|
|
|
|
|
_LICENSE = "" |
|
|
|
_URL = "" |
|
|
|
GENRES = ["Adhunik", "Folk", "Hiphop", "Indie", "Islamic", "Metal", "Pop", "Rock"] |
|
CORRUPTED_FILES = ["abcd.wav"] |
|
|
|
|
|
class BanglaBeats(datasets.GeneratorBasedBuilder): |
|
"""The BanglaBeats dataset""" |
|
|
|
def _info(self): |
|
return datasets.DatasetInfo( |
|
description=_DESCRIPTION, |
|
features=datasets.Features( |
|
{ |
|
"file": datasets.Value("string"), |
|
"audio": datasets.Audio(sampling_rate=22_050), |
|
"genre": datasets.ClassLabel(names=GENRES), |
|
} |
|
), |
|
homepage=_HOMEPAGE, |
|
license=_LICENSE, |
|
citation=_CITATION, |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
local_extracted_archive = dl_manager.download_and_extract("data/data.zip") |
|
return [ |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TRAIN, |
|
gen_kwargs={ |
|
"local_extracted_archive": local_extracted_archive, |
|
}, |
|
) |
|
] |
|
|
|
def _generate_examples(self, local_extracted_archive): |
|
paths = list(Path(local_extracted_archive).glob("**/*.wav")) |
|
paths = [p for p in paths if "._" not in p.name] |
|
data = [] |
|
|
|
for path in paths: |
|
label = str(path).split("/")[-2] |
|
name = str(path).split("/")[-1] |
|
if name in CORRUPTED_FILES: |
|
continue |
|
|
|
data.append({"file": str(path), "genre": label}) |
|
df = pd.DataFrame(data) |
|
df.sort_values("file", inplace=True) |
|
|
|
for idx_, row in df.iterrows(): |
|
yield idx_, {"file": row["file"], "audio": row["file"], "genre": row["genre"]} |