slplab commited on
Commit
11801b3
1 Parent(s): 4093f5a

Upload asd_syl_240115.py with huggingface_hub

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