ParsiGoo / ParsiGoo.py
Kamtera's picture
Upload ParsiGoo.py with huggingface_hub
27102cb
raw
history blame
1.91 kB
import os
import datasets
class ParsiGoo(datasets.GeneratorBasedBuilder):
VERSION = datasets.Version("1.0.0")
def _info(self):
features = datasets.Features(
{
"text": datasets.Value("string"),
"audio_file": datasets.Value("string"),
"speaker_name": datasets.Value("string"),
"root_path": datasets.Value("string")
}
)
return datasets.DatasetInfo(
description="ParsiGoo dataset",
features=features,
homepage="https://example.com",
citation="",
)
def _split_generators(self, dl_manager):
data_dir = "datasets"#dl_manager.download_and_extract("https://example.com/datasets/parsigoo.zip")
splits = []
for speaker_name in os.listdir(data_dir):
if not os.path.isdir(os.path.join(data_dir, speaker_name)):
continue
root_path = os.path.join(data_dir, speaker_name)
meta_file = os.path.join(root_path, "metadata.csv")
splits.append(
datasets.SplitGenerator(
name=speaker_name,
gen_kwargs={
"txt_file": meta_file,
"speaker_name": speaker_name,
"root_path": root_path
}
)
)
return splits
def _generate_examples(self, txt_file, speaker_name, root_path):
with open(txt_file, "r", encoding="utf-8") as ttf:
for i, line in enumerate(ttf):
cols = line.split("|")
wav_file = cols[1].strip()
text = cols[0].strip()
wav_file = os.path.join(root_path, "wavs", wav_file)
yield i, {"text": text, "audio_file": wav_file, "speaker_name": speaker_name, "root_path": root_path}