File size: 5,226 Bytes
b60a622 0c91518 |
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 |
# coding=utf-8
# Copyright 2021 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors.
# Copyright 2023 Jim O'Regan
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from pathlib import Path
import datasets
from datasets.tasks import AutomaticSpeechRecognition, AudioClassification
import os
_DESCRIPTION = """
An Emotional Audio-Textual Corpus
The EATD-Corpus is a dataset that consists of audio and text files of 162 volunteers who received counseling.
Training set contains data from 83 volunteers (19 depressed and 64 non-depressed).
Validation set contains data from 79 volunteers (11 depressed and 68 non-depressed).
"""
_URL = "https://github.com/speechandlanguageprocessing/ICASSP2022-Depression"
_CITE = """
@INPROCEEDINGS{9746569,
author={Shen, Ying and Yang, Huiyu and Lin, Lin},
booktitle={ICASSP 2022 - 2022 IEEE International Conference on Acoustics, Speech and Signal Processing (ICASSP)},
title={Automatic Depression Detection: an Emotional Audio-Textual Corpus and A Gru/Bilstm-Based Model},
year={2022},
pages={6247-6251},
doi={10.1109/ICASSP43922.2022.9746569}
}
"""
class EATDDataset(datasets.GeneratorBasedBuilder):
VERSION = datasets.Version("1.1.0")
BUILDER_CONFIGS = [
datasets.BuilderConfig(name="speech", version=VERSION, description="Data for speech recognition"),
]
def _info(self):
features = datasets.Features(
{
"audio_raw": datasets.Audio(sampling_rate=16_000),
"audio": datasets.Audio(sampling_rate=16_000),
"id": datasets.Value("string"),
"text": datasets.Value("string"),
"raw_sds": datasets.Value("uint8"),
"sds_score": datasets.Value("float"),
"label": datasets.ClassLabel(names=["neutral", "negative", "positive"])
}
)
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=features,
supervised_keys=None,
homepage=_URL,
citation=_CITE,
task_templates=[
AutomaticSpeechRecognition(audio_column="audio", transcription_column="text"),
AudioClassification(audio_column="audio", label_column="label")
],
)
def _split_generators(self, dl_manager):
if hasattr(dl_manager, 'manual_dir') and dl_manager.manual_dir is not None:
data_dir = os.path.abspath(os.path.expanduser(dl_manager.manual_dir))
return [
datasets.SplitGenerator(
name=datasets.Split.TRAIN,
gen_kwargs={
"split": "train",
"data_dir": data_dir,
},
),
datasets.SplitGenerator(
name=datasets.Split.VALIDATION,
gen_kwargs={
"split": "valid",
"data_dir": data_dir,
},
),
]
def _generate_examples(
self, split, data_dir
):
basepath = Path(data_dir)
prefix = "v" if split == "valid" else "t"
for dir in basepath.glob(f"{prefix}_*"):
base_id = dir.name
with open(str(dir / "label.txt")) as labelf:
label = labelf.read().strip()
if label.endswith(".0"):
raw_sds = int(label[:-2])
else:
raw_sds = int(label)
with open(str(dir / "new_label.txt")) as labelf:
new_label = labelf.read().strip()
sds_score = float(new_label)
for polarity in ["neutral", "negative", "positive"]:
raw_audio = dir / f"{polarity}.wav"
proc_audio = dir / f"{polarity}_out.wav"
text_file = dir / f"{polarity}.txt"
with open(raw_audio, "rb") as rawf, open(proc_audio, "rb") as procf, open(text_file, "r") as textf:
text = textf.read().strip()
sid = f"{base_id}_{polarity}"
yield sid, {
"audio_raw": {
"bytes": rawf.read(),
"path": str(raw_audio),
},
"audio": {
"bytes": procf.read(),
"path": str(proc_audio),
},
"text": text,
"id": sid,
"raw_sds": raw_sds,
"sds_score": sds_score,
"label": polarity
}
|