vm_sound_classification / vm_sound_classification.py
HoneyTian's picture
update
6f80449
#!/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