import os import re import datasets from datasets import load_dataset, load_dataset_builder from datasets.tasks import AutomaticSpeechRecognition _HOMEPAGE = "https://huggingface.co/datasets/mskov/misophoniaSounds" _CITATION = "" _DESCRIPTION = "Dataset for misophonia inducing sound detection" _DATA_URLS = { "https://huggingface.co/datasets/mskov/misophoniaSounds/data/audio/all_audio.tar.gz" #"data/all_audio.tar.gz" } _PROMPTS_URLS ={ "train": "https://huggingface.co/datasets/mskov/misophoniaSounds/data/train/train_prompts.csv", "test": "https://huggingface.co/datasets/mskov/misophoniaSounds/data/test/test_prompts.csv" #"train": "data/rain_prompts.csv", #"test": "data/test_prompts.csv" } _NAMES = ["breathing", "chewing", "coughing", "mouth_sounds", "lip_smack", "sniffling", "yawn"] class Miso(datasets.GeneratorBasedBuilder): """Misophonia Audio""" def _info(self): return datasets.DatasetInfo( description=_DESCRIPTION, features=datasets.Features( { "audio": datasets.Audio(sampling_rate=16000), #"transcript": datasets.features.ClassLabel(names=_NAMES), "transcript": datasets.Value("string"), } ), #supervised_keys=("audio"), supervised_keys=None, homepage=_HOMEPAGE, citation=_CITATION, task_templates=[AutomaticSpeechRecognition(audio_column="audio", transcription_column="transcript")], ) def _split_generators(self, dl_manager): #data_files = dl_manager.download_and_extract(_DATA_URLS), prompts_paths = dl_manager.download_and_extract(_PROMPTS_URLS), audio_files = dl_manager.download_and_extract(_DATA_URLS), return [ datasets.SplitGenerator( name=datasets.Split.TRAIN, gen_kwargs={ "audio_files": dl_manager.iter_archive(audio_files), "filepath": prompts_paths["train"], }, ), datasets.SplitGenerator( name=datasets.Split.TEST, gen_kwargs={ "audio_files": dl_manager.iter_archive(audio_files), "filepath": prompts_paths["test"], }, ), ] def _generate_examples(self, audio_files): """This function returns the examples in the raw (text) form.""" idx = 0 for fpath, audio in audio_files: #label = filepath.split('/')[-1][:-4] #description = description.replace('_', ' ') label = fpath.split(',') print(label) yield idx, { "audio": {"path": fpath, "bytes": audio.read()}, "text": label, } idx += 1