# coding=utf-8 # Copyright 2021 Artem Ploujnikov # Lint as: python3 import json import datasets _DESCRIPTION = """\ This is a public domain speech dataset consisting of 13,100 short audio clips of a single speaker reading passages from 7 non-fiction books. A transcription is provided for each clip. Clips vary in length from 1 to 10 seconds and have a total length of approximately 24 hours. """ _BASE_URL = "https://huggingface.co/datasets/flexthink/librig2p-nostress-space/resolve/main" _HOMEPAGE_URL = "https://huggingface.co/datasets/flexthink/ljspeech" _PHONEMES = [ "AA", "AE", "AH", "AO", "AW", "AY", "B", "CH", "D", "DH", "EH", "ER", "EY", "F", "G", "HH", "IH", "IY", "JH", "K", "L", "M", "N", "NG", "OW", "OY", "P", "R", "S", "SH", "T", "TH", "UH", "UW", "V", "W", "Y", "Z", "ZH", " " ] _SPLITS = ["train", "valid", "test"] class LJSpeech(datasets.GeneratorBasedBuilder): def __init__(self, base_url=None, splits=None, *args, **kwargs): super().__init__(*args, **kwargs) self.base_url = base_url or _BASE_URL self.splits = splits or _SPLITS def _info(self): return datasets.DatasetInfo( description=_DESCRIPTION, features=datasets.Features( { "char": datasets.Value("string"), "phn_raw": datasets.Sequence(datasets.Value("string")), "phn": datasets.Sequence(datasets.ClassLabel(names=_PHONEMES)), "wav": datasets.Value("string"), }, ), supervised_keys=None, homepage=_HOMEPAGE_URL, ) def _get_url(self, split): return f'{self.base_url}/ljspeech_{split}.json' def _split_generator(self, dl_manager, split): url = self._get_url(split) path = dl_manager.download_and_extract(url) return datasets.SplitGenerator( name=split, gen_kwargs={"datapath": path, "datatype": split}, ) def _split_generators(self, dl_manager): return [ self._split_generator(dl_manager, split) for split in self.splits ] def _generate_examples(self, datapath, datatype): with open(datapath, encoding="utf-8") as f: data = json.load(f) for item_id, item in data.items(): resp = { "char": item["char"], "phn": item["phn"], "phn_raw": item["phn"], "wav": item["wav"] } yield item_id, resp