|
from datasets import GeneratorBasedBuilder, DatasetInfo, SplitGenerator, Split, Features, Value, Audio,SplitGenerator, Split |
|
import os |
|
import json |
|
import csv |
|
|
|
import datasets |
|
from datasets.utils.py_utils import size_str |
|
from tqdm import tqdm |
|
|
|
|
|
_BASE_URL = "https://huggingface.co/datasets/iulik-pisik/horoscop_neti/resolve/main/" |
|
_AUDIO_URL = _BASE_URL + "audio/{split}.tar" |
|
_TRANSCRIPT_URL = _BASE_URL + "transcript/{split}.tsv" |
|
|
|
class HoroscopNeti(GeneratorBasedBuilder): |
|
|
|
def _info(self): |
|
return DatasetInfo( |
|
description="Descrierea datasetului tău.", |
|
features=Features({ |
|
"path": Value("string"), |
|
"audio": Audio(sampling_rate=16000), |
|
"sentence": Value("string"), |
|
}), |
|
supervised_keys=("audio", "transcript"), |
|
homepage="https://huggingface.co/datasets/iulik-pisik/horoscop_neti", |
|
citation="Referința de citare a datasetului", |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
audio_urls = { |
|
"train_audio": _AUDIO_URL.format(split="train"), |
|
"test_audio": _AUDIO_URL.format(split="test"), |
|
"validation_audio": _AUDIO_URL.format(split="validation"), |
|
} |
|
tsv_urls = { |
|
"train_tsv": _TRANSCRIPT_URL.format(split="train"), |
|
"test_tsv": _TRANSCRIPT_URL.format(split="test"), |
|
"validation_tsv": _TRANSCRIPT_URL.format(split="validation"), |
|
} |
|
|
|
downloaded_audio_files = dl_manager.download_and_extract(audio_urls) |
|
downloaded_tsv_files = dl_manager.download(tsv_urls) |
|
|
|
return [ |
|
SplitGenerator( |
|
name=Split.TRAIN, |
|
gen_kwargs={ |
|
"archive_path": downloaded_audio_files["train_audio"], |
|
"tsv_path": downloaded_tsv_files["train_tsv"], |
|
}, |
|
), |
|
SplitGenerator( |
|
name=Split.TEST, |
|
gen_kwargs={ |
|
"archive_path": downloaded_audio_files["test_audio"], |
|
"tsv_path": downloaded_tsv_files["test_tsv"], |
|
}, |
|
), |
|
SplitGenerator( |
|
name=Split.VALIDATION, |
|
gen_kwargs={ |
|
"archive_path": downloaded_audio_files["validation_audio"], |
|
"tsv_path": downloaded_tsv_files["validation_tsv"], |
|
}, |
|
), |
|
] |
|
|
|
|
|
def _generate_examples(self, archive_path, tsv_path): |
|
with open(tsv_path, encoding="utf-8") as f: |
|
reader = csv.DictReader(f, delimiter="\t", quoting=csv.QUOTE_NONE) |
|
for row in tqdm(reader, desc="Se citesc datele..."): |
|
audio_file_name = row["path"] |
|
audio_path = os.path.join(archive_path, audio_file_name) |
|
|
|
if not os.path.isfile(audio_path): |
|
continue |
|
|
|
yield audio_file_name, { |
|
"path": audio_path, |
|
"audio": audio_path, |
|
"sentence": row["sentence"], |
|
} |