File size: 2,797 Bytes
19b99af
 
 
 
 
 
 
 
 
 
b1a7d26
19b99af
 
f2c06af
 
0d03698
 
19b99af
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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"
    #"train": "train_prompts.csv",
    #"test": "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),
                #"transcript": datasets.Value("string"),
                }
            ),
            #supervised_keys=("audio"),
            supervised_keys=None,
            homepage=_HOMEPAGE,
            citation=_CITATION,
            task_templates=[AutomaticSpeechRecognition(audio_column="audio", transcription_column="transcription")],
        )
    def _split_generators(self, dl_manager):
        #data_files = dl_manager.download_and_extract(_DATA_URLS),
        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('/')[-1][:-4]
            #description = description.replace('_', ' ')
            label = filepath.split(',')
            print(label)
            yield idx, {
                "audio": {"path": filepath, "bytes": audio.read()},
                "text": label,
            }
            idx += 1