holylovenia commited on
Commit
8c7edea
1 Parent(s): afc6213

Upload jv_id_tts.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. jv_id_tts.py +186 -0
jv_id_tts.py ADDED
@@ -0,0 +1,186 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import csv
2
+ import os
3
+ from pathlib import Path
4
+ from typing import List
5
+
6
+ import datasets
7
+
8
+ from nusacrowd.utils import schemas
9
+ from nusacrowd.utils.configs import NusantaraConfig
10
+ from nusacrowd.utils.constants import (DEFAULT_NUSANTARA_VIEW_NAME,
11
+ DEFAULT_SOURCE_VIEW_NAME, Tasks)
12
+
13
+ _DATASETNAME = "jv_id_tts"
14
+ _SOURCE_VIEW_NAME = DEFAULT_SOURCE_VIEW_NAME
15
+ _UNIFIED_VIEW_NAME = DEFAULT_NUSANTARA_VIEW_NAME
16
+
17
+ _LANGUAGES = ["jav"]
18
+ _LOCAL = False
19
+ _CITATION = """\
20
+ @inproceedings{sodimana18_sltu,
21
+ author={Keshan Sodimana and Pasindu {De Silva} and Supheakmungkol Sarin and Oddur Kjartansson and Martin Jansche and Knot Pipatsrisawat and Linne Ha},
22
+ title={{A Step-by-Step Process for Building TTS Voices Using Open Source Data and Frameworks for Bangla, Javanese, Khmer, Nepali, Sinhala, and Sundanese}},
23
+ year=2018,
24
+ booktitle={Proc. 6th Workshop on Spoken Language Technologies for Under-Resourced Languages (SLTU 2018)},
25
+ pages={66--70},
26
+ doi={10.21437/SLTU.2018-14}
27
+ }
28
+ """
29
+
30
+ _DESCRIPTION = """\
31
+ This data set contains high-quality transcribed audio data for Javanese.
32
+ The data set consists of wave files, and a TSV file.
33
+ The file line_index.tsv contains a filename and the transcription of audio in the file.
34
+ Each filename is prepended with a speaker identification number.
35
+ The data set has been manually quality checked, but there might still be errors.
36
+ This dataset was collected by Google in collaboration with Gadjah Mada University in Indonesia.
37
+ """
38
+
39
+ _HOMEPAGE = "http://openslr.org/41/"
40
+
41
+ _LICENSE = "See https://www.openslr.org/resources/41/LICENSE file for license information. Attribution-ShareAlike 4.0 (CC BY-SA 4.0)."
42
+
43
+ _URLs = {
44
+ _DATASETNAME: {
45
+ "female": "https://www.openslr.org/resources/41/jv_id_female.zip",
46
+ "male": "https://www.openslr.org/resources/41/jv_id_male.zip",
47
+ }
48
+ }
49
+
50
+ _SUPPORTED_TASKS = [Tasks.TEXT_TO_SPEECH]
51
+
52
+ _SOURCE_VERSION = "1.0.0"
53
+ _NUSANTARA_VERSION = "1.0.0"
54
+
55
+
56
+ class JvIdTTS(datasets.GeneratorBasedBuilder):
57
+ """jv_id_tts contains high-quality Multi-speaker TTS data for Javanese (jv-ID)."""
58
+
59
+ BUILDER_CONFIGS = [
60
+ NusantaraConfig(
61
+ name="jv_id_tts_source",
62
+ version=datasets.Version(_SOURCE_VERSION),
63
+ description="JV_ID_TTS source schema",
64
+ schema="source",
65
+ subset_id="jv_id_tts",
66
+ ),
67
+ NusantaraConfig(
68
+ name="jv_id_tts_nusantara_sptext",
69
+ version=datasets.Version(_NUSANTARA_VERSION),
70
+ description="JV_ID_TTS Nusantara schema",
71
+ schema="nusantara_sptext",
72
+ subset_id="jv_id_tts",
73
+ ),
74
+ ]
75
+
76
+ DEFAULT_CONFIG_NAME = "jv_id_tts_source"
77
+
78
+ def _info(self):
79
+ if self.config.schema == "source":
80
+ features = datasets.Features(
81
+ {
82
+ "id": datasets.Value("string"),
83
+ "speaker_id": datasets.Value("string"),
84
+ "path": datasets.Value("string"),
85
+ "audio": datasets.Audio(sampling_rate=16_000),
86
+ "text": datasets.Value("string"),
87
+ }
88
+ )
89
+ elif self.config.schema == "nusantara_sptext":
90
+ features = schemas.speech_text_features
91
+
92
+ return datasets.DatasetInfo(
93
+ description=_DESCRIPTION,
94
+ features=features,
95
+ homepage=_HOMEPAGE,
96
+ license=_LICENSE,
97
+ citation=_CITATION,
98
+ task_templates=[datasets.AutomaticSpeechRecognition(audio_column="audio", transcription_column="text")],
99
+ )
100
+
101
+ def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
102
+ male_path = Path(dl_manager.download_and_extract(_URLs[_DATASETNAME]["male"]))
103
+ female_path = Path(dl_manager.download_and_extract(_URLs[_DATASETNAME]["female"]))
104
+
105
+ return [
106
+ datasets.SplitGenerator(
107
+ name=datasets.Split.TRAIN,
108
+ gen_kwargs={
109
+ "male_filepath": male_path,
110
+ "female_filepath": female_path,
111
+ },
112
+ ),
113
+ ]
114
+
115
+ def _generate_examples(self, male_filepath: Path, female_filepath: Path):
116
+
117
+ if self.config.schema == "source" or self.config.schema == "nusantara_sptext":
118
+ tsv_file = os.path.join(male_filepath, "jv_id_male", "line_index.tsv")
119
+ with open(tsv_file, "r") as file:
120
+ tsv_data = csv.reader(file, delimiter="\t")
121
+
122
+ for line in tsv_data:
123
+ # for male data, the tsv contains three columns
124
+ audio_id, _, transcription_text = line[0], line[1], line[2]
125
+ speaker_id = audio_id.split("_")[1]
126
+ wav_path = os.path.join(male_filepath, "jv_id_male", "wavs", "{}.wav".format(audio_id))
127
+
128
+ if os.path.exists(wav_path):
129
+ if self.config.schema == "source":
130
+ ex = {
131
+ "id": audio_id,
132
+ "speaker_id": speaker_id,
133
+ "path": wav_path,
134
+ "audio": wav_path,
135
+ "text": transcription_text,
136
+ }
137
+ yield audio_id, ex
138
+ elif self.config.schema == "nusantara_sptext":
139
+ ex = {
140
+ "id": audio_id,
141
+ "speaker_id": speaker_id,
142
+ "path": wav_path,
143
+ "audio": wav_path,
144
+ "text": transcription_text,
145
+ "metadata": {
146
+ "speaker_age": None,
147
+ "speaker_gender": "male",
148
+ },
149
+ }
150
+ yield audio_id, ex
151
+
152
+ tsv_file = os.path.join(female_filepath, "jv_id_female", "line_index.tsv")
153
+ with open(tsv_file, "r") as file:
154
+ tsv_data = csv.reader(file, delimiter="\t")
155
+
156
+ for line in tsv_data:
157
+ audio_id, transcription_text = line[0], line[1]
158
+ speaker_id = audio_id.split("_")[1]
159
+ wav_path = os.path.join(female_filepath, "jv_id_female", "wavs", "{}.wav".format(audio_id))
160
+
161
+ if os.path.exists(wav_path):
162
+ if self.config.schema == "source":
163
+ ex = {
164
+ "id": audio_id,
165
+ "speaker_id": speaker_id,
166
+ "path": wav_path,
167
+ "audio": wav_path,
168
+ "text": transcription_text,
169
+ }
170
+ yield audio_id, ex
171
+ elif self.config.schema == "nusantara_sptext":
172
+ ex = {
173
+ "id": audio_id,
174
+ "speaker_id": speaker_id,
175
+ "path": wav_path,
176
+ "audio": wav_path,
177
+ "text": transcription_text,
178
+ "metadata": {
179
+ "speaker_age": None,
180
+ "speaker_gender": "female",
181
+ },
182
+ }
183
+ yield audio_id, ex
184
+ else:
185
+ raise ValueError(f"Invalid config: {self.config.name}")
186
+