marveleverthard
commited on
Commit
•
8dfa1a9
1
Parent(s):
cfd5828
Upload jv_id_asr_split.py
Browse files- jv_id_asr_split.py +162 -0
jv_id_asr_split.py
ADDED
@@ -0,0 +1,162 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
"jv_id_asr_train": "https://univindonesia-my.sharepoint.com/:u:/g/personal/marvel_martin_office_ui_ac_id/EePJbXPFbTNLlEweWxtBL6EBFCK19d6Ncj0PvAvbR9G-5A?e=bS3ELh",
|
57 |
+
"jv_id_asr_dev": "https://univindonesia-my.sharepoint.com/:u:/g/personal/marvel_martin_office_ui_ac_id/ESnRInfU0mJHq38mfHBXAqABrWWxIbnT06FiAcbWGtmvmg?e=dEZJG9",
|
58 |
+
"jv_id_asr_test": "https://univindonesia-my.sharepoint.com/:u:/g/personal/marvel_martin_office_ui_ac_id/EQGIXHDhNnVAsfkFurSdWrAB7r_jxq_PRLIbjeFG_Swlmw?e=rhBknp",
|
59 |
+
}
|
60 |
+
|
61 |
+
_SUPPORTED_TASKS = [Tasks.SPEECH_RECOGNITION] # example: [Tasks.TRANSLATION, Tasks.NAMED_ENTITY_RECOGNITION, Tasks.RELATION_EXTRACTION]
|
62 |
+
|
63 |
+
_SOURCE_VERSION = "1.0.0"
|
64 |
+
|
65 |
+
_SEACROWD_VERSION = "2024.06.20"
|
66 |
+
|
67 |
+
|
68 |
+
class JvIdASR(datasets.GeneratorBasedBuilder):
|
69 |
+
"""Javanese ASR training data set containing ~185K utterances."""
|
70 |
+
|
71 |
+
SOURCE_VERSION = datasets.Version(_SOURCE_VERSION)
|
72 |
+
SEACROWD_VERSION = datasets.Version(_SEACROWD_VERSION)
|
73 |
+
|
74 |
+
BUILDER_CONFIGS = [
|
75 |
+
SEACrowdConfig(
|
76 |
+
name="jv_id_asr_source",
|
77 |
+
version=SOURCE_VERSION,
|
78 |
+
description="jv_id_asr source schema",
|
79 |
+
schema="source",
|
80 |
+
subset_id="jv_id_asr",
|
81 |
+
),
|
82 |
+
SEACrowdConfig(
|
83 |
+
name="jv_id_asr_seacrowd_sptext",
|
84 |
+
version=SEACROWD_VERSION,
|
85 |
+
description="jv_id_asr Nusantara schema",
|
86 |
+
schema="seacrowd_sptext",
|
87 |
+
subset_id="jv_id_asr",
|
88 |
+
),
|
89 |
+
]
|
90 |
+
|
91 |
+
DEFAULT_CONFIG_NAME = "jv_id_asr_source"
|
92 |
+
|
93 |
+
def _info(self) -> datasets.DatasetInfo:
|
94 |
+
if self.config.schema == "source":
|
95 |
+
features = datasets.Features(
|
96 |
+
{
|
97 |
+
"id": datasets.Value("string"),
|
98 |
+
"speaker_id": datasets.Value("string"),
|
99 |
+
"path": datasets.Value("string"),
|
100 |
+
"audio": datasets.Audio(sampling_rate=16_000),
|
101 |
+
"text": datasets.Value("string"),
|
102 |
+
}
|
103 |
+
)
|
104 |
+
elif self.config.schema == "seacrowd_sptext":
|
105 |
+
features = schemas.speech_text_features
|
106 |
+
|
107 |
+
return datasets.DatasetInfo(
|
108 |
+
description=_DESCRIPTION,
|
109 |
+
features=features,
|
110 |
+
homepage=_HOMEPAGE,
|
111 |
+
license=_LICENSE,
|
112 |
+
citation=_CITATION,
|
113 |
+
)
|
114 |
+
|
115 |
+
def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
|
116 |
+
return [
|
117 |
+
datasets.SplitGenerator(
|
118 |
+
name=datasets.Split.TRAIN,
|
119 |
+
gen_kwargs={"filepath": dl_manager.download_and_extract(_URLs["jv_id_asr_train"])},
|
120 |
+
),
|
121 |
+
datasets.SplitGenerator(
|
122 |
+
name=datasets.Split.VALIDATION,
|
123 |
+
gen_kwargs={"filepath": dl_manager.download_and_extract(_URLs["jv_id_asr_dev"])},
|
124 |
+
),
|
125 |
+
datasets.SplitGenerator(
|
126 |
+
name=datasets.Split.TEST,
|
127 |
+
gen_kwargs={"filepath": dl_manager.download_and_extract(_URLs["jv_id_asr_test"])},
|
128 |
+
)
|
129 |
+
]
|
130 |
+
|
131 |
+
def _generate_examples(self, filepath: str):
|
132 |
+
tsv_file = os.path.join(filepath, "asr_javanese", "utt_spk_text.tsv")
|
133 |
+
with open(tsv_file, "r") as f:
|
134 |
+
tsv_file = csv.reader(f, delimiter="\t")
|
135 |
+
for line in tsv_file:
|
136 |
+
audio_id, sp_id, text = line[0], line[1], line[2]
|
137 |
+
wav_path = os.path.join(filepath, "asr_javanese", "data", "{}".format(audio_id[:2]), "{}.flac".format(audio_id))
|
138 |
+
|
139 |
+
if os.path.exists(wav_path):
|
140 |
+
if self.config.schema == "source":
|
141 |
+
ex = {
|
142 |
+
"id": audio_id,
|
143 |
+
"speaker_id": sp_id,
|
144 |
+
"path": wav_path,
|
145 |
+
"audio": wav_path,
|
146 |
+
"text": text,
|
147 |
+
}
|
148 |
+
yield audio_id, ex
|
149 |
+
elif self.config.schema == "seacrowd_sptext":
|
150 |
+
ex = {
|
151 |
+
"id": audio_id,
|
152 |
+
"speaker_id": sp_id,
|
153 |
+
"path": wav_path,
|
154 |
+
"audio": wav_path,
|
155 |
+
"text": text,
|
156 |
+
"metadata": {
|
157 |
+
"speaker_age": None,
|
158 |
+
"speaker_gender": None,
|
159 |
+
},
|
160 |
+
}
|
161 |
+
yield audio_id, ex
|
162 |
+
f.close()
|