File size: 5,896 Bytes
212b70c 1ede384 212b70c 1ede384 212b70c b42cad6 1ede384 212b70c 99f3be3 4924311 5f51769 45f21af 3b3a3f3 212b70c 3b3a3f3 212b70c 3b3a3f3 212b70c 3b3a3f3 212b70c 3b3a3f3 212b70c 3b3a3f3 99f3be3 3b3a3f3 1ede384 212b70c 1ede384 5f51769 1ede384 5f51769 1ede384 3b3a3f3 dc94f26 212b70c |
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 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
""" Babelbox Voice Dataset"""
import os
import csv
import codecs
import datasets
from typing import List
from pathlib import Path
from tqdm import tqdm
logger = datasets.logging.get_logger(__name__)
_CITATION = """\
@inproceedings{babelboxvoice:2022,
author = {Andersson, O. and Bjelkenhed, M. and Bielsa, M. et al},
title = {Babelbox Voice: A Speech Corpus for training Whisper},
year = 2022
}
"""
_DL_BASE_URL = "https://huggingface.co/datasets/babelbox/babelbox_voice/resolve/main/archive/nst"
_DL_URL_FORMAT = _DL_BASE_URL + "/nst-data-{:0>3d}.tar.gz"
_METADATA_URL = "https://huggingface.co/datasets/babelbox/babelbox_voice/resolve/main/archive/nst/metadata.tar.gz"
_HF_REPO_PATH = "https://huggingface.co/datasets/babelbox/babelbox_voice/"
class BabelboxVoiceConfig(datasets.BuilderConfig):
"""BuilderConfig for BabelboxVoice."""
def __init__(self, name, version, **kwargs):
self.name = name
self.version = version
self.features = kwargs.pop("features", None)
self.description = kwargs.pop("description", None)
self.data_url = kwargs.pop("data_url", None)
self.nb_data_shards = kwargs.pop("nb_data_shards", None)
self.metadata_url = kwargs.pop("metadata_url", None)
description = (
f"Babelbox Voice speech to text dataset."
)
super(BabelboxVoiceConfig, self).__init__(
name=name,
version=version,
**kwargs,
)
class BabelboxVoice(datasets.GeneratorBasedBuilder):
VERSION = datasets.Version("1.0.0")
BUILDER_CONFIGS = [
BabelboxVoiceConfig(
name="nst",
version=VERSION,
description="This part of Babel Voice includes data from National Library of Norway",
features=["path", "audio", "sentence"],
data_url= _HF_REPO_PATH + "resolve/main/archive/nst/nst-data-{:0>3d}.tar.gz",
nb_data_shards = 30,
metadata_url= _HF_REPO_PATH + "resolve/main/archive/nst/metadata.tar.gz"
),
BabelboxVoiceConfig(
name="audiosubs",
version=VERSION,
description="This part of Babel Voice includes data from audio with subtitles",
features=["path", "audio", "sentence"],
data_url= _HF_REPO_PATH + "resolve/main/archive/audiosubs/audiosubs-data-{:0>3d}.tar.gz",
nb_data_shards = 2,
metadata_url= None
)
]
DEFAULT_CONFIG_NAME = "nst"
def _info(self):
description = (
"Babelbox Voice is an initiative to help teach machines how real people speak. "
)
if self.config.name == "nst":
features = datasets.Features(
{
"path": datasets.Value("string"),
"audio": datasets.features.Audio(sampling_rate=16_000),
"sentence": datasets.Value("string")
}
)
else:
features = datasets.Features(
{
"path": datasets.Value("string"),
"audio": datasets.features.Audio(sampling_rate=16_000),
"sentence": datasets.Value("string")
}
)
return datasets.DatasetInfo(
description=description,
features=features,
supervised_keys=None,
version=self.config.version
)
def get_metadata(self, dl_manager, metadata_url):
if metadata_url == None: return None
metadata_path = dl_manager.download(metadata_url)
local_extracted_metadata_path = dl_manager.extract(metadata_path) if not dl_manager.is_streaming else None
metadata_archive = dl_manager.iter_archive(metadata_path)
metadata = {}
for path, file in metadata_archive:
reader = csv.DictReader(codecs.iterdecode(file, 'utf-8'))
for row in tqdm(reader, desc="Reading metadata..."):
filename = row['filename_channel_1']
sentence = row['text']
metadata[filename] = sentence
return metadata
def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
download_urls = [self.config.data_url.format(i) for i in range(1, self.config.nb_data_shards + 1) ]
archive_paths = dl_manager.download(download_urls)
local_extracted_archive_paths = dl_manager.extract(archive_paths) if not dl_manager.is_streaming else {}
metadata = self.get_metadata(dl_manager, self.config.metadata_url)
return [
datasets.SplitGenerator(name=datasets.Split.TRAIN,
gen_kwargs={
"local_extracted_archive_paths": local_extracted_archive_paths,
"archives": [dl_manager.iter_archive(path) for path in archive_paths],
"metadata": metadata
})
]
def _generate_examples(self, local_extracted_archive_paths, archives, metadata):
sampling_rate = 16000
for i, audio_archive in enumerate(archives):
for path, file in audio_archive:
if local_extracted_archive_paths == False:
path = os.path.join(local_extracted_archive_paths[i], path)
result = dict()
result["path"] = path
result["audio"] = {"path": path, "bytes": file.read()}
result["sentence"] = metadata[path]
yield path, result
|