from datasets import Dataset, GeneratorBasedBuilder, Features import os import tarfile import librosa import datasets _LICENSE = "https://creativecommons.org/licenses/by/4.0/" _HOMEPAGE = "https://lindat.mff.cuni.cz/repository/xmlui/handle/11234/1-3126" _DATASET_URL = "https://lindat.mff.cuni.cz/repository/xmlui/bitstream/handle/11234/1-3126/snemovna.tar.xz" _DESCRIPTION = "Large corpus of Czech parliament plenary sessions, originaly released 2019-11-29 by Kratochvíl Jonáš, Polák Peter and Bojar Ondřej\ The dataset consists of 444 hours of transcribed speech audio snippets 1 to 40 seconds long.\ Original dataset transcriptions were converted to true case from uppercase using spacy library." _CITATION = """\ @misc{11234/1-3126, title = {Large Corpus of Czech Parliament Plenary Hearings}, author = {Kratochv{\'{\i}}l, Jon{\'a}{\v s} and Pol{\'a}k, Peter and Bojar, Ond{\v r}ej}, url = {http://hdl.handle.net/11234/1-3126}, note = {{LINDAT}/{CLARIAH}-{CZ} digital library at the Institute of Formal and Applied Linguistics ({{\'U}FAL}), Faculty of Mathematics and Physics, Charles University}, copyright = {Creative Commons - Attribution 4.0 International ({CC} {BY} 4.0)}, year = {2019} } """ class CzechParliamentPlenaryHearings(GeneratorBasedBuilder): def __init__(self, **kwargs): super().__init__(**kwargs) def _info(self): return datasets.DatasetInfo( description=_DESCRIPTION, features=datasets.Features( { "id": datasets.Value("string"), "audio": datasets.features.Audio(sampling_rate=16000), "transcription": datasets.Value("string") } ), supervised_keys=None, homepage=_HOMEPAGE, citation=_CITATION, license=_LICENSE ) def _split_generators(self, dl_manager): archive_path = dl_manager.download(_DATASET_URL) data_dir = os.path.join(archive_path, 'ASR_DATA') splits = ("train", "dev", "test") split_names = { "train": datasets.Split.TRAIN, "dev": datasets.Split.VALIDATION, "test": datasets.Split.TEST, } split_generators = [] for split in splits: split_generators.append( name=split_names.get(split, split), gen_kwargs={'split': split, 'data_dir': data_dir} ) return split_generators def _generate_examples(self, split_dir, archive_path): for folder_name in os.listdir(split_dir): folder_path = os.path.join(split_dir, folder_name) if os.path.isdir(folder_path): for file_name in os.listdir(folder_path): file_path = os.path.join(folder_path, file_name) if file_name.endswith('.trn'): with open(file_path, 'r') as f: transcription = f.read().strip() elif file_name.endswith('.wav'): with self._dl_manager.iter_archive(archive_path, filter_func=lambda x: x.path == file_path) as files: audio_file = next(files) audio_path = os.path.join(folder_name, audio_file.path.split('/')[-1]) audio, sr = librosa.load(audio_file, sr=16000) yield f'{folder_name}/{audio_file.path.split("/")[-1]}', { 'audio': { 'path': audio_path, 'bytes': audio }, 'transcription': transcription, }