File size: 6,306 Bytes
05d2efb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b281cf4
05d2efb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Apr 18 16:14:58 2023

@author: lin.kinwahedward
"""
#------------------------------------------------------------------------------
# Standard Libraries
import datasets
import numpy as np
import os
#------------------------------------------------------------------------------
"""The Audio, Speech, and Vision Processing Lab - Emotional Sound Database (ASVP - ESD)"""

_CITATION = """\
@article{gsj2020asvpesd,
  title={ASVP-ESD:A dataset and its benchmark for emotion recognition using both speech and non-speech utterances},
  author={Dejoli Tientcheu Touko Landry and Qianhua He and Haikang Yan and Yanxiong Li},
  journal={Global Scientific Journals},
  volume={8},
  issue={6},
  pages={1793--1798},
  year={2020}
}
"""

_DESCRIPTION = """\
ASVP-ESD
"""

_HOMEPAGE = "https://www.kaggle.com/datasets/dejolilandry/asvpesdspeech-nonspeech-emotional-utterances?resource=download-directory"

_LICENSE = "CC BY 4.0"

_DATA_URL = "https://drive.google.com/uc?export=download&id=1aKnr5kXgUjMB5MAhUTZmm3b8gjP8qA3O"


id2labels = {
    1: "boredom,sigh",
    2: "neutral,calm",
    3: "happy,laugh,gaggle",
    4: "sad,cry",
    5: "angry,grunt,frustration",
    6: "fearful,scream,panic",
    7: "disgust,dislike,contempt",
    8: "surprised,gasp,amazed",
    9: "excited",
    10: "pleasure",
    11: "pain,groan",
    12: "disappointment,disapproval",
    13: "breath"
}

#------------------------------------------------------------------------------
# Define Dataset Configuration (e.g., subset of dataset, but it is not used here.)
class ASVP_ESD_Config(datasets.BuilderConfig):
    #--------------------------------------------------------------------------
    def __init__(self, name, description, homepage, data_url):
        
        super(ASVP_ESD_Config, self).__init__(
            name = self.name,
            version = datasets.Version("1.0.0"),
            description = self.description,
        )
        self.name = name
        self.description = description
        self.homepage = homepage
        self.data_url = data_url
#------------------------------------------------------------------------------
# Define Dataset Class
class ASVP_ESD(datasets.GeneratorBasedBuilder):
    #--------------------------------------------------------------------------
    BUILDER_CONFIGS = [ASVP_ESD_Config(
        name = "ASVP_ESD",
        description = _DESCRIPTION,
        homepage = _HOMEPAGE,
        data_url = _DATA_URL
        )]
    #--------------------------------------------------------------------------
    '''
        Define the "column header" (feature) of a datum.
        3 Features:
            1) path_to_file
            2) audio samples
            3) emotion label
    '''
    def _info(self):
        
        features = datasets.Features(
                {
                    "path": datasets.Value("string"),
                    "audio": datasets.Audio(sampling_rate = 16000),
                    "label": datasets.ClassLabel(
                        names = [
                            "boredom,sigh",
                            "neutral,calm",
                            "happy,laugh,gaggle",
                            "sad,cry",
                            "angry,grunt,frustration",
                            "fearful,scream,panic",
                            "disgust,dislike,contempt",
                            "surprised,gasp,amazed",
                            "excited",
                            "pleasure",
                            "pain,groan",
                            "disappointment,disapproval",
                            "breath"
                        ])
                }
            )
        
        # return dataset info and data feature info
        return datasets.DatasetInfo(
            description = _DESCRIPTION,
            features = features,
            homepage = _HOMEPAGE,
            citation = _CITATION,
        )
    #--------------------------------------------------------------------------
    def _split_generators(self, dl_manager):
        
        dataset_path = dl_manager.download_and_extract(self.config.data_url)
        
        return [
            datasets.SplitGenerator(
                # set the whole dataset as "training set". No worry, can split later! 
                name = datasets.Split.TRAIN,
                # _generate_examples()'s parameters, thus name must match!
                gen_kwargs = {
                    "dataset_path": dataset_path
                },
            )
        ]
    #--------------------------------------------------------------------------
    def _generate_examples(self, dataset_path):
        '''
            Get the audio file and set the corresponding labels
        '''
        key = 0
        actors = np.arange(129)
        for dir_name in actors:
            #--------------------------------------------------------------------------
            dir_path = dataset_path + "/ASVP_ESD/Speech/actor_" + str(dir_name)
            for filename in os.listdir(dir_path):
                if filename.endswith(".wav"):
                    labels = filename[:-4].split("_")
                    yield key, {
                        "path": dir_path + "/" + filename,
                        # huggingface dataset's will use soundfile to read the audio file
                        "audio": dir_path + "/" + filename,
                        "label": id2labels[int(labels[0])],
                    }
                    key += 1
            #--------------------------------------------------------------------------
            dir_path = dataset_path + "/ASVP_ESD/NonSpeech/actor_" + str(dir_name)
            for filename in os.listdir(dir_path):
                if filename.endswith(".wav"):
                    labels = filename[:-4].split("_")
                    yield key, {
                        "path": dir_path + "/" + filename,
                        # huggingface dataset's will use soundfile to read the audio file
                        "audio": dir_path + "/" + filename,
                        "label": id2labels[int(labels[0])],
                    }
                    key += 1
#------------------------------------------------------------------------------