import gzip import json import re import os import datasets logger = datasets.logging.get_logger(__name__) _DESCRIPTION = """\ This data set contains multi-speaker high quality transcribed audio data for Sinhalese. The data set consists of wave files, and a TSV file. The file si_lk.lines.txt contains a FileID, which in tern contains the UserID and the Transcription of audio in the file. The data set has been manually quality checked, but there might still be errors. This dataset was collected by Google in Sri Lanka. """ _CITATION = """ @inproceedings{kjartansson-etal-tts-sltu2018, title = {{A Step-by-Step Process for Building TTS Voices Using Open Source Data and Framework for Bangla, Javanese, Khmer, Nepali, Sinhala, and Sundanese}}, author = {Keshan Sodimana and Knot Pipatsrisawat and Linne Ha and Martin Jansche and Oddur Kjartansson and Pasindu De Silva and Supheakmungkol Sarin}, booktitle = {Proc. The 6th Intl. Workshop on Spoken Language Technologies for Under-Resourced Languages (SLTU)}, year = {2018}, address = {Gurugram, India}, month = aug, pages = {66--70}, URL = {http://dx.doi.org/10.21437/SLTU.2018-14} } """ _URL = "https://www.openslr.org/30/" _DATA_URL = "https://www.openslr.org/resources/30/si_lk.tar.gz" _LICENSE = "https://www.openslr.org/resources/30/LICENSE.txt" _LANGUAGES = [ "si", ] class SiTTSConfig(datasets.BuilderConfig): """BuilderConfig for SiTTS.""" def __init__(self, *args, languages, **kwargs): """BuilderConfig for SiTTS. Args: languages (:obj:`List[str]`): list of languages to load **kwargs: keyword arguments forwarded to super. """ super().__init__( *args, name="+".join(languages), **kwargs, ) self.languages = languages class SiTTS(datasets.GeneratorBasedBuilder): """SiTTS, a manually quality checked, Sinhala multi-speaker TTS corpora.""" BUILDER_CONFIGS = [SiTTSConfig(languages=[lang]) for lang in _LANGUAGES] BUILDER_CONFIG_CLASS = SiTTSConfig def _info(self): return datasets.DatasetInfo( description=_DESCRIPTION, features=datasets.Features( { "sentence": datasets.Value("string"), "file_path": datasets.Value("string"), } ), supervised_keys=None, homepage=_URL, citation=_CITATION, license=_LICENSE, ) def _split_generators(self, dl_manager): abs_path_to_clips = dl_manager.download_and_extract(_DATA_URL) abs_path_to_data = dl_manager.download(f"{_URL}si_lk.lines.txt") return [ datasets.SplitGenerator( name=datasets.Split.TRAIN, gen_kwargs={ "filepath": os.path.join(abs_path_to_data, "si_lk.lines.txt"), "path_to_clips": abs_path_to_clips, }, ), ] def _generate_examples(self, filepath, path_to_clips): data_fields = list(self._info().features.keys()) path_idx = data_fields.index("file_path") with open(filepath, encoding="utf-8") as f: lines = f.readlines() for id_, line in enumerate(lines): sentence = re.findall(r'"(.*?)"', line)[0].strip() file_path = f'{re.findall(r"(sin_[^\s]+)", line)[0]}.wav' field_values = [sentence, file_path] # set absolute path for wav audio file field_values[path_idx] = os.path.join( path_to_clips, field_values[path_idx] ) # if data is incomplete, fill with empty values if len(field_values) < len(data_fields): field_values += (len(data_fields) - len(field_values)) * ["''"] yield id_, {key: value for key, value in zip(data_fields, field_values)}