sidleal commited on
Commit
c46123b
·
verified ·
1 Parent(s): 5e3ddb7

new metadata

Browse files
Files changed (1) hide show
  1. CORAA-MUPE-ASR.py +132 -117
CORAA-MUPE-ASR.py CHANGED
@@ -1,117 +1,132 @@
1
- import csv
2
- import datasets
3
-
4
- _PROMPTS_URLS = {
5
- "train": "train.csv",
6
- "validation": "validation.csv",
7
- "test": "test.csv",
8
- }
9
-
10
- _ARCHIVES = {
11
- "train": "train.tar.gz",
12
- "validation": "validation.tar.gz",
13
- "test": "test.tar.gz",
14
- }
15
-
16
- _PATH_TO_CLIPS = {
17
- "train": "train",
18
- "validation": "validation",
19
- "test": "test",
20
- }
21
-
22
- class MUPEASRDataset(datasets.GeneratorBasedBuilder):
23
- def _info(self):
24
- return datasets.DatasetInfo(
25
- features=datasets.Features(
26
- {
27
- "audio_id": datasets.Value("int64"),
28
- "audio_name": datasets.Value("string"),
29
- "file_path": datasets.Value("string"),
30
- "speaker_type": datasets.Value("string"),
31
- "speaker_code": datasets.Value("string"),
32
- "speaker_gender": datasets.Value("string"),
33
- "audio_quality": datasets.Value("string"),
34
- "start_time": datasets.Value("float32"),
35
- "end_time": datasets.Value("float32"),
36
- "duration": datasets.Value("float32"),
37
- "normalized_text": datasets.Value("string"),
38
- "original_text": datasets.Value("string"),
39
- "audio": datasets.Audio(sampling_rate=16_000),
40
- }
41
- )
42
- )
43
-
44
- def _split_generators(self, dl_manager):
45
- prompts_path = dl_manager.download(_PROMPTS_URLS)
46
- archive = dl_manager.download(_ARCHIVES)
47
-
48
- return [
49
- datasets.SplitGenerator(
50
- name = datasets.Split.VALIDATION,
51
- gen_kwargs = {
52
- "prompts_path": prompts_path["validation"],
53
- "path_to_clips": _PATH_TO_CLIPS["validation"],
54
- "audio_files": dl_manager.iter_archive(archive["validation"]),
55
- }
56
- ),
57
- datasets.SplitGenerator(
58
- name = datasets.Split.TEST,
59
- gen_kwargs = {
60
- "prompts_path": prompts_path["test"],
61
- "path_to_clips": _PATH_TO_CLIPS["test"],
62
- "audio_files": dl_manager.iter_archive(archive["test"]),
63
- }
64
- ),
65
- datasets.SplitGenerator(
66
- name = datasets.Split.TRAIN,
67
- gen_kwargs = {
68
- "prompts_path": prompts_path["train"],
69
- "path_to_clips": _PATH_TO_CLIPS["train"],
70
- "audio_files": dl_manager.iter_archive(archive["train"]),
71
- }
72
- ),
73
- ]
74
-
75
- def _generate_examples(self, prompts_path, path_to_clips, audio_files):
76
- examples = {}
77
- with open(prompts_path, "r") as f:
78
- csv_reader = csv.DictReader(f)
79
- for row in csv_reader:
80
- audio_id = row['audio_id']
81
- audio_name = row['audio_name']
82
- file_path = row['file_path']
83
- speaker_type = row['speaker_type']
84
- speaker_code = row['speaker_code']
85
- speaker_gender = row['speaker_gender']
86
- audio_quality = row['audio_quality']
87
- start_time = row['start_time']
88
- end_time = row['end_time']
89
- duration = row['duration']
90
- normalized_text = row['normalized_text']
91
- original_text = row['original_text']
92
-
93
- examples[file_path] = {
94
- "audio_id" : audio_id,
95
- "audio_name" : audio_name,
96
- "file_path" : file_path,
97
- "speaker_type" : speaker_type,
98
- "speaker_code" : speaker_code,
99
- "speaker_gender" : speaker_gender,
100
- "audio_quality" : audio_quality,
101
- "start_time" : start_time,
102
- "end_time" : end_time,
103
- "duration" : duration,
104
- "normalized_text" : normalized_text,
105
- "original_text" : original_text,
106
- }
107
- inside_clips_dir = False
108
- id_ = 0
109
- for path, f in audio_files:
110
- if path.startswith(path_to_clips):
111
- inside_clips_dir = True
112
- if path in examples:
113
- audio = {"path": path, "bytes": f.read()}
114
- yield id_, {**examples[path], "audio": audio}
115
- id_ += 1
116
- elif inside_clips_dir:
117
- break
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import csv
2
+ import datasets
3
+
4
+ _PROMPTS_URLS = {
5
+ "train": "train.csv",
6
+ "validation": "validation.csv",
7
+ "test": "test.csv",
8
+ }
9
+
10
+ _ARCHIVES = {
11
+ "train": "train.tar.gz",
12
+ "validation": "validation.tar.gz",
13
+ "test": "test.tar.gz",
14
+ }
15
+
16
+ _PATH_TO_CLIPS = {
17
+ "train": "train",
18
+ "validation": "validation",
19
+ "test": "test",
20
+ }
21
+
22
+ class MUPEASRDataset(datasets.GeneratorBasedBuilder):
23
+ def _info(self):
24
+ return datasets.DatasetInfo(
25
+ features=datasets.Features(
26
+ {
27
+ "audio_id": datasets.Value("int64"),
28
+ "audio_name": datasets.Value("string"),
29
+ "file_path": datasets.Value("string"),
30
+ "speaker_type": datasets.Value("string"),
31
+ "speaker_code": datasets.Value("string"),
32
+ "speaker_gender": datasets.Value("string"),
33
+ "education": datasets.Value("string"),
34
+ "birth_state": datasets.Value("string"),
35
+ "birth_country": datasets.Value("string"),
36
+ "age": datasets.Value("int64"),
37
+ "birth_year": datasets.Value("int64"),
38
+ "audio_quality": datasets.Value("string"),
39
+ "start_time": datasets.Value("float32"),
40
+ "end_time": datasets.Value("float32"),
41
+ "duration": datasets.Value("float32"),
42
+ "normalized_text": datasets.Value("string"),
43
+ "original_text": datasets.Value("string"),
44
+ "audio": datasets.Audio(sampling_rate=16_000),
45
+ }
46
+ )
47
+ )
48
+
49
+ def _split_generators(self, dl_manager):
50
+ prompts_path = dl_manager.download(_PROMPTS_URLS)
51
+ archive = dl_manager.download(_ARCHIVES)
52
+
53
+ return [
54
+ datasets.SplitGenerator(
55
+ name = datasets.Split.VALIDATION,
56
+ gen_kwargs = {
57
+ "prompts_path": prompts_path["validation"],
58
+ "path_to_clips": _PATH_TO_CLIPS["validation"],
59
+ "audio_files": dl_manager.iter_archive(archive["validation"]),
60
+ }
61
+ ),
62
+ datasets.SplitGenerator(
63
+ name = datasets.Split.TEST,
64
+ gen_kwargs = {
65
+ "prompts_path": prompts_path["test"],
66
+ "path_to_clips": _PATH_TO_CLIPS["test"],
67
+ "audio_files": dl_manager.iter_archive(archive["test"]),
68
+ }
69
+ ),
70
+ datasets.SplitGenerator(
71
+ name = datasets.Split.TRAIN,
72
+ gen_kwargs = {
73
+ "prompts_path": prompts_path["train"],
74
+ "path_to_clips": _PATH_TO_CLIPS["train"],
75
+ "audio_files": dl_manager.iter_archive(archive["train"]),
76
+ }
77
+ ),
78
+ ]
79
+
80
+ def _generate_examples(self, prompts_path, path_to_clips, audio_files):
81
+ examples = {}
82
+ with open(prompts_path, "r") as f:
83
+ csv_reader = csv.DictReader(f)
84
+ for row in csv_reader:
85
+ audio_id = row['audio_id']
86
+ audio_name = row['audio_name']
87
+ file_path = row['file_path']
88
+ speaker_type = row['speaker_type']
89
+ speaker_code = row['speaker_code']
90
+ speaker_gender = row['speaker_gender']
91
+ education = row['education']
92
+ birth_state = row['birth_state']
93
+ birth_country = row['birth_country']
94
+ age = row['age']
95
+ birth_year = row['birth_year']
96
+ audio_quality = row['audio_quality']
97
+ start_time = row['start_time']
98
+ end_time = row['end_time']
99
+ duration = row['duration']
100
+ normalized_text = row['normalized_text']
101
+ original_text = row['original_text']
102
+
103
+ examples[file_path] = {
104
+ "audio_id" : audio_id,
105
+ "audio_name" : audio_name,
106
+ "file_path" : file_path,
107
+ "speaker_type" : speaker_type,
108
+ "speaker_code" : speaker_code,
109
+ "speaker_gender" : speaker_gender,
110
+ "education" : education,
111
+ "birth_state" : birth_state,
112
+ "birth_country" : birth_country,
113
+ "age" : age,
114
+ "birth_year" : birth_year,
115
+ "audio_quality" : audio_quality,
116
+ "start_time" : start_time,
117
+ "end_time" : end_time,
118
+ "duration" : duration,
119
+ "normalized_text" : normalized_text,
120
+ "original_text" : original_text,
121
+ }
122
+ inside_clips_dir = False
123
+ id_ = 0
124
+ for path, f in audio_files:
125
+ if path.startswith(path_to_clips):
126
+ inside_clips_dir = True
127
+ if path in examples:
128
+ audio = {"path": path, "bytes": f.read()}
129
+ yield id_, {**examples[path], "audio": audio}
130
+ id_ += 1
131
+ elif inside_clips_dir:
132
+ break