|
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/all_audio.tar.gz" |
|
} |
|
_PROMPTS_URLS ={ |
|
"train": "https://huggingface.co/datasets/mskov/misophoniaSounds/data/train_prompts.csv", |
|
"test": "https://huggingface.co/datasets/mskov/misophoniaSounds/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=16_000), |
|
"transcript": datasets.features.ClassLabel(names=_NAMES), |
|
|
|
} |
|
), |
|
|
|
supervised_keys=None, |
|
homepage=_HOMEPAGE, |
|
citation=_CITATION, |
|
task_templates=[AutomaticSpeechRecognition(audio_column="audio", transcription_column="transcription")], |
|
) |
|
def _split_generators(self, dl_manager): |
|
|
|
prompts_paths = dl_manager.download(_PROMPTS_URLS), |
|
audio_files = dl_manager.download(_DATA_URLS), |
|
return [ |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TRAIN, |
|
gen_kwargs={ |
|
"filepath": prompts_paths["train"], |
|
"audio_files": dl_manager.iter_archive(audio_files), |
|
}, |
|
), |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TEST, |
|
gen_kwargs={ |
|
"filepath": prompts_paths["test"], |
|
"audio_files": dl_manager.iter_archive(audio_files), |
|
}, |
|
), |
|
] |
|
def _generate_examples(self, filepath, audio_files): |
|
"""This function returns the examples in the raw (text) form.""" |
|
idx = 0 |
|
for filepath, audio in audio_files: |
|
|
|
|
|
label = filepath.split(',') |
|
print(label) |
|
yield idx, { |
|
"audio": {"path": filepath, "bytes": audio.read()}, |
|
"text": label, |
|
} |
|
idx += 1 |