holylovenia commited on
Commit
b3a759a
1 Parent(s): d3b2621

Upload jv_id_asr.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. jv_id_asr.py +159 -0
jv_id_asr.py ADDED
@@ -0,0 +1,159 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright 2022 The HuggingFace Datasets Authors and the current dataset script contributor.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ import csv
17
+ import os
18
+ from pathlib import Path
19
+ from typing import List
20
+
21
+ import datasets
22
+
23
+ from seacrowd.utils import schemas
24
+ from seacrowd.utils.configs import SEACrowdConfig
25
+ from seacrowd.utils.constants import Tasks
26
+
27
+ _CITATION = """\
28
+ @inproceedings{kjartansson-etal-sltu2018,
29
+ title = {{Crowd-Sourced Speech Corpora for Javanese, Sundanese, Sinhala, Nepali, and Bangladeshi Bengali}},
30
+ author = {Oddur Kjartansson and Supheakmungkol Sarin and Knot Pipatsrisawat and Martin Jansche and Linne Ha},
31
+ booktitle = {Proc. The 6th Intl. Workshop on Spoken Language Technologies for Under-Resourced Languages (SLTU)},
32
+ year = {2018},
33
+ address = {Gurugram, India},
34
+ month = aug,
35
+ pages = {52--55},
36
+ URL = {http://dx.doi.org/10.21437/SLTU.2018-11},
37
+ }
38
+ """
39
+
40
+ _DATASETNAME = "jv_id_asr"
41
+
42
+ _DESCRIPTION = """\
43
+ This data set contains transcribed audio data for Javanese. The data set consists of wave files, and a TSV file.
44
+ The file utt_spk_text.tsv contains a FileID, UserID and the transcription of audio in the file.
45
+ The data set has been manually quality checked, but there might still be errors.
46
+ This dataset was collected by Google in collaboration with Reykjavik University and Universitas Gadjah Mada in Indonesia.
47
+ """
48
+
49
+ _HOMEPAGE = "http://openslr.org/35/"
50
+ _LANGUAGES = ["jav"]
51
+ _LOCAL = False
52
+
53
+ _LICENSE = "Attribution-ShareAlike 4.0 International"
54
+
55
+ _URLS = {
56
+ _DATASETNAME: "https://www.openslr.org/resources/35/asr_javanese_{}.zip",
57
+ }
58
+
59
+ _SUPPORTED_TASKS = [Tasks.SPEECH_RECOGNITION] # example: [Tasks.TRANSLATION, Tasks.NAMED_ENTITY_RECOGNITION, Tasks.RELATION_EXTRACTION]
60
+
61
+ _SOURCE_VERSION = "1.0.0"
62
+
63
+ _SEACROWD_VERSION = "2024.06.20"
64
+
65
+
66
+ class JvIdASR(datasets.GeneratorBasedBuilder):
67
+ """Javanese ASR training data set containing ~185K utterances."""
68
+
69
+ SOURCE_VERSION = datasets.Version(_SOURCE_VERSION)
70
+ SEACROWD_VERSION = datasets.Version(_SEACROWD_VERSION)
71
+
72
+ BUILDER_CONFIGS = [
73
+ SEACrowdConfig(
74
+ name="jv_id_asr_source",
75
+ version=SOURCE_VERSION,
76
+ description="jv_id_asr source schema",
77
+ schema="source",
78
+ subset_id="jv_id_asr",
79
+ ),
80
+ SEACrowdConfig(
81
+ name="jv_id_asr_seacrowd_sptext",
82
+ version=SEACROWD_VERSION,
83
+ description="jv_id_asr Nusantara schema",
84
+ schema="seacrowd_sptext",
85
+ subset_id="jv_id_asr",
86
+ ),
87
+ ]
88
+
89
+ DEFAULT_CONFIG_NAME = "jv_id_asr_source"
90
+
91
+ def _info(self) -> datasets.DatasetInfo:
92
+ if self.config.schema == "source":
93
+ features = datasets.Features(
94
+ {
95
+ "id": datasets.Value("string"),
96
+ "speaker_id": datasets.Value("string"),
97
+ "path": datasets.Value("string"),
98
+ "audio": datasets.Audio(sampling_rate=16_000),
99
+ "text": datasets.Value("string"),
100
+ }
101
+ )
102
+ elif self.config.schema == "seacrowd_sptext":
103
+ features = schemas.speech_text_features
104
+
105
+ return datasets.DatasetInfo(
106
+ description=_DESCRIPTION,
107
+ features=features,
108
+ homepage=_HOMEPAGE,
109
+ license=_LICENSE,
110
+ citation=_CITATION,
111
+ )
112
+
113
+ def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
114
+ urls = _URLS[_DATASETNAME]
115
+ base_path = {}
116
+ for id in range(10):
117
+ base_path[id] = dl_manager.download_and_extract(urls.format(str(id)))
118
+ for id in ["a", "b", "c", "d", "e", "f"]:
119
+ base_path[id] = dl_manager.download_and_extract(urls.format(str(id)))
120
+ return [
121
+ datasets.SplitGenerator(
122
+ name=datasets.Split.TRAIN,
123
+ gen_kwargs={"filepath": base_path},
124
+ ),
125
+ ]
126
+
127
+ def _generate_examples(self, filepath: Path):
128
+ for key, fp in filepath.items():
129
+ tsv_file = os.path.join(fp, "asr_javanese", "utt_spk_text.tsv")
130
+ with open(tsv_file, "r") as f:
131
+ tsv_file = csv.reader(f, delimiter="\t")
132
+ for line in tsv_file:
133
+ audio_id, sp_id, text = line[0], line[1], line[2]
134
+ wav_path = os.path.join(fp, "asr_javanese", "data", "{}".format(audio_id[:2]), "{}.flac".format(audio_id))
135
+
136
+ if os.path.exists(wav_path):
137
+ if self.config.schema == "source":
138
+ ex = {
139
+ "id": audio_id,
140
+ "speaker_id": sp_id,
141
+ "path": wav_path,
142
+ "audio": wav_path,
143
+ "text": text,
144
+ }
145
+ yield audio_id, ex
146
+ elif self.config.schema == "seacrowd_sptext":
147
+ ex = {
148
+ "id": audio_id,
149
+ "speaker_id": sp_id,
150
+ "path": wav_path,
151
+ "audio": wav_path,
152
+ "text": text,
153
+ "metadata": {
154
+ "speaker_age": None,
155
+ "speaker_gender": None,
156
+ },
157
+ }
158
+ yield audio_id, ex
159
+ f.close()