czech_parliament_plenary_hearings / czech_parliament_plenary_hearings.py
jkot's picture
Update czech_parliament_plenary_hearings.py
0c4fd82
raw
history blame
No virus
3.43 kB
import os
import tarfile
import soundfile as sf
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 MyAudioDataset(datasets.GeneratorBasedBuilder):
VERSION = datasets.Version("1.0.0")
def _info(self):
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=datasets.Features(
{
"id": datasets.Value("string"),
"audio": datasets.features.Audio(),
"transcription": datasets.Value("string"),
"audio_sampling_rate": datasets.Value("int32"),
}
),
supervised_keys=None,
homepage=_HOMEPAGE,
citation=_CITATION,
license=_LICENSE
)
def _split_generators(self, dl_manager):
archive_path = dl_manager.download_and_extract(_DATASET_URL)
return [
datasets.SplitGenerator(
name=datasets.Split.TRAIN,
gen_kwargs={"directory": os.path.join(
archive_path, "ASR_DATA", "train")},
),
datasets.SplitGenerator(
name=datasets.Split.VALIDATION,
gen_kwargs={"directory": os.path.join(
archive_path, "ASR_DATA", "dev")},
),
datasets.SplitGenerator(
name=datasets.Split.TEST,
gen_kwargs={"directory": os.path.join(
archive_path, "ASR_DATA", "test")},
),
]
def _generate_examples(self, directory):
for root, _, files in os.walk(directory):
for filename in files:
if filename.endswith(".wav"):
audio_path = os.path.join(root, filename)
transcription_path = os.path.join(root, filename + ".trn")
# Load audio and transcription
audio, sampling_rate = sf.read(audio_path)
with open(transcription_path, "r", encoding="utf-8") as f:
transcription = f.read().strip()
yield f"{audio_path}-{transcription}", {
"audio": audio,
"transcription": transcription,
"audio_sampling_rate": sampling_rate,
}