#!/usr/bin/python3 # -*- coding: utf-8 -*- from glob import glob import json import os from pathlib import Path import datasets _DATA_URL_MAP = { "kitchen_16k": "https://zenodo.org/records/1227121/files/DKITCHEN_16k.zip?download=1", "kitchen_48k": "https://zenodo.org/records/1227121/files/DKITCHEN_48k.zip?download=1", "living_16k": "https://zenodo.org/records/1227121/files/DLIVING_16k.zip?download=1", "living_48k": "https://zenodo.org/records/1227121/files/DLIVING_48k.zip?download=1", "washing_16k": "https://zenodo.org/records/1227121/files/DWASHING_16k.zip?download=1", "washing_48k": "https://zenodo.org/records/1227121/files/DWASHING_48k.zip?download=1", "field_16k": "https://zenodo.org/records/1227121/files/NFIELD_16k.zip?download=1", "field_48k": "https://zenodo.org/records/1227121/files/NFIELD_48k.zip?download=1", "park_16k": "https://zenodo.org/records/1227121/files/NPARK_16k.zip?download=1", "park_48k": "https://zenodo.org/records/1227121/files/NPARK_48k.zip?download=1", "river_16k": "https://zenodo.org/records/1227121/files/NRIVER_16k.zip?download=1", "river_48k": "https://zenodo.org/records/1227121/files/NRIVER_48k.zip?download=1", "hallway_16k": "https://zenodo.org/records/1227121/files/OHALLWAY_16k.zip?download=1", "hallway_48k": "https://zenodo.org/records/1227121/files/OHALLWAY_48k.zip?download=1", "meeting_16k": "https://zenodo.org/records/1227121/files/OMEETING_16k.zip?download=1", "meeting_48k": "https://zenodo.org/records/1227121/files/OMEETING_48k.zip?download=1", "office_16k": "https://zenodo.org/records/1227121/files/OOFFICE_16k.zip?download=1", "office_48k": "https://zenodo.org/records/1227121/files/OOFFICE_48k.zip?download=1", "cafeter_16k": "https://zenodo.org/records/1227121/files/PCAFETER_16k.zip?download=1", "cafeter_48k": "https://zenodo.org/records/1227121/files/PCAFETER_48k.zip?download=1", "resto_16k": "https://zenodo.org/records/1227121/files/PRESTO_16k.zip?download=1", "resto_48k": "https://zenodo.org/records/1227121/files/PRESTO_48k.zip?download=1", "station_16k": "https://zenodo.org/records/1227121/files/PSTATION_16k.zip?download=1", "station_48k": "https://zenodo.org/records/1227121/files/PSTATION_48k.zip?download=1", "cafe_48k": "https://zenodo.org/records/1227121/files/SCAFE_48k.zip?download=1", "square_16k": "https://zenodo.org/records/1227121/files/SPSQUARE_16k.zip?download=1", "square_48k": "https://zenodo.org/records/1227121/files/SPSQUARE_48k.zip?download=1", "traffic_16k": "https://zenodo.org/records/1227121/files/STRAFFIC_16k.zip?download=1", "traffic_48k": "https://zenodo.org/records/1227121/files/STRAFFIC_48k.zip?download=1", "bus_16k": "https://zenodo.org/records/1227121/files/TBUS_16k.zip?download=1", "bus_48k": "https://zenodo.org/records/1227121/files/TBUS_48k.zip?download=1", "car_16k": "https://zenodo.org/records/1227121/files/TCAR_16k.zip?download=1", "car_48k": "https://zenodo.org/records/1227121/files/TCAR_48k.zip?download=1", "metro_16k": "https://zenodo.org/records/1227121/files/TMETRO_16k.zip?download=1", "metro_48k": "https://zenodo.org/records/1227121/files/TMETRO_48k.zip?download=1", } _CITATION = """\ @dataset{DEMAND, author = {Xing Tian}, title = {DEMAND}, month = jan, year = 2025, publisher = {Xing Tian}, version = {1.0}, } """ _DESCRIPTION = """DEMAND: Diverse Environments Multichannel Acoustic Noise Database""" _VERSION = datasets.Version("1.0.0") _BUILDER_CONFIGS = [ datasets.BuilderConfig(name=key, version=_VERSION, description=key) for key in _DATA_URL_MAP.keys() ] class Demand(datasets.GeneratorBasedBuilder): VERSION = _VERSION BUILDER_CONFIGS = _BUILDER_CONFIGS def _info(self): features = datasets.Features( { "category": datasets.Value("string"), "audio": datasets.Audio(), } ) return datasets.DatasetInfo( description=_DESCRIPTION, features=features, supervised_keys=None, homepage="", license="", citation=_CITATION, ) def _split_generators(self, dl_manager): """Returns SplitGenerators.""" data_url = _DATA_URL_MAP.get(self.config.name) if data_url is None: raise AssertionError(f"subset {self.config.name} is not available.") archive_path = dl_manager.download_and_extract(data_url) return [ datasets.SplitGenerator( name=datasets.Split.TRAIN, gen_kwargs={"archive_path": archive_path, "dl_manager": dl_manager}, ), ] def _generate_examples(self, archive_path, dl_manager): """Yields examples.""" archive_path = Path(archive_path) sample_idx = 0 for filename in archive_path.glob("**/*.wav"): print(filename) yield sample_idx, { "category": filename.parts[-2], "audio": filename.as_posix(), } sample_idx += 1 if __name__ == '__main__': pass