|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
""" Load norwegian 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/no_2020/no-16khz_reorganized_english.pdf |
|
|
|
TODO: |
|
* add multi channel option |
|
* add train-validation-test split option |
|
* add sample option |
|
* add data preview |
|
|
|
Suggested filtering: |
|
* replace("<eeeh>", "") |
|
* replace("<mmm>", "") |
|
* replace("\\\\Punktum", "") |
|
* replace("\\\\Komma", "") |
|
""" |
|
|
|
import json |
|
import os |
|
|
|
from tqdm import tqdm |
|
import datasets |
|
|
|
|
|
_DESCRIPTION = """\ |
|
This database was created by Nordic Language Technology for the development of automatic speech recognition and dictation in Norwegian. |
|
In this 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-54/" |
|
|
|
_LICENSE = "CC0 1.0" |
|
|
|
|
|
|
|
|
|
_URLS = { |
|
"close_channel": [ |
|
"https://www.nb.no/sbfil/talegjenkjenning/16kHz_2020/no_2020/lydfiler_16_1_a.tar.gz", |
|
"https://www.nb.no/sbfil/talegjenkjenning/16kHz_2020/no_2020/lydfiler_16_1_b.tar.gz", |
|
"https://www.nb.no/sbfil/talegjenkjenning/16kHz_2020/no_2020/lydfiler_16_1_c.tar.gz", |
|
"https://www.nb.no/sbfil/talegjenkjenning/16kHz_2020/no_2020/lydfiler_16_1_d.tar.gz", |
|
], |
|
"distant_channel": [ |
|
"https://www.nb.no/sbfil/talegjenkjenning/16kHz_2020/no_2020/lydfiler_16_2_a.tar.gz", |
|
"https://www.nb.no/sbfil/talegjenkjenning/16kHz_2020/no_2020/lydfiler_16_2_b.tar.gz", |
|
"https://www.nb.no/sbfil/talegjenkjenning/16kHz_2020/no_2020/lydfiler_16_2_c.tar.gz", |
|
"https://www.nb.no/sbfil/talegjenkjenning/16kHz_2020/no_2020/lydfiler_16_2_d.tar.gz", |
|
] |
|
|
|
|
|
} |
|
|
|
_ANNOTATIONS_URL = [ |
|
"https://www.nb.no/sbfil/talegjenkjenning/16kHz_2020/no_2020/ADB_NOR_0463.tar.gz", |
|
"https://www.nb.no/sbfil/talegjenkjenning/16kHz_2020/no_2020/ADB_NOR_0464.tar.gz", |
|
"https://www.nb.no/sbfil/talegjenkjenning/16kHz_2020/no_2020/ADB_OD_Nor.NOR.tar.gz" |
|
] |
|
|
|
|
|
class NstNO(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 = { |
|
"region_of_birth": datasets.Value("string"), |
|
"region_of_youth": datasets.Value("string"), |
|
"remarks": datasets.Value("string"), |
|
"pid": datasets.Value("string"), |
|
"directory": datasets.Value("string"), |
|
"imported_sheet_file": datasets.Value("string"), |
|
"mumber_of_recordings": datasets.Value("string"), |
|
"rec_date": datasets.Value("string"), |
|
"rec_time": datasets.Value("string"), |
|
"record_duration": datasets.Value("string"), |
|
"record_session": datasets.Value("string"), |
|
"sheet_number": datasets.Value("string"), |
|
"ansi_codepage": datasets.Value("string"), |
|
"board": datasets.Value("string"), |
|
"byte_format": datasets.Value("string"), |
|
"channels": datasets.Value("string"), |
|
"character_set": datasets.Value("string"), |
|
"coding": datasets.Value("string"), |
|
"dos_codepage": datasets.Value("string"), |
|
"delimiter": datasets.Value("string"), |
|
"frequency": datasets.Value("string"), |
|
"memo": datasets.Value("string"), |
|
"script": datasets.Value("string"), |
|
"version": datasets.Value("string"), |
|
|
|
|
|
|
|
|
|
"audio": datasets.features.Audio(sampling_rate=48000), |
|
'client_id': datasets.Value("string"), |
|
'path': datasets.Value("string"), |
|
'sentence': datasets.Value("string"), |
|
'up_votes': datasets.Value("int64"), |
|
'down_votes': datasets.Value("int64"), |
|
'age': datasets.Value("string"), |
|
'sex': 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_dirs = dl_manager.download_and_extract(urls) |
|
annotations_dirs = dl_manager.download_and_extract(_ANNOTATIONS_URL) |
|
print(f"data dirs: {data_dirs}") |
|
print(f"annotation dirs: {annotations_dirs}") |
|
return [ |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TRAIN, |
|
|
|
gen_kwargs={ |
|
"data_dirs": data_dirs, |
|
"annotations_dirs": annotations_dirs |
|
}, |
|
), |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
] |
|
|
|
|
|
def _generate_examples(self, data_dirs, annotations_dirs): |
|
|
|
if self.config.name == "close_channel": |
|
channel_ext = "-1" |
|
else: |
|
channel_ext = "-2" |
|
|
|
for annotations_dir in annotations_dirs: |
|
annotations_files = os.listdir(annotations_dir) |
|
for annotation_filename in tqdm(annotations_files): |
|
|
|
annotations_filepath = os.path.join(annotations_dir, annotation_filename) |
|
with open(annotations_filepath, "r") as f: |
|
annotation = json.load(f) |
|
|
|
if "val_recordings" in annotation: |
|
val_recordings = annotation["val_recordings"] |
|
for recording in val_recordings: |
|
|
|
|
|
|
|
|
|
rel_filepath = f'no/{annotation["pid"]}/{annotation["pid"]}_{recording["file"]}'.replace(".wav", f"{channel_ext}.wav") |
|
for data_dir in data_dirs: |
|
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 = { |
|
"region_of_birth": annotation["info"]["Region_of_Birth"] or "", |
|
"region_of_youth": annotation["info"]["Region_of_Youth"] or "", |
|
"remarks": annotation["info"]["Remarks"] or "", |
|
"pid": annotation["pid"] or "", |
|
"directory": annotation["session"]["Directory"] or "", |
|
"imported_sheet_file": annotation["session"]["Imported_sheet_file"] or "", |
|
"mumber_of_recordings": annotation["session"]["Number_of_recordings"] or "", |
|
"rec_date": annotation["session"]["RecDate"] or "", |
|
"rec_time": annotation["session"]["RecTime"] or "", |
|
"record_duration": annotation["session"]["Record_duration"] or "", |
|
"record_session": annotation["session"]["Record_session"] or "", |
|
"sheet_number": annotation["session"]["Sheet_number"] or "", |
|
"ansi_codepage": annotation["system"]["ANSI_Codepage"] or "", |
|
"board": annotation["system"]["Board"] or "", |
|
"byte_format": annotation["system"]["ByteFormat"] or "", |
|
"channels": annotation["system"]["Channels"] or "", |
|
"character_set": annotation["system"]["CharacterSet"] or "", |
|
"coding": annotation["system"]["Coding"] or "", |
|
"dos_codepage": annotation["system"]["DOS_Codepage"] or "", |
|
"delimiter": annotation["system"]["Delimiter"] or "", |
|
"frequency": annotation["system"]["Frequency"] or "", |
|
"memo": annotation["system"]["Memo"] or "", |
|
"script": annotation["system"]["Script"] or "", |
|
"version": annotation["system"]["Version"] or "", |
|
"audio": {"path": rel_filepath, "bytes": audio_bytes}, |
|
'client_id': annotation["info"]["Speaker_ID"] or "", |
|
'path': rel_filepath, |
|
'sentence': recording["text"], |
|
'up_votes': 1, |
|
'down_votes': 0, |
|
'age': annotation["info"]["Age"] or "", |
|
'sex': annotation["info"]["Sex"] or "", |
|
'accent': "", |
|
'locale': "sv", |
|
'segment': "", |
|
'channel': self.config.name or "" |
|
} |
|
yield rel_filepath, result |
|
|