Datasets:
Languages:
Portuguese
License:
RodrigoLimaRFL
commited on
Commit
•
7bd51bf
1
Parent(s):
f7dd2f7
Create nurc-sp-dev.py
Browse files- nurc-sp-dev.py +103 -0
nurc-sp-dev.py
ADDED
@@ -0,0 +1,103 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import csv
|
2 |
+
import datasets
|
3 |
+
|
4 |
+
_PROMPTS_URLS = {
|
5 |
+
"dev": "data/audios_dev_metadata.csv",
|
6 |
+
}
|
7 |
+
|
8 |
+
_ARCHIVES = {
|
9 |
+
"dev": "data/dev.tar",
|
10 |
+
}
|
11 |
+
|
12 |
+
_PATH_TO_CLIPS = {
|
13 |
+
"dev": "dev",
|
14 |
+
}
|
15 |
+
|
16 |
+
class NurcSPDataset(datasets.GeneratorBasedBuilder):
|
17 |
+
def _info(self):
|
18 |
+
return datasets.DatasetInfo(
|
19 |
+
features=datasets.Features(
|
20 |
+
{
|
21 |
+
"audio_name": datasets.Value("string"),
|
22 |
+
"file_path": datasets.Value("string"),
|
23 |
+
"text": datasets.Value("string"),
|
24 |
+
"start_time": datasets.Value("string"),
|
25 |
+
"end_time": datasets.Value("string"),
|
26 |
+
"duration": datasets.Value("string"),
|
27 |
+
"quality": datasets.Value("string"),
|
28 |
+
"speech_genre": datasets.Value("string"),
|
29 |
+
"speech_style": datasets.Value("string"),
|
30 |
+
"variety": datasets.Value("string"),
|
31 |
+
"accent": datasets.Value("string"),
|
32 |
+
"sex": datasets.Value("string"),
|
33 |
+
"age_range": datasets.Value("string"),
|
34 |
+
"num_speakers": datasets.Value("string"),
|
35 |
+
"speaker_id": datasets.Value("string"),
|
36 |
+
"audio": datasets.Audio(sampling_rate=16_000),
|
37 |
+
}
|
38 |
+
)
|
39 |
+
)
|
40 |
+
|
41 |
+
def _split_generators(self, dl_manager):
|
42 |
+
prompts_path = dl_manager.download(_PROMPTS_URLS)
|
43 |
+
archive = dl_manager.download(_ARCHIVES)
|
44 |
+
|
45 |
+
return [
|
46 |
+
datasets.SplitGenerator(
|
47 |
+
name = datasets.Split.VALIDATION,
|
48 |
+
gen_kwargs = {
|
49 |
+
"prompts_path": prompts_path["dev"],
|
50 |
+
"path_to_clips": _PATH_TO_CLIPS["dev"],
|
51 |
+
"audio_files": dl_manager.iter_archive(archive["dev"]),
|
52 |
+
}
|
53 |
+
),
|
54 |
+
]
|
55 |
+
|
56 |
+
def _generate_examples(self, prompts_path, path_to_clips, audio_files):
|
57 |
+
examples = {}
|
58 |
+
with open(prompts_path, "r") as f:
|
59 |
+
csv_reader = csv.DictReader(f)
|
60 |
+
for row in csv_reader:
|
61 |
+
audio_name = row['audio_name']
|
62 |
+
file_path = row['file_path']
|
63 |
+
text = row['text']
|
64 |
+
start_time = row['start_time']
|
65 |
+
end_time = row['end_time']
|
66 |
+
duration = row['duration']
|
67 |
+
quality = row['quality']
|
68 |
+
speech_genre = row['speech_genre']
|
69 |
+
speech_style = row['speech_style']
|
70 |
+
variety = row['variety']
|
71 |
+
accent = row['accent']
|
72 |
+
sex = row['sex']
|
73 |
+
age_range = row['age_range']
|
74 |
+
num_speakers = row['num_speakers']
|
75 |
+
speaker_id = row['speaker_id']
|
76 |
+
examples[file_path] = {
|
77 |
+
"audio_name": audio_name,
|
78 |
+
"file_path": file_path,
|
79 |
+
"text": text,
|
80 |
+
"start_time": start_time,
|
81 |
+
"end_time": end_time,
|
82 |
+
"duration": duration,
|
83 |
+
"quality": quality,
|
84 |
+
"speech_genre": speech_genre,
|
85 |
+
"speech_style": speech_style,
|
86 |
+
"variety": variety,
|
87 |
+
"accent": accent,
|
88 |
+
"sex": sex,
|
89 |
+
"age_range": age_range,
|
90 |
+
"num_speakers": num_speakers,
|
91 |
+
"speaker_id": speaker_id,
|
92 |
+
}
|
93 |
+
inside_clips_dir = False
|
94 |
+
id_ = 0
|
95 |
+
for path, f in audio_files:
|
96 |
+
if path.startswith(path_to_clips):
|
97 |
+
inside_clips_dir = True
|
98 |
+
if path in examples:
|
99 |
+
audio = {"path": path, "bytes": f.read()}
|
100 |
+
yield id_, {**examples[path], "audio": audio}
|
101 |
+
id_ += 1
|
102 |
+
elif inside_clips_dir:
|
103 |
+
break
|