Upload kscg_small_20v50_16k.py with huggingface_hub
Browse files- kscg_small_20v50_16k.py +89 -0
kscg_small_20v50_16k.py
ADDED
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import datasets
|
2 |
+
|
3 |
+
_DATA_URL = "data/kscg_small_20v50_16k.tar.gz"
|
4 |
+
|
5 |
+
_PROMPTS_URLS = {
|
6 |
+
"train": "data/prompts-train.txt.gz",
|
7 |
+
"test": "data/prompts-test.txt.gz",
|
8 |
+
}
|
9 |
+
|
10 |
+
class KscgSmall25(datasets.GeneratorBasedBuilder):
|
11 |
+
"""KSCG Small 20v50"""
|
12 |
+
|
13 |
+
def _info(self):
|
14 |
+
features = datasets.Features(
|
15 |
+
{
|
16 |
+
'path': datasets.Value('string'),
|
17 |
+
'audio': datasets.Audio(sampling_rate=16_000),
|
18 |
+
'gender': datasets.ClassLabel(
|
19 |
+
num_classes=2,
|
20 |
+
names=[
|
21 |
+
'M',
|
22 |
+
'F',
|
23 |
+
]
|
24 |
+
),
|
25 |
+
'age': datasets.ClassLabel(
|
26 |
+
num_classes=2,
|
27 |
+
names=[
|
28 |
+
'20s',
|
29 |
+
'50s'
|
30 |
+
]
|
31 |
+
)
|
32 |
+
}
|
33 |
+
)
|
34 |
+
|
35 |
+
return datasets.DatasetInfo(
|
36 |
+
features=features,
|
37 |
+
supervised_keys=None,
|
38 |
+
)
|
39 |
+
|
40 |
+
def _split_generators(self, dl_manager):
|
41 |
+
"""Returns SplitGenerators."""
|
42 |
+
|
43 |
+
prompts_paths = dl_manager.download_and_extract(_PROMPTS_URLS)
|
44 |
+
archive = dl_manager.download(_DATA_URL)
|
45 |
+
train_dir = "kscg_small_20v50/train"
|
46 |
+
test_dir = "kscg_small_20v50/test"
|
47 |
+
|
48 |
+
return [
|
49 |
+
datasets.SplitGenerator(
|
50 |
+
name=datasets.Split.TRAIN,
|
51 |
+
gen_kwargs={
|
52 |
+
"prompts_path": prompts_paths["train"],
|
53 |
+
"path_to_clips": train_dir,
|
54 |
+
"audio_files": dl_manager.iter_archive(archive)
|
55 |
+
},
|
56 |
+
),
|
57 |
+
datasets.SplitGenerator(
|
58 |
+
name=datasets.Split.TEST,
|
59 |
+
gen_kwargs={
|
60 |
+
"prompts_path": prompts_paths["test"],
|
61 |
+
"path_to_clips": test_dir,
|
62 |
+
"audio_files": dl_manager.iter_archive(archive)
|
63 |
+
},
|
64 |
+
),
|
65 |
+
]
|
66 |
+
|
67 |
+
def _generate_examples(self, prompts_path, path_to_clips, audio_files):
|
68 |
+
examples = {}
|
69 |
+
with open(prompts_path, encoding='utf-8') as f:
|
70 |
+
for row in f:
|
71 |
+
data = row.strip().split(",")
|
72 |
+
audio_path = data[0] + ".wav"
|
73 |
+
examples[audio_path] = {
|
74 |
+
'path': audio_path,
|
75 |
+
# 'phone_transcription': data[1],
|
76 |
+
'gender': data[1],
|
77 |
+
'age': data[2]
|
78 |
+
}
|
79 |
+
inside_clips_dir = False
|
80 |
+
id_ = 0
|
81 |
+
for path, f, in audio_files:
|
82 |
+
if path.startswith(path_to_clips):
|
83 |
+
inside_clips_dir = True
|
84 |
+
if path in examples:
|
85 |
+
audio = {"path": path, "bytes": f.read()}
|
86 |
+
yield id_, {**examples[path], "audio": audio}
|
87 |
+
id_ += 1
|
88 |
+
elif inside_clips_dir:
|
89 |
+
break
|