File size: 3,028 Bytes
6f80449 |
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 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
#!/usr/bin/python3
# -*- coding: utf-8 -*-
from glob import glob
import os
from pathlib import Path
import datasets
_URLS = {
"EarlyMedia-1": "data/wav_finished/EarlyMedia-1.zip",
"EarlyMedia-55": "data/wav_finished/EarlyMedia-55.zip",
"EarlyMedia-60": "data/wav_finished/EarlyMedia-60.zip",
"EarlyMedia-62": "data/wav_finished/EarlyMedia-62.zip",
"EarlyMedia-66": "data/wav_finished/EarlyMedia-66.zip",
"en-IN": "data/wav_finished/en-IN.zip",
"en-PH": "data/wav_finished/en-PH.zip",
"en-SG": "data/wav_finished/en-SG.zip",
"en-US": "data/wav_finished/en-US.zip",
"es-MX": "data/wav_finished/es-MX.zip",
"es-PE": "data/wav_finished/es-PE.zip",
"id-ID": "data/wav_finished/id-ID.zip",
"ja-JP": "data/wav_finished/ja-JP.zip",
"ko-KR": "data/wav_finished/ko-KR.zip",
"ms-MY": "data/wav_finished/ms-MY.zip",
"pt-BR": "data/wav_finished/pt-BR.zip",
"th-TH": "data/wav_finished/th-TH.zip",
"zh-TW": "data/wav_finished/zh-TW.zip",
}
_CITATION = """\
@dataset{early_media,
author = {Xing Tian},
title = {vm_sound_classification},
month = aug,
year = 2024,
publisher = {Xing Tian},
version = {1.0},
}
"""
_DESCRIPTION = """\
"""
VERSION = datasets.Version("1.0.0")
class VMSoundClassification(datasets.GeneratorBasedBuilder):
BUILDER_CONFIGS = [
datasets.BuilderConfig(name=name, version=VERSION, description=name) for name in _URLS.keys()
]
def _info(self):
features = datasets.Features(
{
"country": datasets.Value("string"),
"label": datasets.Value("string"),
"path": datasets.Value("string"),
"audio": datasets.Audio(sampling_rate=8000),
}
)
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=features,
supervised_keys=None,
homepage="",
license="",
citation=_CITATION,
)
def _split_generators(self, dl_manager):
"""Returns SplitGenerators."""
url = _URLS[self.config.name]
dl_path = dl_manager.download_and_extract(url)
archive_path = os.path.join(dl_path, self.config.name)
return [
datasets.SplitGenerator(
name=datasets.Split.TRAIN,
gen_kwargs={"archive_path": archive_path, "split": "train"},
),
]
def _generate_examples(self, archive_path, split):
"""Yields examples."""
archive_path = Path(archive_path)
filename_list = archive_path.glob("*/*/*.wav")
for idx, filename in enumerate(filename_list):
label = filename.parts[-2]
country = filename.parts[-4]
yield idx, {
"country": country,
"label": label,
"path": filename.as_posix(),
"audio": filename.as_posix(),
}
if __name__ == '__main__':
pass
|