Corvin Jaedicke commited on
Commit
c2b3dc3
·
1 Parent(s): d3c6adf

First version of the daps dataset.

Browse files
Files changed (1) hide show
  1. daps.py +146 -0
daps.py ADDED
@@ -0,0 +1,146 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ """DAPS Dataset"""
16
+
17
+ import glob
18
+ import os
19
+
20
+ import datasets
21
+
22
+ # Find for instance the citation on arxiv or on the dataset repo/website
23
+ _CITATION = """\
24
+ @article{mysore2014can,
25
+ title={Can we automatically transform speech recorded on common consumer devices in real-world environments into professional production quality speech?—a dataset, insights, and challenges},
26
+ author={Mysore, Gautham J},
27
+ journal={IEEE Signal Processing Letters},
28
+ volume={22},
29
+ number={8},
30
+ pages={1006--1010},
31
+ year={2014},
32
+ publisher={IEEE}
33
+ }
34
+ """
35
+
36
+ # You can copy an official description
37
+ _DESCRIPTION = """\
38
+ The DAPS (Device and Produced Speech) dataset is a collection of aligned versions of professionally produced studio speech recordings and recordings of the same speech on common consumer devices (tablet and smartphone) in real-world environments. It has 15 versions of audio (3 professional versions and 12 consumer device/real-world environment combinations). Each version consists of about 4 1/2 hours of data (about 14 minutes from each of 20 speakers).
39
+ """
40
+
41
+ _HOMEPAGE = "https://ccrma.stanford.edu/~gautham/Site/daps.html"
42
+
43
+ _LICENSE = "Creative Commons Attribution Non Commercial 4.0 International"
44
+
45
+ # The HuggingFace Datasets library doesn't host the datasets but only points to the original files.
46
+ # This can be an arbitrary nested dict/list of URLs (see below in `_split_generators` method)
47
+ _URLS = "https://zenodo.org/record/4660670/files/daps.tar.gz"
48
+
49
+
50
+ class DapsDataset(datasets.GeneratorBasedBuilder):
51
+ """The DAPS (Device and Produced Speech) dataset is a collection of aligned versions of professionally produced studio speech recordings and recordings of the same speech on common consumer devices (tablet and smartphone) in real-world environments."""
52
+
53
+ VERSION = datasets.Version("2.12.0")
54
+
55
+ DEFAULT_CONFIG_NAME = "aligned_examples" # It's not mandatory to have a default configuration. Just use one if it make sense.
56
+
57
+ def _info(self):
58
+ features = datasets.Features(
59
+ {
60
+ "recording_environment": datasets.Value("string"),
61
+ "speaker_id": datasets.Value("string"),
62
+ "script_id": datasets.Value("string"),
63
+ "clean_path": datasets.Value("string"),
64
+ "produced_path": datasets.Value("string"),
65
+ "device_path": datasets.Value("string"),
66
+ "clean_audio": datasets.Audio(sampling_rate=44_100),
67
+ "produced_audio": datasets.Audio(sampling_rate=44_100),
68
+ "device_audio": datasets.Audio(sampling_rate=44_100),
69
+ }
70
+ )
71
+ return datasets.DatasetInfo(
72
+ # This is the description that will appear on the datasets page.
73
+ description=_DESCRIPTION,
74
+ # This defines the different columns of the dataset and their types
75
+ features=features, # Here we define them above because they are different between the two configurations
76
+ # If there's a common (input, target) tuple from the features, uncomment supervised_keys line below and
77
+ # specify them. They'll be used if as_supervised=True in builder.as_dataset.
78
+ # supervised_keys=("sentence", "label"),
79
+ # Homepage of the dataset for documentation
80
+ homepage=_HOMEPAGE,
81
+ # License for the dataset if available
82
+ license=_LICENSE,
83
+ # Citation for the dataset
84
+ citation=_CITATION,
85
+ )
86
+
87
+ def _split_generators(self, dl_manager):
88
+ """Returns SplitGenerators."""
89
+ # If several configurations are possible (listed in BUILDER_CONFIGS), the configuration selected by the user is in self.config.name
90
+
91
+ # dl_manager is a datasets.download.DownloadManager that can be used to download and extract URLS
92
+ # It can accept any type or nested list/dict and will give back the same structure with the url replaced with path to local files.
93
+ # By default the archives will be extracted and a path to a cached folder where they are extracted is returned instead of the archive
94
+ urls = _URLS
95
+ data_dir = dl_manager.download_and_extract(urls)
96
+ return [
97
+ datasets.SplitGenerator(
98
+ name=datasets.Split.TRAIN,
99
+ # These kwargs will be passed to _generate_examples
100
+ gen_kwargs={
101
+ "filepath": data_dir,
102
+ },
103
+ )
104
+ ]
105
+
106
+ # method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
107
+ def _generate_examples(self, filepath):
108
+ gt = ["clean", "produced"]
109
+ environments = [
110
+ "ipad_balcony1",
111
+ "ipad_livingroom1",
112
+ "ipadflat_office1",
113
+ "ipad_bedroom1",
114
+ "ipad_office1",
115
+ "iphone_balcony1",
116
+ "ipad_confroom1",
117
+ "ipad_office2",
118
+ "iphone_bedroom1",
119
+ "ipad_confroom2",
120
+ "ipadflat_confroom1",
121
+ "iphone_livingroom1",
122
+ ]
123
+ # example path: daps/iphone_bedroom1/m8_script5_iphone_bedroom1.wav
124
+ for env in environments:
125
+ for device_path in glob.glob(os.path.join(filepath, env) + "/*.wav"):
126
+ speaker_id = os.path.basename(device_path).split("_")[-4]
127
+ script_id = os.path.basename(device_path).split("_")[-3]
128
+ clean_path = device_path.replace(env, "clean")
129
+ produced_path = device_path.replace(env, "produced")
130
+ with open(clean_path, "rb") as f:
131
+ clean_audio = {"path": clean_path, "bytes": f.read()}
132
+ with open(produced_path, "rb") as f:
133
+ produced_audio = {"path": produced_path, "bytes": f.read()}
134
+ with open(device_path, "rb") as f:
135
+ device_audio = {"path": device_path, "bytes": f.read()}
136
+ yield f"{speaker_id}_{script_id}_{env}", {
137
+ "recording_environment": env,
138
+ "speaker_id": speaker_id,
139
+ "script_id": script_id,
140
+ "clean_path": clean_path,
141
+ "produced_path": produced_path,
142
+ "device_path": device_path,
143
+ "clean_audio": clean_audio,
144
+ "produced_audio": produced_audio,
145
+ "device_audio": device_audio,
146
+ }