|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"""silero_open_stt Dataset""" |
|
|
|
|
|
import csv |
|
|
import os |
|
|
import json |
|
|
|
|
|
import datasets |
|
|
from tqdm import tqdm |
|
|
|
|
|
|
|
|
_DESCRIPTION = """open_stt is a Russian dataset for speech research.""" |
|
|
|
|
|
_CITATION = """None""" |
|
|
|
|
|
_HOMEPAGE = "https://github.com/snakers4/open_stt" |
|
|
_LICENSE = "cc-by-nc-4.0" |
|
|
|
|
|
_BASE_URL = "https://huggingface.co/datasets/Sh1man/silero_open_stt_opus/resolve/main/" |
|
|
_AUDIO_URL = _BASE_URL + "data/{subset}/{split}/{subset}_{split}_{shard_idx}.tar" |
|
|
_METADATA_URL = _BASE_URL + "metadata/{subset}/{split}.tsv" |
|
|
_N_SHARDS_URL = _BASE_URL + "n_shards.json" |
|
|
|
|
|
|
|
|
SUBSETS = { |
|
|
"tts_russian_addresses_rhvoice_4voices": { |
|
|
"description": "Поднабор tts_russian_addresses_rhvoice_4voices датасета silero_open_stt", |
|
|
}, |
|
|
} |
|
|
|
|
|
|
|
|
class silero_open_sttConfig(datasets.BuilderConfig): |
|
|
"""BuilderConfig для silero_open_stt.""" |
|
|
|
|
|
def __init__(self, name, subset, description, **kwargs): |
|
|
"""BuilderConfig для silero_open_stt. |
|
|
|
|
|
Args: |
|
|
name: Название набора данных |
|
|
subset: Поднабор данных |
|
|
description: Описание поднабора |
|
|
**kwargs: Дополнительные аргументы для суперкласса |
|
|
""" |
|
|
self.subset = subset |
|
|
super(silero_open_sttConfig, self).__init__( |
|
|
name=name, |
|
|
version=datasets.Version("1.0.0"), |
|
|
description=description, |
|
|
**kwargs, |
|
|
) |
|
|
|
|
|
|
|
|
class silero_open_stt(datasets.GeneratorBasedBuilder): |
|
|
"""Аудио-датасет silero_open_stt.""" |
|
|
|
|
|
VERSION = datasets.Version("1.0.0") |
|
|
DEFAULT_WRITER_BATCH_SIZE = 1000 |
|
|
|
|
|
BUILDER_CONFIGS = [ |
|
|
silero_open_sttConfig( |
|
|
name=subset, |
|
|
subset=subset, |
|
|
description=f"silero_open_stt - {info['description']}", |
|
|
) |
|
|
for subset, info in SUBSETS.items() |
|
|
] |
|
|
|
|
|
def _info(self): |
|
|
features = datasets.Features( |
|
|
{ |
|
|
"id": datasets.Value("string"), |
|
|
"path": datasets.Value("string"), |
|
|
"text": datasets.Value("string"), |
|
|
"duration": datasets.Value("float32"), |
|
|
"audio": datasets.Audio(sampling_rate=16000), |
|
|
} |
|
|
) |
|
|
|
|
|
return datasets.DatasetInfo( |
|
|
description=_DESCRIPTION, |
|
|
features=features, |
|
|
supervised_keys=None, |
|
|
homepage=_HOMEPAGE, |
|
|
license=_LICENSE, |
|
|
citation=_CITATION |
|
|
) |
|
|
|
|
|
def _split_generators(self, dl_manager): |
|
|
"""Returns SplitGenerators.""" |
|
|
subset = self.config.subset |
|
|
|
|
|
|
|
|
n_shards_path = dl_manager.download_and_extract(_N_SHARDS_URL) |
|
|
with open(n_shards_path, encoding="utf-8") as f: |
|
|
n_shards = json.load(f) |
|
|
|
|
|
|
|
|
if subset not in n_shards: |
|
|
raise ValueError(f"Subset {subset} not found in n_shards.json") |
|
|
|
|
|
|
|
|
splits = list(n_shards[subset].keys()) |
|
|
if not splits: |
|
|
raise ValueError(f"No splits found for subset {subset}") |
|
|
|
|
|
|
|
|
audio_urls = {} |
|
|
for split in splits: |
|
|
if n_shards[subset][split] > 0: |
|
|
audio_urls[split] = [ |
|
|
_AUDIO_URL.format(subset=subset, split=split, shard_idx=i) |
|
|
for i in range(n_shards[subset][split]) |
|
|
] |
|
|
|
|
|
|
|
|
archive_paths = dl_manager.download(audio_urls) |
|
|
local_extracted_archive_paths = dl_manager.extract(archive_paths) if not dl_manager.is_streaming else {} |
|
|
|
|
|
|
|
|
meta_urls = {split: _METADATA_URL.format(subset=subset, split=split) for split in splits} |
|
|
meta_paths = dl_manager.download_and_extract(meta_urls) |
|
|
|
|
|
|
|
|
split_generators = [] |
|
|
split_names = { |
|
|
"train": datasets.Split.TRAIN, |
|
|
"validate": datasets.Split.VALIDATION, |
|
|
"test": datasets.Split.TEST, |
|
|
} |
|
|
|
|
|
for split in splits: |
|
|
split_generators.append( |
|
|
datasets.SplitGenerator( |
|
|
name=split_names.get(split, split), |
|
|
gen_kwargs={ |
|
|
"local_extracted_archive_paths": local_extracted_archive_paths.get(split), |
|
|
"archives": [dl_manager.iter_archive(path) for path in archive_paths[split]], |
|
|
"meta_path": meta_paths[split], |
|
|
}, |
|
|
), |
|
|
) |
|
|
|
|
|
return split_generators |
|
|
|
|
|
def _generate_examples(self, local_extracted_archive_paths, archives, meta_path): |
|
|
"""Yields examples.""" |
|
|
data_fields = list(self._info().features.keys()) |
|
|
metadata = {} |
|
|
|
|
|
with open(meta_path, encoding="utf-8") as f: |
|
|
reader = csv.DictReader(f, delimiter="\t", quoting=csv.QUOTE_NONE) |
|
|
for row in tqdm(reader, desc="Reading metadata..."): |
|
|
|
|
|
for field in data_fields: |
|
|
if field not in row and field != "audio": |
|
|
row[field] = "" |
|
|
|
|
|
metadata[row["path"]] = row |
|
|
|
|
|
for i, audio_archive in enumerate(archives): |
|
|
for path, file in audio_archive: |
|
|
_, filename = os.path.split(path) |
|
|
if filename in metadata: |
|
|
result = dict(metadata[filename]) |
|
|
|
|
|
path = os.path.join(local_extracted_archive_paths[i], path) if local_extracted_archive_paths else path |
|
|
result["audio"] = {"path": path, "bytes": file.read()} |
|
|
result["path"] = path |
|
|
yield path, result |
|
|
|