|
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_urania/resolve/main/" |
|
_AUDIO_URL = _BASE_URL + "audio.tar" |
|
_TRANSCRIPT_URL = _BASE_URL + "transcript.tsv" |
|
|
|
class HoroscopUrania(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_urania", |
|
citation="Referința de citare a datasetului", |
|
) |
|
|
|
|
|
def _split_generators(self, dl_manager): |
|
|
|
downloaded_audio_files = dl_manager.download_and_extract(_AUDIO_URL) |
|
downloaded_tsv_files = dl_manager.download(_TRANSCRIPT_URL) |
|
|
|
return [ |
|
SplitGenerator( |
|
name=Split.DATA, |
|
gen_kwargs={ |
|
"archive_path": downloaded_audio_files, |
|
"tsv_path": downloaded_tsv_files, |
|
}, |
|
), |
|
] |
|
|
|
|
|
|
|
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"], |
|
} |