retineo commited on
Commit
f93ba28
·
verified ·
1 Parent(s): 32f3b10

Update su_id_asr_split.py

Browse files
Files changed (1) hide show
  1. su_id_asr_split.py +54 -70
su_id_asr_split.py CHANGED
@@ -38,7 +38,9 @@ _HOMEPAGE = "https://indonlp.github.io/nusa-catalogue/card.html?su_id_asr"
38
  _LICENSE = "Attribution-ShareAlike 4.0 International."
39
 
40
  _URLs = {
41
- "su_id_asr": "https://www.openslr.org/resources/36/asr_sundanese_{}.zip",
 
 
42
  }
43
 
44
  _SUPPORTED_TASKS = [Tasks.SPEECH_RECOGNITION]
@@ -93,76 +95,58 @@ class SuIdASR(datasets.GeneratorBasedBuilder):
93
  )
94
 
95
  def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
96
- lines = []
97
- filepath = dl_manager.download_and_extract(_URLs["su_id_asr"].format(str(0)))
98
- tsv_file = os.path.join(filepath, "asr_sundanese", "utt_spk_text.tsv")
99
-
100
- with open(tsv_file, "r") as file:
101
- tsv_file = csv.reader(file, delimiter="\t")
102
-
103
- for line in tsv_file:
104
- lines.append(line)
105
-
106
- rlen = len(lines)
107
-
108
- split_generators = []
109
- split_names = {
110
- "train": datasets.Split.TRAIN,
111
- "dev": datasets.Split.VALIDATION,
112
- "test": datasets.Split.TEST,
113
- }
114
- split_set = {
115
- "train": 8*rlen//10,
116
- "dev": rlen//10+1,
117
- "test": rlen//10+1,
118
- }
119
-
120
- for split in ("train", "dev", "test"):
121
- split_generators.append(
122
- datasets.SplitGenerator(
123
- name=split_names.get(split),
124
- gen_kwargs={
125
- "tsv_file": lines[:split_set.get(split)],
126
- "filepath": filepath,
127
- },
128
- ),
129
  )
130
- lines = lines[split_set.get(split):]
131
 
132
- return split_generators
133
-
134
- def _generate_examples(self, filepath: str, tsv_file):
135
 
136
  if self.config.schema == "source" or self.config.schema == "seacrowd_sptext":
137
-
138
- for line in tsv_file:
139
- audio_id, speaker_id, transcription_text = line[0], line[1], line[2]
140
-
141
- wav_path = os.path.join(filepath, "asr_sundanese", "data", "{}".format(audio_id[:2]), "{}.flac".format(audio_id))
142
-
143
- if os.path.exists(wav_path):
144
- if self.config.schema == "source":
145
- ex = {
146
- "id": audio_id,
147
- "speaker_id": speaker_id,
148
- "path": wav_path,
149
- "audio": wav_path,
150
- "text": transcription_text,
151
- }
152
- yield audio_id, ex
153
- elif self.config.schema == "seacrowd_sptext":
154
- ex = {
155
- "id": audio_id,
156
- "speaker_id": speaker_id,
157
- "path": wav_path,
158
- "audio": wav_path,
159
- "text": transcription_text,
160
- "metadata": {
161
- "speaker_age": None,
162
- "speaker_gender": None,
163
- },
164
- }
165
- yield audio_id, ex
166
-
167
- else:
168
- raise ValueError(f"Invalid config: {self.config.name}")
 
 
 
 
 
 
38
  _LICENSE = "Attribution-ShareAlike 4.0 International."
39
 
40
  _URLs = {
41
+ "su_id_asr_train": "https://univindonesia-my.sharepoint.com/:u:/g/personal/bimasena_putra_office_ui_ac_id/EdJMdFZbSp5LlAT0TEP2fvcB38OHB1hIRslTpCs-wTrJMA?e=jfK6xC",
42
+ "su_id_asr_dev": "https://univindonesia-my.sharepoint.com/:u:/g/personal/bimasena_putra_office_ui_ac_id/Efe8LnwT8KtOjJybXjOQdFwBso5RBp39SwGGWsEbindXDQ?e=IFIN6J",
43
+ "su_id_asr_test": "https://univindonesia-my.sharepoint.com/:u:/g/personal/bimasena_putra_office_ui_ac_id/EfjvnrniV_hKmrSMY0XYvt8BXiXx5SNxt5mhfLiMw0dExw?e=zGCjc5",
44
  }
45
 
46
  _SUPPORTED_TASKS = [Tasks.SPEECH_RECOGNITION]
 
95
  )
96
 
97
  def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
98
+ return [
99
+ datasets.SplitGenerator(
100
+ name=datasets.Split.TRAIN,
101
+ gen_kwargs={"filepath": dl_manager.download_and_extract(_URLs["su_id_asr_train"])},
102
+ ),
103
+ datasets.SplitGenerator(
104
+ name=datasets.Split.VALIDATION,
105
+ gen_kwargs={"filepath": dl_manager.download_and_extract(_URLs["su_id_asr_dev"])},
106
+ ),
107
+ datasets.SplitGenerator(
108
+ name=datasets.Split.TEST,
109
+ gen_kwargs={"filepath": dl_manager.download_and_extract(_URLs["su_id_asr_test"])},
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
110
  )
111
+ ]
112
 
113
+ def _generate_examples(self, filepath: str):
 
 
114
 
115
  if self.config.schema == "source" or self.config.schema == "seacrowd_sptext":
116
+
117
+ tsv_file = os.path.join(filepath, "asr_sundanese", "utt_spk_text.tsv")
118
+
119
+ with open(tsv_file, "r") as file:
120
+ tsv_file = csv.reader(file, delimiter="\t")
121
+
122
+ for line in tsv_file:
123
+ audio_id, speaker_id, transcription_text = line[0], line[1], line[2]
124
+
125
+ wav_path = os.path.join(filepath, "asr_sundanese", "data", "{}".format(audio_id[:2]), "{}.flac".format(audio_id))
126
+
127
+ if os.path.exists(wav_path):
128
+ if self.config.schema == "source":
129
+ ex = {
130
+ "id": audio_id,
131
+ "speaker_id": speaker_id,
132
+ "path": wav_path,
133
+ "audio": wav_path,
134
+ "text": transcription_text,
135
+ }
136
+ yield audio_id, ex
137
+ elif self.config.schema == "seacrowd_sptext":
138
+ ex = {
139
+ "id": audio_id,
140
+ "speaker_id": speaker_id,
141
+ "path": wav_path,
142
+ "audio": wav_path,
143
+ "text": transcription_text,
144
+ "metadata": {
145
+ "speaker_age": None,
146
+ "speaker_gender": None,
147
+ },
148
+ }
149
+ yield audio_id, ex
150
+
151
+ else:
152
+ raise ValueError(f"Invalid config: {self.config.name}")