RodrigoLimaRFL commited on
Commit
ee83a56
·
verified ·
1 Parent(s): 3578c45

Update tasdda.py

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