|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
""" Load swedish NST dataset provided by National Library of Norway | Språkbanken. |
|
|
|
Documentation with full description of the data: https://www.nb.no/sbfil/talegjenkjenning/16kHz_2020/se_2020/se-16khz_reorganized.pdf |
|
|
|
TODO: |
|
* add multi channel option |
|
* add train-validation-test split option |
|
""" |
|
|
|
import csv |
|
import json |
|
import os |
|
|
|
import datasets |
|
|
|
|
|
_DESCRIPTION = """\ |
|
This database was created by Nordic Language Technology for the development |
|
of automatic speech recognition and dictation in Swedish. |
|
In this updated version, the organization of the data have been altered to improve the usefulness of the database. |
|
In the original version of the material, |
|
the files were organized in a specific folder structure where the folder names were meaningful. |
|
However, the file names were not meaningful, and there were also cases of files with identical names in different folders. |
|
This proved to be impractical, since users had to keep the original folder structure in order to use the data. |
|
The files have been renamed, such that the file names are unique and meaningful regardless of the folder structure. |
|
The original metadata files were in spl format. These have been converted to JSON format. |
|
The converted metadata files are also anonymized and the text encoding has been converted from ANSI to UTF-8. |
|
See the documentation file for a full description of the data and the changes made to the database.""" |
|
|
|
_HOMEPAGE = "https://www.nb.no/sprakbanken/en/resource-catalogue/oai-nb-no-sbr-56/" |
|
|
|
_LICENSE = "CC0 1.0" |
|
|
|
|
|
|
|
|
|
_URLS = { |
|
"close_channel": "https://www.nb.no/sbfil/talegjenkjenning/16kHz_2020/se_2020/lydfiler_16_1.tar.gz", |
|
"distant_channel": "https://www.nb.no/sbfil/talegjenkjenning/16kHz_2020/se_2020/lydfiler_16_2.tar.gz", |
|
|
|
|
|
} |
|
|
|
_ANNOTATIONS_URL = "https://www.nb.no/sbfil/talegjenkjenning/16kHz_2020/se_2020/ADB_SWE_0467.tar.gz" |
|
|
|
|
|
class NstSV(datasets.GeneratorBasedBuilder): |
|
"""Audio dataset for Swedish ASR provided by National Library of Norawy. |
|
|
|
Originally, recordings have been made on two channels: a close one and a distant one. |
|
Channels have been separated and can be loaded independently. |
|
|
|
TODO: enable and validate multi_channel |
|
Two configurations available: |
|
- close_channel |
|
- distant_channel |
|
|
|
Main data and metadata available: |
|
- audio file (bytes) |
|
- manually annotated transcription (str) |
|
- age (str) |
|
- gender (str) |
|
- region of birth (str) |
|
- region of youth (str) |
|
- recording session info (object) |
|
- recording system (object) |
|
- "type" of recording (see detailed documentatin) |
|
- common_voice-like structured information |
|
(info mentioned above with object structure like common voice dataset for ease of merging) |
|
|
|
""" |
|
|
|
VERSION = datasets.Version("1.1.0") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BUILDER_CONFIGS = [ |
|
datasets.BuilderConfig(name="close_channel", version=VERSION, description="Close channel recordings"), |
|
datasets.BuilderConfig(name="distant_channel", version=VERSION, description="Distant channel recordings"), |
|
] |
|
|
|
DEFAULT_CONFIG_NAME = "close_channel" |
|
|
|
def _info(self): |
|
features_dict = { |
|
"info": dict, |
|
"metadata": dict, |
|
"pid": datasets.Value("string"), |
|
"session": dict, |
|
"system": dict, |
|
"val_recordings": list, |
|
"audio": datasets.features.Audio(sampling_rate=16000), |
|
'client_id': datasets.Value("string"), |
|
'path': datasets.Value("string"), |
|
'sentence': datasets.Value("string"), |
|
'up_votes': datasets.Value("int32"), |
|
'down_votes': datasets.Value("int32"), |
|
'age': datasets.Value("string"), |
|
'gender': datasets.Value("string"), |
|
'accent': datasets.Value("string"), |
|
'locale': datasets.Value("string"), |
|
'segment': datasets.Value("string"), |
|
'channel': datasets.Value("string") |
|
} |
|
return datasets.DatasetInfo( |
|
|
|
description=_DESCRIPTION, |
|
|
|
features=datasets.Features(features_dict), |
|
|
|
|
|
|
|
|
|
|
|
homepage=_HOMEPAGE, |
|
|
|
license=_LICENSE, |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
|
|
|
|
|
|
|
|
|
|
|
|
urls = _URLS[self.config.name] |
|
data_dir = dl_manager.download_and_extract(urls) |
|
annotations_dir = dl_manager.download_and_extract(_ANNOTATIONS_URL) |
|
|
|
return [ |
|
datasets.SplitGenerator( |
|
name="all", |
|
|
|
gen_kwargs={ |
|
"data_dir": data_dir, |
|
"annotations_dir": annotations_dir |
|
}, |
|
), |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
] |
|
|
|
|
|
def _generate_examples(self, data_dir, annotations_dir): |
|
|
|
|
|
|
|
if self.config.name == "close_channel": |
|
channel_ext = "-1" |
|
else: |
|
channel_ext = "-2" |
|
|
|
for annotation_filename in os.listdir(annotations_dir): |
|
|
|
annotations_filepath = os.path.join(annotations_dir, annotation_filename) |
|
with open(annotations_filepath, "r") as f: |
|
annotation = json.load(f) |
|
|
|
for recording in annotation["val_recordings"]: |
|
|
|
|
|
|
|
|
|
rel_filepath = f'se/{annotation["pid"]}/{annotation["pid"]}_{recording["file"]}'.replace(".wav", f"{channel_ext}.wav") |
|
audio_filepath = f"{data_dir}/{rel_filepath}" |
|
if os.path.exists(audio_filepath): |
|
with open(audio_filepath, "rb") as f: |
|
audio_bytes = f.read() |
|
result = { |
|
"info": annotation["info"], |
|
"metadata": annotation["metadata"], |
|
"pid": annotation["pid"], |
|
"session": annotation["session"], |
|
"system": annotation["system"], |
|
"val_recordings": annotation["val_recordings"], |
|
"client_id": annotation["info"]["Speaker_ID"], |
|
'path': rel_filepath, |
|
'audio': {"path": rel_filepath, "bytes": audio_bytes}, |
|
'sentence': recording["text"], |
|
'up_votes': 0, |
|
'down_votes': 0, |
|
'age': annotation["info"]["Age"], |
|
'gender': annotation["info"]["Sex"], |
|
'accent': "", |
|
'locale': "sv", |
|
'segment': "" |
|
} |
|
|
|
yield rel_filepath, result |
|
|
|
|
|
|
|
|