Add dataset loader attempt
Browse files- vystadial2016_asr.py +138 -0
vystadial2016_asr.py
ADDED
@@ -0,0 +1,138 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# coding=utf-8
|
2 |
+
# Copyright 2022 Vojtěch Drábek
|
3 |
+
|
4 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5 |
+
# you may not use this file except in compliance with the License.
|
6 |
+
# You may obtain a copy of the License at
|
7 |
+
#
|
8 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9 |
+
#
|
10 |
+
# Unless required by applicable law or agreed to in writing, software
|
11 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13 |
+
# See the License for the specific language governing permissions and
|
14 |
+
# limitations under the License.
|
15 |
+
|
16 |
+
# Lint as: python3
|
17 |
+
"""Vystadial 2016 Czech automatic speech recognition dataset."""
|
18 |
+
|
19 |
+
|
20 |
+
import os
|
21 |
+
|
22 |
+
import datasets
|
23 |
+
from datasets.tasks import AutomaticSpeechRecognition
|
24 |
+
|
25 |
+
|
26 |
+
_CITATION = """\
|
27 |
+
@misc{11234/1-1740,
|
28 |
+
title = {Vystadial 2016 – Czech data},
|
29 |
+
author = {Pl{\'a}tek, Ond{\v r}ej and Du{\v s}ek, Ond{\v r}ej and Jur{\v c}{\'{\i}}{\v c}ek, Filip},
|
30 |
+
url = {http://hdl.handle.net/11234/1-1740},
|
31 |
+
note = {{LINDAT}/{CLARIAH}-{CZ} digital library at the Institute of Formal and Applied Linguistics ({{\'U}FAL}), Faculty of Mathematics and Physics, Charles University},
|
32 |
+
copyright = {Creative Commons - Attribution-{ShareAlike} 4.0 International ({CC} {BY}-{SA} 4.0)},
|
33 |
+
year = {2016} }
|
34 |
+
"""
|
35 |
+
|
36 |
+
_DESCRIPTION = """\
|
37 |
+
This is the Czech data collected during the `VYSTADIAL` project. It is an extension of the 'Vystadial 2013' Czech part data release. The dataset comprises of telephone conversations in Czech, developed for training acoustic models for automatic speech recognition in spoken dialogue systems.
|
38 |
+
"""
|
39 |
+
|
40 |
+
_URL = "https://lindat.mff.cuni.cz/repository/xmlui/handle/11234/1-1740"
|
41 |
+
_DL_URL = "https://lindat.mff.cuni.cz/repository/xmlui/bitstream/handle/11234/1-1740/data_voip_cs_2016.tar.gz?sequence=1&isAllowed=y"
|
42 |
+
|
43 |
+
|
44 |
+
class Vystadial2016ASRConfig(datasets.BuilderConfig):
|
45 |
+
"""BuilderConfig for Vysadial 2016."""
|
46 |
+
|
47 |
+
def __init__(self, **kwargs):
|
48 |
+
"""
|
49 |
+
Args:
|
50 |
+
data_dir: `string`, the path to the folder containing the files in the
|
51 |
+
downloaded .tar
|
52 |
+
citation: `string`, citation for the data set
|
53 |
+
url: `string`, url for information about the data set
|
54 |
+
**kwargs: keyword arguments forwarded to super.
|
55 |
+
"""
|
56 |
+
super(Vystadial2016ASRConfig, self).__init__(version=datasets.Version("1.0.0", ""), **kwargs)
|
57 |
+
|
58 |
+
|
59 |
+
class Vystadial2016ASR(datasets.GeneratorBasedBuilder):
|
60 |
+
"""Vystadial 2016 dataset."""
|
61 |
+
|
62 |
+
DEFAULT_WRITER_BATCH_SIZE = 256
|
63 |
+
DEFAULT_CONFIG_NAME = "all"
|
64 |
+
BUILDER_CONFIGS = [
|
65 |
+
Vystadial2016ASRConfig(name="all", description="All samples."),
|
66 |
+
]
|
67 |
+
|
68 |
+
def _info(self):
|
69 |
+
return datasets.DatasetInfo(
|
70 |
+
description=_DESCRIPTION,
|
71 |
+
features=datasets.Features(
|
72 |
+
{
|
73 |
+
"file": datasets.Value("string"),
|
74 |
+
"audio": datasets.Audio(sampling_rate=16_000),
|
75 |
+
"text": datasets.Value("string"),
|
76 |
+
}
|
77 |
+
),
|
78 |
+
supervised_keys=("file", "text"),
|
79 |
+
homepage=_URL,
|
80 |
+
citation=_CITATION,
|
81 |
+
task_templates=[AutomaticSpeechRecognition(audio_column="audio", transcription_column="text")],
|
82 |
+
)
|
83 |
+
|
84 |
+
def _split_generators(self, dl_manager):
|
85 |
+
archive_path = dl_manager.download(_DL_URL)
|
86 |
+
# (Optional) In non-streaming mode, we can extract the archive locally to have actual local audio files:
|
87 |
+
local_extracted_archive = dl_manager.extract(archive_path) if not dl_manager.is_streaming else {}
|
88 |
+
|
89 |
+
return [ datasets.SplitGenerator(
|
90 |
+
name="test",
|
91 |
+
gen_kwargs={
|
92 |
+
"local_extracted_archive": local_extracted_archive.get("?"),
|
93 |
+
"files": dl_manager.iter_archive(archive_path["train.clean.100"]),
|
94 |
+
},
|
95 |
+
),
|
96 |
+
datasets.SplitGenerator(
|
97 |
+
name="train",
|
98 |
+
gen_kwargs={
|
99 |
+
"local_extracted_archive": local_extracted_archive.get("train.clean.360"),
|
100 |
+
"files": dl_manager.iter_archive(archive_path["train.clean.360"]),
|
101 |
+
},
|
102 |
+
), ]
|
103 |
+
|
104 |
+
def _generate_examples(self, files, local_extracted_archive):
|
105 |
+
"""Generate examples from a Vystadial2016 archive_path."""
|
106 |
+
key = 0
|
107 |
+
audio_data = {}
|
108 |
+
transcripts = []
|
109 |
+
for path, f in files:
|
110 |
+
id_ = path.split("/")[-1][:-4]
|
111 |
+
if path.endswith(".wav"):
|
112 |
+
audio_data[id_] = f.read()
|
113 |
+
elif path.endswith(".trs"):
|
114 |
+
for line in f:
|
115 |
+
if line:
|
116 |
+
line = line.decode("utf-8").strip()
|
117 |
+
id_, transcript = line.split(" ", 1)
|
118 |
+
audio_file = f"{id_}.wav"
|
119 |
+
audio_file = (
|
120 |
+
os.path.join(local_extracted_archive, audio_file)
|
121 |
+
if local_extracted_archive
|
122 |
+
else audio_file
|
123 |
+
)
|
124 |
+
transcripts.append(
|
125 |
+
{
|
126 |
+
"id": id_,
|
127 |
+
"file": audio_file,
|
128 |
+
"text": transcript,
|
129 |
+
}
|
130 |
+
)
|
131 |
+
if audio_data and len(audio_data) == len(transcripts):
|
132 |
+
for transcript in transcripts:
|
133 |
+
audio = {"path": transcript["file"], "bytes": audio_data[transcript["id"]]}
|
134 |
+
yield key, {"audio": audio, **transcript}
|
135 |
+
key += 1
|
136 |
+
audio_data = {}
|
137 |
+
transcripts = []
|
138 |
+
|