File size: 2,079 Bytes
0834d5a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/python3
# -*- coding: utf-8 -*-
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