|
|
|
|
|
|
|
|
from pathlib import Path |
|
|
|
|
|
import datasets |
|
|
import librosa |
|
|
|
|
|
|
|
|
_DATA_URL_MAP = { |
|
|
"en-PH": "data/noise/en-PH.zip", |
|
|
|
|
|
} |
|
|
|
|
|
_CITATION = """\ |
|
|
@dataset{nx_noise, |
|
|
author = {Xing Tian}, |
|
|
title = {nx noise}, |
|
|
month = jan, |
|
|
year = 2025, |
|
|
publisher = {Xing Tian}, |
|
|
version = {1.0}, |
|
|
} |
|
|
""" |
|
|
|
|
|
|
|
|
_DESCRIPTION = """noise from user side in calling.""" |
|
|
|
|
|
|
|
|
class NXNoise(datasets.GeneratorBasedBuilder): |
|
|
VERSION = datasets.Version("1.0.0") |
|
|
|
|
|
BUILDER_CONFIGS = [ |
|
|
datasets.BuilderConfig(name="en-PH", version=VERSION, description="noise from en-PH"), |
|
|
] |
|
|
|
|
|
def _info(self): |
|
|
features = datasets.Features( |
|
|
{ |
|
|
"audio": datasets.Audio(), |
|
|
"duration": datasets.Value("float16"), |
|
|
} |
|
|
) |
|
|
|
|
|
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"): |
|
|
y, sr = librosa.load(filename, sr=None) |
|
|
yield sample_idx, { |
|
|
"audio": filename.as_posix(), |
|
|
"duration": round(librosa.get_duration(y=y, sr=sr), 4), |
|
|
} |
|
|
sample_idx += 1 |
|
|
|
|
|
|
|
|
if __name__ == '__main__': |
|
|
pass |
|
|
|