RodrigoLimaRFL commited on
Commit
64515be
·
verified ·
1 Parent(s): 18682cb

Delete NURC-SP_ENTOA_TTS.py

Browse files
Files changed (1) hide show
  1. NURC-SP_ENTOA_TTS.py +0 -303
NURC-SP_ENTOA_TTS.py DELETED
@@ -1,303 +0,0 @@
1
- import csv
2
- import datasets
3
- from datasets import BuilderConfig, GeneratorBasedBuilder, DatasetInfo, SplitGenerator, Split
4
- from pathlib import Path
5
-
6
- _PROMPTS_PROSODIC_URLS = {
7
- "dev": "prosodic/validation.csv",
8
- "train": "prosodic/train.csv",
9
- }
10
-
11
- _PROMPTS_AUDIO_CORPUS_URLS = {
12
- "dev": "audioCorpus/validation.csv",
13
- "train": "audioCorpus/train.csv",
14
- }
15
-
16
- _PROMPTS_AUTOMATIC_URLS = {
17
- "dev": "automatic/validation.csv",
18
- "train": "automatic/train.csv",
19
- }
20
-
21
- _PROMPTS_TEST_URLS = {
22
- "test": "test/test.csv",
23
- }
24
-
25
- _ARCHIVES_PROSODIC = {
26
- "dev": "prosodic/audios.tar.gz",
27
- "train": "prosodic/audios.tar.gz",
28
- }
29
-
30
- _ARCHIVES_AUDIO_CORPUS = {
31
- "dev": "audioCorpus/audios.tar.gz",
32
- "train": "audioCorpus/audios.tar.gz",
33
- }
34
-
35
- _ARCHIVES_AUTOMATIC = {
36
- "train": "automatic/nurc_cm_automatic_segmented_audios.zip",
37
- "dev": "automatic/nurc_cm_automatic_segmented_audios.zip",
38
- }
39
-
40
- _ARCHIVES_TEST = {
41
- "test": "test/test.zip",
42
- }
43
-
44
- _PATH_TO_CLIPS = {
45
- "dev": "",
46
- "train": "",
47
- "test": "",
48
- }
49
-
50
-
51
- class NurcSPConfig(BuilderConfig):
52
- def __init__(self, prompts_type, **kwargs):
53
- super().__init__(**kwargs)
54
- self.prompts_type = prompts_type
55
-
56
-
57
- class NurcSPDataset(GeneratorBasedBuilder):
58
- BUILDER_CONFIGS = [
59
- NurcSPConfig(name="audioCorpus", description="Audio Corpus audio prompts", prompts_type="audioCorpus"),
60
- NurcSPConfig(name="prosodic", description="Prosodic audio prompts", prompts_type="prosodic"),
61
- NurcSPConfig(name="automatic", description="Automatic audio prompts", prompts_type="automatic"),
62
- NurcSPConfig(name="test", description="Test audio prompts", prompts_type="test"),
63
- ]
64
-
65
- def _info(self):
66
- if self.config.name == "prosodic":
67
- return DatasetInfo(
68
- features=datasets.Features(
69
- {
70
- "path": datasets.Value("string"),
71
- "name": datasets.Value("string"),
72
- "speaker": datasets.Value("string"),
73
- "start_time": datasets.Value("string"),
74
- "end_time": datasets.Value("string"),
75
- "normalized_text": datasets.Value("string"),
76
- "text": datasets.Value("string"),
77
- "duration": datasets.Value("string"),
78
- "type": datasets.Value("string"),
79
- "year": datasets.Value("string"),
80
- "gender": datasets.Value("string"),
81
- "age_range": datasets.Value("string"),
82
- "total_duration": datasets.Value("string"),
83
- "quality": datasets.Value("string"),
84
- "theme": datasets.Value("string"),
85
- "audio": datasets.Audio(sampling_rate=16_000, mono=True),
86
- }
87
- )
88
- )
89
- elif self.config.name == "audioCorpus":
90
- return DatasetInfo(
91
- features=datasets.Features(
92
- {
93
- "audio_name": datasets.Value("string"),
94
- "file_path": datasets.Value("string"),
95
- "text": datasets.Value("string"),
96
- "start_time": datasets.Value("string"),
97
- "end_time": datasets.Value("string"),
98
- "duration": datasets.Value("string"),
99
- "quality": datasets.Value("string"),
100
- "speech_genre": datasets.Value("string"),
101
- "speech_style": datasets.Value("string"),
102
- "variety": datasets.Value("string"),
103
- "accent": datasets.Value("string"),
104
- "sex": datasets.Value("string"),
105
- "age_range": datasets.Value("string"),
106
- "num_speakers": datasets.Value("string"),
107
- "speaker_id": datasets.Value("string"),
108
- "audio": datasets.Audio(sampling_rate=16_000, mono=True),
109
- }
110
- )
111
- )
112
- elif self.config.name == "automatic":
113
- return DatasetInfo(
114
- features=datasets.Features(
115
- {
116
- "path": datasets.Value("string"),
117
- "name": datasets.Value("string"),
118
- "speaker": datasets.Value("string"),
119
- "start_time": datasets.Value("string"),
120
- "end_time": datasets.Value("string"),
121
- "text": datasets.Value("string"),
122
- "duration": datasets.Value("string"),
123
- "audio": datasets.Audio(sampling_rate=16_000, mono=True),
124
- }
125
- )
126
- )
127
- elif self.config.name == "test":
128
- return DatasetInfo(
129
- features=datasets.Features(
130
- {
131
- "path": datasets.Value("string"),
132
- "name": datasets.Value("string"),
133
- "speaker": datasets.Value("string"),
134
- "start_time": datasets.Value("string"),
135
- "end_time": datasets.Value("string"),
136
- "text": datasets.Value("string"),
137
- "duration": datasets.Value("string"),
138
- "audio": datasets.Audio(sampling_rate=16_000, mono=True),
139
- }
140
- )
141
- )
142
-
143
-
144
- def _split_generators(self, dl_manager):
145
- if self.config.prompts_type == "prosodic":
146
- prompts_urls = _PROMPTS_PROSODIC_URLS
147
- archive_link = _ARCHIVES_PROSODIC
148
- elif self.config.prompts_type == "audioCorpus":
149
- prompts_urls = _PROMPTS_AUDIO_CORPUS_URLS
150
- archive_link = _ARCHIVES_AUDIO_CORPUS
151
- elif self.config.prompts_type == "automatic":
152
- prompts_urls = _PROMPTS_AUTOMATIC_URLS
153
- archive_link = _ARCHIVES_AUTOMATIC
154
- elif self.config.prompts_type == "test":
155
- prompts_urls = _PROMPTS_TEST_URLS
156
- archive_link = _ARCHIVES_TEST
157
- else:
158
- return
159
-
160
- prompts_path = dl_manager.download(prompts_urls)
161
- archive = dl_manager.download(archive_link)
162
-
163
- if self.config.prompts_type == "prosodic" or self.config.prompts_type == "audioCorpus":
164
- return [
165
- SplitGenerator(
166
- name=Split.VALIDATION,
167
- gen_kwargs={
168
- "prompts_path": prompts_path["dev"],
169
- "path_to_clips": _PATH_TO_CLIPS["dev"],
170
- "audio_files": dl_manager.iter_archive(archive["dev"]),
171
- "split_name": "validation"
172
- }
173
- ),
174
- SplitGenerator(
175
- name=Split.TRAIN,
176
- gen_kwargs={
177
- "prompts_path": prompts_path["train"],
178
- "path_to_clips": _PATH_TO_CLIPS["train"],
179
- "audio_files": dl_manager.iter_archive(archive["train"]),
180
- "split_name": "train"
181
- }
182
- ),
183
- ]
184
- elif self.config.prompts_type == "automatic":
185
- return [
186
- SplitGenerator(
187
- name=Split.VALIDATION,
188
- gen_kwargs={
189
- "prompts_path": prompts_path["dev"],
190
- "path_to_clips": _PATH_TO_CLIPS["dev"],
191
- "audio_files": dl_manager.iter_archive(archive["dev"]),
192
- "split_name": "validation"
193
- }
194
- ),
195
- SplitGenerator(
196
- name=Split.TRAIN,
197
- gen_kwargs={
198
- "prompts_path": prompts_path["train"],
199
- "path_to_clips": _PATH_TO_CLIPS["train"],
200
- "audio_files": dl_manager.iter_archive(archive["train"]),
201
- "split_name": "train"
202
- }
203
- ),
204
- ]
205
- elif self.config.prompts_type == "test":
206
- return[
207
- SplitGenerator(
208
- name=Split.TEST,
209
- gen_kwargs={
210
- "prompts_path": prompts_path["test"],
211
- "path_to_clips": _PATH_TO_CLIPS["test"],
212
- "audio_files": dl_manager.iter_archive(archive["test"]),
213
- "split_name": "test"
214
- }
215
- ),
216
- ]
217
-
218
- def _generate_examples(self, prompts_path, path_to_clips, audio_files, split_name):
219
- examples = {}
220
- csv_paths = []
221
-
222
- with open(prompts_path, "r", encoding="utf-8") as f:
223
- if self.config.prompts_type == "test":
224
- csv_reader = csv.DictReader(f, delimiter=";") # Explicitly set delimiter
225
- else:
226
- csv_reader = csv.DictReader(f)
227
-
228
- if self.config.prompts_type == "prosodic":
229
- for row in csv_reader:
230
- file_path = Path(row['path']).as_posix()
231
- examples[file_path] = {
232
- "path": row['path'],
233
- "name": row['name'],
234
- "speaker": row['speaker'],
235
- "start_time": row['start_time'],
236
- "end_time": row['end_time'],
237
- "normalized_text": row['normalized_text'],
238
- "text": row['text'],
239
- "duration": row['duration'],
240
- "type": row['type'],
241
- "year": row['year'],
242
- "gender": row['gender'],
243
- "age_range": row['age_range'],
244
- "total_duration": row['total_duration'],
245
- "quality": row['quality'],
246
- "theme": row['theme'],
247
- }
248
- csv_paths.append(file_path)
249
- elif self.config.prompts_type == "audioCorpus":
250
- for row in csv_reader:
251
- file_path = Path(row['file_path']).as_posix()
252
- examples[file_path] = {
253
- "audio_name": row['audio_name'],
254
- "file_path": row['file_path'],
255
- "text": row['text'],
256
- "start_time": row['start_time'],
257
- "end_time": row['end_time'],
258
- "duration": row['duration'],
259
- "quality": row['quality'],
260
- "speech_genre": row['speech_genre'],
261
- "speech_style": row['speech_style'],
262
- "variety": row['variety'],
263
- "accent": row['accent'],
264
- "sex": row['sex'],
265
- "age_range": row['age_range'],
266
- "num_speakers": row['num_speakers'],
267
- "speaker_id": row['speaker_id'],
268
- }
269
- csv_paths.append(file_path)
270
- elif self.config.prompts_type == "automatic":
271
- for row in csv_reader:
272
- file_path = Path(row['path']).as_posix()
273
- examples[file_path] = {
274
- "path": row['path'],
275
- "name": row['name'],
276
- "speaker": row['speaker'],
277
- "start_time": row['start_time'],
278
- "end_time": row['end_time'],
279
- "text": row['text'],
280
- "duration": row['duration'],
281
- }
282
- csv_paths.append(file_path)
283
- elif self.config.prompts_type == "test":
284
- for row in csv_reader:
285
- file_path = Path(row['path']).as_posix()
286
- examples[file_path] = {
287
- "path": row['path'],
288
- "name": row['name'],
289
- "speaker": row['speaker'],
290
- "start_time": row['start_time'],
291
- "end_time": row['end_time'],
292
- "text": row['text'],
293
- "duration": row['duration'],
294
- }
295
- csv_paths.append(file_path)
296
-
297
- id_ = 0
298
- for path, f in audio_files:
299
- path = Path(path).as_posix()
300
- if path.startswith(path_to_clips) and path in examples:
301
- audio = {"path": path, "bytes": f.read()}
302
- yield id_, {**examples[path], "audio": audio}
303
- id_ += 1