RodrigoLimaRFL commited on
Commit
25596de
1 Parent(s): 8e3cd61

Create CORAA-NURC-SP-Audio-Corpus.py

Browse files
Files changed (1) hide show
  1. CORAA-NURC-SP-Audio-Corpus.py +145 -0
CORAA-NURC-SP-Audio-Corpus.py ADDED
@@ -0,0 +1,145 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import csv
2
+ import datasets
3
+
4
+
5
+ _PROMPTS_URLS = {
6
+ "dev": "original/audios_dev_metadata.csv",
7
+ "test": "original/audios_test_metadata.csv",
8
+ "train": "original/audios_train_metadata.csv",
9
+ }
10
+
11
+ _PROMPTS_FILTERED_URLS = {
12
+ "dev": "filtered/audios_dev_metadata.csv",
13
+ "test": "filtered/audios_test_metadata.csv",
14
+ "train": "filtered/audios_train_metadata.csv",
15
+ }
16
+
17
+ _ARCHIVES = {
18
+ "dev": "dev.tar.gz",
19
+ "test": "test.tar.gz",
20
+ "train": "train.tar.gz",
21
+ }
22
+
23
+ _PATH_TO_CLIPS = {
24
+ "dev": "dev",
25
+ "test": "test",
26
+ "train": "train",
27
+ }
28
+
29
+
30
+ class NurcSPDataset(datasets.GeneratorBasedBuilder):
31
+ def _info(self):
32
+ return datasets.DatasetInfo(
33
+ features=datasets.Features(
34
+ {
35
+ "audio_name": datasets.Value("string"),
36
+ "file_path": datasets.Value("string"),
37
+ "text": datasets.Value("string"),
38
+ "start_time": datasets.Value("string"),
39
+ "end_time": datasets.Value("string"),
40
+ "duration": datasets.Value("string"),
41
+ "quality": datasets.Value("string"),
42
+ "speech_genre": datasets.Value("string"),
43
+ "speech_style": datasets.Value("string"),
44
+ "variety": datasets.Value("string"),
45
+ "accent": datasets.Value("string"),
46
+ "sex": datasets.Value("string"),
47
+ "age_range": datasets.Value("string"),
48
+ "num_speakers": datasets.Value("string"),
49
+ "speaker_id": datasets.Value("string"),
50
+ "audio": datasets.Audio(sampling_rate=16_000),
51
+ }
52
+ )
53
+ )
54
+
55
+ def _split_generators(self, dl_manager, config=None):
56
+ prompts_urls = _PROMPTS_URLS # Default to original prompts URLs if config is not provided
57
+
58
+ if config and 'type' in config:
59
+ prompts_type = config['type']
60
+ if prompts_type == 'original':
61
+ prompts_urls = _PROMPTS_URLS
62
+ elif prompts_type == 'filtered':
63
+ prompts_urls = _PROMPTS_FILTERED_URLS
64
+ else:
65
+ raise ValueError(f"Invalid prompts type '{prompts_type}'. Please choose 'original' or 'filtered'.")
66
+
67
+ prompts_path = dl_manager.download(prompts_urls)
68
+ archive = dl_manager.download(_ARCHIVES)
69
+
70
+ return [
71
+ datasets.SplitGenerator(
72
+ name=datasets.Split.VALIDATION,
73
+ gen_kwargs={
74
+ "prompts_path": prompts_path["dev"],
75
+ "path_to_clips": _PATH_TO_CLIPS["dev"],
76
+ "audio_files": dl_manager.iter_archive(archive["dev"]),
77
+ }
78
+ ),
79
+ datasets.SplitGenerator(
80
+ name=datasets.Split.TEST,
81
+ gen_kwargs={
82
+ "prompts_path": prompts_path["test"],
83
+ "path_to_clips": _PATH_TO_CLIPS["test"],
84
+ "audio_files": dl_manager.iter_archive(archive["test"]),
85
+ }
86
+ ),
87
+ datasets.SplitGenerator(
88
+ name=datasets.Split.TRAIN,
89
+ gen_kwargs={
90
+ "prompts_path": prompts_path["train"],
91
+ "path_to_clips": _PATH_TO_CLIPS["train"],
92
+ "audio_files": dl_manager.iter_archive(archive["train"]),
93
+ }
94
+ ),
95
+ ]
96
+
97
+
98
+ def _generate_examples(self, prompts_path, path_to_clips, audio_files):
99
+ examples = {}
100
+ with open(prompts_path, "r") as f:
101
+ csv_reader = csv.DictReader(f)
102
+ for row in csv_reader:
103
+ audio_name = row['audio_name']
104
+ file_path = row['file_path']
105
+ text = row['text']
106
+ start_time = row['start_time']
107
+ end_time = row['end_time']
108
+ duration = row['duration']
109
+ quality = row['quality']
110
+ speech_genre = row['speech_genre']
111
+ speech_style = row['speech_style']
112
+ variety = row['variety']
113
+ accent = row['accent']
114
+ sex = row['sex']
115
+ age_range = row['age_range']
116
+ num_speakers = row['num_speakers']
117
+ speaker_id = row['speaker_id']
118
+ examples[file_path] = {
119
+ "audio_name": audio_name,
120
+ "file_path": file_path,
121
+ "text": text,
122
+ "start_time": start_time,
123
+ "end_time": end_time,
124
+ "duration": duration,
125
+ "quality": quality,
126
+ "speech_genre": speech_genre,
127
+ "speech_style": speech_style,
128
+ "variety": variety,
129
+ "accent": accent,
130
+ "sex": sex,
131
+ "age_range": age_range,
132
+ "num_speakers": num_speakers,
133
+ "speaker_id": speaker_id,
134
+ }
135
+ inside_clips_dir = False
136
+ id_ = 0
137
+ for path, f in audio_files:
138
+ if path.startswith(path_to_clips):
139
+ inside_clips_dir = True
140
+ if path in examples:
141
+ audio = {"path": path, "bytes": f.read()}
142
+ yield id_, {**examples[path], "audio": audio}
143
+ id_ += 1
144
+ elif inside_clips_dir:
145
+ break