Update czech_parliament_plenary_hearings.py
Browse files
czech_parliament_plenary_hearings.py
CHANGED
@@ -1,10 +1,8 @@
|
|
|
|
1 |
import os
|
2 |
import tarfile
|
3 |
-
|
4 |
-
import soundfile as sf
|
5 |
-
|
6 |
import datasets
|
7 |
-
|
8 |
_LICENSE = "https://creativecommons.org/licenses/by/4.0/"
|
9 |
_HOMEPAGE = "https://lindat.mff.cuni.cz/repository/xmlui/handle/11234/1-3126"
|
10 |
_DATASET_URL = "https://lindat.mff.cuni.cz/repository/xmlui/bitstream/handle/11234/1-3126/snemovna.tar.xz"
|
@@ -23,8 +21,9 @@ _CITATION = """\
|
|
23 |
year = {2019} } """
|
24 |
|
25 |
|
26 |
-
class
|
27 |
-
|
|
|
28 |
|
29 |
def _info(self):
|
30 |
return datasets.DatasetInfo(
|
@@ -32,9 +31,8 @@ class MyAudioDataset(datasets.GeneratorBasedBuilder):
|
|
32 |
features=datasets.Features(
|
33 |
{
|
34 |
"id": datasets.Value("string"),
|
35 |
-
"audio": datasets.features.Audio(),
|
36 |
-
"transcription": datasets.Value("string")
|
37 |
-
"audio_sampling_rate": datasets.Value("int32"),
|
38 |
}
|
39 |
),
|
40 |
supervised_keys=None,
|
@@ -44,40 +42,37 @@ class MyAudioDataset(datasets.GeneratorBasedBuilder):
|
|
44 |
)
|
45 |
|
46 |
def _split_generators(self, dl_manager):
|
47 |
-
|
|
|
|
|
48 |
|
49 |
-
|
50 |
-
datasets.
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
)
|
60 |
-
|
61 |
-
name=datasets.Split.TEST,
|
62 |
-
gen_kwargs={"directory": os.path.join(
|
63 |
-
archive_path, "ASR_DATA", "test")},
|
64 |
-
),
|
65 |
-
]
|
66 |
|
67 |
-
def _generate_examples(self,
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
|
|
|
|
|
|
|
|
73 |
|
74 |
-
|
75 |
-
audio, sampling_rate = sf.read(audio_path)
|
76 |
-
with open(transcription_path, "r", encoding="utf-8") as f:
|
77 |
-
transcription = f.read().strip()
|
78 |
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
}
|
|
|
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"
|
|
|
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(
|
|
|
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,
|
|
|
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 |
+
splits = ("train", "dev", "test")
|
48 |
|
49 |
+
split_names = {
|
50 |
+
"train": datasets.Split.TRAIN,
|
51 |
+
"dev": datasets.Split.VALIDATION,
|
52 |
+
"test": datasets.Split.TEST,
|
53 |
+
}
|
54 |
+
split_generators = []
|
55 |
+
for split in splits:
|
56 |
+
split_generators.append(
|
57 |
+
name=split_names.get(split, split),
|
58 |
+
gen_kwargs={'split': split, 'data_dir': data_dir}
|
59 |
+
)
|
60 |
+
return split_generators
|
|
|
|
|
|
|
|
|
|
|
61 |
|
62 |
+
def _generate_examples(self, split, data_dir):
|
63 |
+
split_dir = os.path.join(data_dir, split)
|
64 |
+
for folder_name in os.listdir(split_dir):
|
65 |
+
folder_path = os.path.join(split_dir, folder_name)
|
66 |
+
if os.path.isdir(folder_path):
|
67 |
+
for audio_file in os.listdir(folder_path):
|
68 |
+
if audio_file.endswith('.wav'):
|
69 |
+
audio_path = os.path.join(folder_path, audio_file)
|
70 |
+
transcription_path = os.path.join(folder_path, audio_file + '.trn')
|
71 |
+
transcription = open(transcription_path).read().strip()
|
72 |
|
73 |
+
audio, sr = librosa.load(audio_path, sr=16000)
|
|
|
|
|
|
|
74 |
|
75 |
+
yield f"{folder_name}/{audio_file}", {
|
76 |
+
'audio': audio,
|
77 |
+
'transcription': transcription,
|
78 |
+
}
|
|