jkot commited on
Commit
b21ba76
1 Parent(s): 6c22c0b

Upload czech_parliament_plenary_hearings.py

Browse files
czech_parliament_plenary_hearings.py ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from datasets import Dataset, GeneratorBasedBuilder, Features
2
+ import os
3
+ import tarfile
4
+ import librosa
5
+ import datasets
6
+ _LICENSE = "https://creativecommons.org/licenses/by/4.0/"
7
+ _HOMEPAGE = "https://lindat.mff.cuni.cz/repository/xmlui/handle/11234/1-3126"
8
+ _DATASET_URL = "https://lindat.mff.cuni.cz/repository/xmlui/bitstream/handle/11234/1-3126{/snemovna.tar.xz}"
9
+
10
+ _DESCRIPTION = "Large corpus of Czech parliament plenary sessions, originaly released 2019-11-29 by Kratochvíl Jonáš, Polák Peter and Bojar Ondřej\
11
+ The dataset consists of 444 hours of transcribed speech audio snippets 1 to 40 seconds long.\
12
+ Original dataset transcriptions were converted to true case from uppercase using spacy library."
13
+
14
+ _CITATION = """\
15
+ @misc{11234/1-3126,
16
+ title = {Large Corpus of Czech Parliament Plenary Hearings},
17
+ author = {Kratochv{\'{\i}}l, Jon{\'a}{\v s} and Pol{\'a}k, Peter and Bojar, Ond{\v r}ej},
18
+ url = {http://hdl.handle.net/11234/1-3126},
19
+ note = {{LINDAT}/{CLARIAH}-{CZ} digital library at the Institute of Formal and Applied Linguistics ({{\'U}FAL}), Faculty of Mathematics and Physics, Charles University},
20
+ copyright = {Creative Commons - Attribution 4.0 International ({CC} {BY} 4.0)},
21
+ year = {2019} } """
22
+
23
+
24
+ class CzechParliamentPlenaryHearings(GeneratorBasedBuilder):
25
+ def __init__(self, **kwargs):
26
+ super().__init__(**kwargs)
27
+
28
+ def _info(self):
29
+ return datasets.DatasetInfo(
30
+ description=_DESCRIPTION,
31
+ features=datasets.Features(
32
+ {
33
+ "id": datasets.Value("string"),
34
+ "audio": datasets.features.Audio(sampling_rate=16000),
35
+ "transcription": datasets.Value("string")
36
+ }
37
+ ),
38
+ supervised_keys=None,
39
+ homepage=_HOMEPAGE,
40
+ citation=_CITATION,
41
+ license=_LICENSE
42
+ )
43
+
44
+ def _split_generators(self, dl_manager):
45
+ data_dir = dl_manager.download_and_extract(_DATASET_URL)
46
+ data_dir = os.path.join(data_dir, 'ASR_DATA')
47
+ return [
48
+ self.SplitGenerator(name='train', gen_kwargs={'split': 'train', 'data_dir': data_dir}),
49
+ self.SplitGenerator(name='validation', gen_kwargs={'split': 'dev', 'data_dir': data_dir}),
50
+ self.SplitGenerator(name='test', gen_kwargs={'split': 'test', 'data_dir': data_dir})
51
+ ]
52
+
53
+ def _generate_examples(self, split, data_dir):
54
+ split_dir = os.path.join(data_dir, split)
55
+ for folder_name in os.listdir(split_dir):
56
+ folder_path = os.path.join(split_dir, folder_name)
57
+ if os.path.isdir(folder_path):
58
+ for audio_file in os.listdir(folder_path):
59
+ if audio_file.endswith('.wav'):
60
+ audio_path = os.path.join(folder_path, audio_file)
61
+ transcription_path = os.path.join(folder_path, audio_file + '.trn')
62
+ transcription = open(transcription_path).read().strip()
63
+
64
+ audio, sr = librosa.load(audio_path, sr=16000)
65
+
66
+ yield f"{folder_name}/{audio_file}", {
67
+ 'audio': audio,
68
+ 'transcription': transcription,
69
+ }