|
import glob |
|
import os |
|
from functools import partial |
|
|
|
import datasets |
|
|
|
DS_NAMES = [ |
|
"coursera" |
|
] |
|
VERSION = datasets.Version("0.0.1") |
|
|
|
|
|
class PublicSpeech(datasets.GeneratorBasedBuilder): |
|
"""Speech dataset.""" |
|
|
|
BUILDER_CONFIGS = [ |
|
datasets.BuilderConfig(name=data_name, version=VERSION, description=f"Speech {data_name} dataset") |
|
for data_name in DS_NAMES |
|
] |
|
|
|
def _info(self): |
|
return datasets.DatasetInfo( |
|
description="Hebrew speech datasets", |
|
features=datasets.Features( |
|
{ |
|
"audio": datasets.Audio(sampling_rate=16000), |
|
"sentence": datasets.Value("string"), |
|
} |
|
), |
|
supervised_keys=("audio", "sentence"), |
|
homepage="https://huggingface.co/datasets/imvladikon/hebrew_speech", |
|
citation="TODO", |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
downloader = partial( |
|
lambda split: dl_manager.download_and_extract(f"data/{self.config.name}/{split}.tar.gz"), |
|
) |
|
|
|
return [ |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TRAIN, |
|
gen_kwargs={"root_path": downloader("train"), "split": "train"}, |
|
), |
|
datasets.SplitGenerator( |
|
name=datasets.Split.VALIDATION, |
|
gen_kwargs={"root_path": downloader("dev"), "split": "dev"}, |
|
), |
|
] |
|
|
|
def _generate_examples(self, root_path, split): |
|
split_path = os.path.join(root_path, split) |
|
for wav in glob.glob(split_path + "/*.wav"): |
|
uid = os.path.splitext(os.path.basename(wav))[0] |
|
with open(os.path.join(split_path, f"{uid}.txt"), encoding="utf-8") as fin: |
|
text = fin.read() |
|
example = { |
|
"audio": wav, |
|
"sentence": text, |
|
} |
|
yield uid, example |
|
|