jimregan commited on
Commit
0c91518
1 Parent(s): 7d38b00

add script

Browse files
Files changed (1) hide show
  1. eatd_corpus.py +122 -0
eatd_corpus.py ADDED
@@ -0,0 +1,122 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from pathlib import Path
2
+ import datasets
3
+ from datasets.tasks import AutomaticSpeechRecognition, AudioClassification
4
+ import os
5
+
6
+
7
+ _DESCRIPTION = """
8
+ An Emotional Audio-Textual Corpus
9
+
10
+ The EATD-Corpus is a dataset that consists of audio and text files of 162 volunteers who received counseling.
11
+
12
+ Training set contains data from 83 volunteers (19 depressed and 64 non-depressed).
13
+
14
+ Validation set contains data from 79 volunteers (11 depressed and 68 non-depressed).
15
+ """
16
+
17
+
18
+ _URL = "https://github.com/speechandlanguageprocessing/ICASSP2022-Depression"
19
+
20
+
21
+ _CITE = """
22
+ @INPROCEEDINGS{9746569,
23
+ author={Shen, Ying and Yang, Huiyu and Lin, Lin},
24
+ booktitle={ICASSP 2022 - 2022 IEEE International Conference on Acoustics, Speech and Signal Processing (ICASSP)},
25
+ title={Automatic Depression Detection: an Emotional Audio-Textual Corpus and A Gru/Bilstm-Based Model},
26
+ year={2022},
27
+ pages={6247-6251},
28
+ doi={10.1109/ICASSP43922.2022.9746569}
29
+ }
30
+ """
31
+
32
+
33
+ class EATDDataset(datasets.GeneratorBasedBuilder):
34
+ VERSION = datasets.Version("1.1.0")
35
+
36
+ BUILDER_CONFIGS = [
37
+ datasets.BuilderConfig(name="speech", version=VERSION, description="Data for speech recognition"),
38
+ ]
39
+
40
+ def _info(self):
41
+ features = datasets.Features(
42
+ {
43
+ "audio_raw": datasets.Audio(sampling_rate=16_000),
44
+ "audio": datasets.Audio(sampling_rate=16_000),
45
+ "id": datasets.Value("string"),
46
+ "text": datasets.Value("string"),
47
+ "raw_sds": datasets.Value("uint8"),
48
+ "sds_score": datasets.Value("float"),
49
+ "label": datasets.ClassLabel(names=["neutral", "negative", "positive"])
50
+ }
51
+ )
52
+
53
+ return datasets.DatasetInfo(
54
+ description=_DESCRIPTION,
55
+ features=features,
56
+ supervised_keys=None,
57
+ homepage=_URL,
58
+ citation=_CITE,
59
+ task_templates=[
60
+ AutomaticSpeechRecognition(audio_column="audio", transcription_column="text"),
61
+ AudioClassification(audio_column="audio", label_column="label")
62
+ ],
63
+ )
64
+
65
+ def _split_generators(self, dl_manager):
66
+ if hasattr(dl_manager, 'manual_dir') and dl_manager.manual_dir is not None:
67
+ data_dir = os.path.abspath(os.path.expanduser(dl_manager.manual_dir))
68
+ return [
69
+ datasets.SplitGenerator(
70
+ name=datasets.Split.TRAIN,
71
+ gen_kwargs={
72
+ "split": "train",
73
+ "data_dir": data_dir,
74
+ },
75
+ ),
76
+ datasets.SplitGenerator(
77
+ name=datasets.Split.VALIDATION,
78
+ gen_kwargs={
79
+ "split": "valid",
80
+ "data_dir": data_dir,
81
+ },
82
+ ),
83
+ ]
84
+
85
+ def _generate_examples(
86
+ self, split, data_dir
87
+ ):
88
+ basepath = Path(data_dir)
89
+ prefix = "v" if split == "valid" else "t"
90
+ for dir in basepath.glob(f"{prefix}_*"):
91
+ base_id = dir.name
92
+ with open(str(dir / "label.txt")) as labelf:
93
+ label = labelf.read().strip()
94
+ if label.endswith(".0"):
95
+ raw_sds = int(label[:-2])
96
+ else:
97
+ raw_sds = int(label)
98
+ with open(str(dir / "new_label.txt")) as labelf:
99
+ new_label = labelf.read().strip()
100
+ sds_score = float(new_label)
101
+ for polarity in ["neutral", "negative", "positive"]:
102
+ raw_audio = dir / f"{polarity}.wav"
103
+ proc_audio = dir / f"{polarity}_out.wav"
104
+ text_file = dir / f"{polarity}.txt"
105
+ with open(raw_audio, "rb") as rawf, open(proc_audio, "rb") as procf, open(text_file, "r") as textf:
106
+ text = textf.read().strip()
107
+ sid = f"{base_id}_{polarity}"
108
+ yield sid, {
109
+ "audio_raw": {
110
+ "bytes": rawf.read(),
111
+ "path": str(raw_audio),
112
+ },
113
+ "audio": {
114
+ "bytes": procf.read(),
115
+ "path": str(proc_audio),
116
+ },
117
+ "text": text,
118
+ "id": sid,
119
+ "raw_sds": raw_sds,
120
+ "sds_score": sds_score,
121
+ "label": polarity
122
+ }