RodrigoLimaRFL
commited on
Update NURC-SP_ENTOA_TTS.py
Browse files- NURC-SP_ENTOA_TTS.py +159 -162
NURC-SP_ENTOA_TTS.py
CHANGED
@@ -1,162 +1,159 @@
|
|
1 |
-
import csv
|
2 |
-
import datasets
|
3 |
-
from datasets import BuilderConfig, GeneratorBasedBuilder, DatasetInfo, SplitGenerator, Split
|
4 |
-
|
5 |
-
_PROSODIC_PROMPTS_URLS = {
|
6 |
-
"validation": "prosodic/audios_dev_metadata.csv",
|
7 |
-
"train": "prosodic/audios_train_metadata.csv",
|
8 |
-
}
|
9 |
-
|
10 |
-
_AUTOMATIC_PROMPTS_URLS = {
|
11 |
-
"validation": "automatic/audios_dev_metadata.csv",
|
12 |
-
"train": "automatic/audios_train_metadata.csv",
|
13 |
-
}
|
14 |
-
|
15 |
-
_ARCHIVES = {
|
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 |
-
"
|
140 |
-
"
|
141 |
-
"
|
142 |
-
"
|
143 |
-
"
|
144 |
-
"
|
145 |
-
"
|
146 |
-
"
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
id_ += 1
|
161 |
-
elif inside_clips_dir:
|
162 |
-
break
|
|
|
1 |
+
import csv
|
2 |
+
import datasets
|
3 |
+
from datasets import BuilderConfig, GeneratorBasedBuilder, DatasetInfo, SplitGenerator, Split
|
4 |
+
|
5 |
+
_PROSODIC_PROMPTS_URLS = {
|
6 |
+
"validation": "prosodic/audios_dev_metadata.csv",
|
7 |
+
"train": "prosodic/audios_train_metadata.csv",
|
8 |
+
}
|
9 |
+
|
10 |
+
_AUTOMATIC_PROMPTS_URLS = {
|
11 |
+
"validation": "automatic/audios_dev_metadata.csv",
|
12 |
+
"train": "automatic/audios_train_metadata.csv",
|
13 |
+
}
|
14 |
+
|
15 |
+
_ARCHIVES = {
|
16 |
+
"prosodic": "prosodic/audios.tar.gz",
|
17 |
+
"automatic": "automatic/audios.tar.gz",
|
18 |
+
}
|
19 |
+
|
20 |
+
_PATH_TO_CLIPS = {
|
21 |
+
"validation_prosodic": "prosodic/audios_dev",
|
22 |
+
"train_prosodic": "prosodic/audios_train",
|
23 |
+
"validation_automatic": "automatic/audios_dev",
|
24 |
+
"train_automatic": "automatic/audios_train",
|
25 |
+
}
|
26 |
+
|
27 |
+
class EntoaConfig(BuilderConfig):
|
28 |
+
def __init__(self, prompts_type="prosodic", **kwargs):
|
29 |
+
super().__init__(**kwargs)
|
30 |
+
self.prompts_type = prompts_type
|
31 |
+
|
32 |
+
class EntoaDataset(GeneratorBasedBuilder):
|
33 |
+
BUILDER_CONFIGS = [
|
34 |
+
EntoaConfig(name="prosodic", description="Prosodic audio prompts", prompts_type="prosodic"),
|
35 |
+
EntoaConfig(name="automatic", description="Automatic audio prompts", prompts_type="automatic"),
|
36 |
+
]
|
37 |
+
|
38 |
+
def _info(self):
|
39 |
+
if self.config.name == "prosodic":
|
40 |
+
features = datasets.Features(
|
41 |
+
{
|
42 |
+
"path": datasets.Value("string"),
|
43 |
+
"name": datasets.Value("string"),
|
44 |
+
"speaker": datasets.Value("string"),
|
45 |
+
"start_time": datasets.Value("string"),
|
46 |
+
"end_time": datasets.Value("string"),
|
47 |
+
"normalized_text": datasets.Value("string"),
|
48 |
+
"text": datasets.Value("string"),
|
49 |
+
"duration": datasets.Value("string"),
|
50 |
+
"type": datasets.Value("string"),
|
51 |
+
"year": datasets.Value("string"),
|
52 |
+
"gender": datasets.Value("string"),
|
53 |
+
"age_range": datasets.Value("string"),
|
54 |
+
"total_duration": datasets.Value("string"),
|
55 |
+
"quality": datasets.Value("string"),
|
56 |
+
"theme": datasets.Value("string"),
|
57 |
+
"audio": datasets.Audio(sampling_rate=16_000),
|
58 |
+
}
|
59 |
+
)
|
60 |
+
else: # automatic
|
61 |
+
features = datasets.Features(
|
62 |
+
{
|
63 |
+
"audio_name": datasets.Value("string"),
|
64 |
+
"file_path": datasets.Value("string"),
|
65 |
+
"text": datasets.Value("string"),
|
66 |
+
"start_time": datasets.Value("string"),
|
67 |
+
"end_time": datasets.Value("string"),
|
68 |
+
"duration": datasets.Value("string"),
|
69 |
+
"quality": datasets.Value("string"),
|
70 |
+
"speech_genre": datasets.Value("string"),
|
71 |
+
"speech_style": datasets.Value("string"),
|
72 |
+
"variety": datasets.Value("string"),
|
73 |
+
"accent": datasets.Value("string"),
|
74 |
+
"sex": datasets.Value("string"),
|
75 |
+
"age_range": datasets.Value("string"),
|
76 |
+
"num_speakers": datasets.Value("string"),
|
77 |
+
"speaker_id": datasets.Value("string"),
|
78 |
+
"audio": datasets.Audio(sampling_rate=16_000),
|
79 |
+
}
|
80 |
+
)
|
81 |
+
return DatasetInfo(features=features)
|
82 |
+
|
83 |
+
def _split_generators(self, dl_manager):
|
84 |
+
prompts_urls = _PROSODIC_PROMPTS_URLS if self.config.name == "prosodic" else _AUTOMATIC_PROMPTS_URLS
|
85 |
+
archive = dl_manager.download(_ARCHIVES[self.config.name])
|
86 |
+
prompts_path = dl_manager.download(prompts_urls)
|
87 |
+
|
88 |
+
return [
|
89 |
+
SplitGenerator(
|
90 |
+
name=Split.VALIDATION,
|
91 |
+
gen_kwargs={
|
92 |
+
"prompts_path": prompts_path["validation"],
|
93 |
+
"path_to_clips": _PATH_TO_CLIPS[f"validation_{self.config.name}"],
|
94 |
+
"audio_files": dl_manager.iter_archive(archive),
|
95 |
+
},
|
96 |
+
),
|
97 |
+
SplitGenerator(
|
98 |
+
name=Split.TRAIN,
|
99 |
+
gen_kwargs={
|
100 |
+
"prompts_path": prompts_path["train"],
|
101 |
+
"path_to_clips": _PATH_TO_CLIPS[f"train_{self.config.name}"],
|
102 |
+
"audio_files": dl_manager.iter_archive(archive),
|
103 |
+
},
|
104 |
+
),
|
105 |
+
]
|
106 |
+
|
107 |
+
def _generate_examples(self, prompts_path, path_to_clips, audio_files):
|
108 |
+
examples = {}
|
109 |
+
with open(prompts_path, "r") as f:
|
110 |
+
csv_reader = csv.DictReader(f)
|
111 |
+
for row in csv_reader:
|
112 |
+
if self.config.name == "prosodic":
|
113 |
+
examples[row['path']] = {
|
114 |
+
"path": row['path'],
|
115 |
+
"name": row['name'],
|
116 |
+
"speaker": row['speaker'],
|
117 |
+
"start_time": row['start_time'],
|
118 |
+
"end_time": row['end_time'],
|
119 |
+
"normalized_text": row['normalized_text'],
|
120 |
+
"text": row['text'],
|
121 |
+
"duration": row['duration'],
|
122 |
+
"type": row['type'],
|
123 |
+
"year": row['year'],
|
124 |
+
"gender": row['gender'],
|
125 |
+
"age_range": row['age_range'],
|
126 |
+
"total_duration": row['total_duration'],
|
127 |
+
"quality": row['quality'],
|
128 |
+
"theme": row['theme'],
|
129 |
+
}
|
130 |
+
else: # automatic
|
131 |
+
examples[row['file_path']] = {
|
132 |
+
"audio_name": row['audio_name'],
|
133 |
+
"file_path": row['file_path'],
|
134 |
+
"text": row['text'],
|
135 |
+
"start_time": row['start_time'],
|
136 |
+
"end_time": row['end_time'],
|
137 |
+
"duration": row['duration'],
|
138 |
+
"quality": row['quality'],
|
139 |
+
"speech_genre": row['speech_genre'],
|
140 |
+
"speech_style": row['speech_style'],
|
141 |
+
"variety": row['variety'],
|
142 |
+
"accent": row['accent'],
|
143 |
+
"sex": row['sex'],
|
144 |
+
"age_range": row['age_range'],
|
145 |
+
"num_speakers": row['num_speakers'],
|
146 |
+
"speaker_id": row['speaker_id'],
|
147 |
+
}
|
148 |
+
|
149 |
+
id_ = 0
|
150 |
+
inside_clips_dir = False
|
151 |
+
for path, f in audio_files:
|
152 |
+
if path.startswith(path_to_clips):
|
153 |
+
inside_clips_dir = True
|
154 |
+
if path in examples:
|
155 |
+
audio = {"path": path, "bytes": f.read()}
|
156 |
+
yield id_, {**examples[path], "audio": audio}
|
157 |
+
id_ += 1
|
158 |
+
elif inside_clips_dir:
|
159 |
+
break
|
|
|
|
|
|