File size: 3,425 Bytes
b21ba76 0c4fd82 b21ba76 0c4fd82 b21ba76 1f22e36 b21ba76 0c4fd82 b21ba76 0c4fd82 b21ba76 9ec223c b21ba76 0c4fd82 799ce12 0c4fd82 b21ba76 0c4fd82 b21ba76 0c4fd82 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
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,
}
|