File size: 4,481 Bytes
d759cba 418f6d9 d759cba |
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 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# coding=utf-8
# Copyright 2021 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors.
# Copyright 2021 Jim O'Regan
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Lint as: python3
"""ClarinPL Sejm/Senat automatic speech recognition dataset."""
import os
import datasets
_CITATION = """\
@article{marasek2014system,
title={System for automatic transcription of sessions of the {P}olish {S}enate},
author={Marasek, Krzysztof and Kor{\v{z}}inek, Danijel and Brocki, {\L}ukasz},
journal={Archives of Acoustics},
volume={39},
number={4},
pages={501--509},
year={2014}
}
"""
_DESCRIPTION = """\
A collection of 97 hours of parliamentary speeches published on the ClarinPL website
Note that in order to limit the required storage for preparing this dataset, the audio
is stored in the .wav format and is not converted to a float32 array. To convert the audio
file to a float32 array, please make use of the `.map()` function as follows:
```python
import soundfile as sf
def map_to_array(batch):
speech_array, _ = sf.read(batch["file"])
batch["speech"] = speech_array
return batch
dataset = dataset.map(map_to_array, remove_columns=["file"])
```
"""
_URL = "https://mowa.clarin-pl.eu/"
_DS_URL = "http://mowa.clarin-pl.eu/korpusy/parlament/parlament.tar.gz"
class ClarinPLSejmSenatASRConfig(datasets.BuilderConfig):
"""BuilderConfig for ClarinPLSejmSenatASR."""
def __init__(self, **kwargs):
"""
Args:
data_dir: `string`, the path to the folder containing the files in the
downloaded .tar
citation: `string`, citation for the data set
url: `string`, url for information about the data set
**kwargs: keyword arguments forwarded to super.
"""
super(ClarinPLSejmSenatASRConfig, self).__init__(version=datasets.Version("2.1.0", ""), **kwargs)
class ClarinPLSejmSenat(datasets.GeneratorBasedBuilder):
"""ClarinPL Sejm/Senat dataset."""
BUILDER_CONFIGS = [
ClarinPLSejmSenatASRConfig(name="clean", description="'Clean' speech."),
]
def _info(self):
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=datasets.Features(
{
"file": datasets.Value("string"),
"text": datasets.Value("string"),
"speaker_id": datasets.Value("string"),
"id": datasets.Value("string"),
}
),
supervised_keys=("file", "text"),
homepage=_URL,
citation=_CITATION,
)
def _split_generators(self, dl_manager):
archive_path = dl_manager.download_and_extract(_DS_URL)
archive_path = os.path.join(archive_path, "SejmSenat")
audio_path = os.path.join(archive_path, "audio")
return [
datasets.SplitGenerator(name="train", gen_kwargs={
"archive_path": os.path.join(archive_path, "train"),
"audio_path": audio_path
}),
datasets.SplitGenerator(name="test", gen_kwargs={
"archive_path": os.path.join(archive_path, "test"),
"audio_path": audio_path
}),
]
def _generate_examples(self, archive_path, audio_path):
"""Generate examples from a ClarinPL Sejm/Senat archive_path."""
with open(os.path.join(archive_path, "text"), "r", encoding="utf-8") as f:
for line in f:
line = line.strip()
key, transcript = line.split(" ", 1)
parts = key.split('-')
dir = '-'.join(parts[0:2])
audio_file = f'{parts[2]}.wav'
example = {
"id": key,
"speaker_id": parts[0],
"file": os.path.join(audio_path, dir, audio_file),
"text": transcript,
}
yield key, example
|