NURC-SP_Corpus_Minimo / NURC-SP_Corpus_Minimo.py
RodrigoLimaRFL's picture
Upload 3 files
34bd4fe verified
raw
history blame
2.73 kB
import csv
import datasets
from datasets import BuilderConfig, GeneratorBasedBuilder, DatasetInfo, SplitGenerator, Split
_PROMPTS_URLS = {
"all": "segmented_audios.csv",
}
_ARCHIVES = {
"all": "nurc-sp_corpus_minimo.tar.gz",
}
class NurcSPConfig(BuilderConfig):
def __init__(self, prompts_type="original", **kwargs):
super().__init__(**kwargs)
self.prompts_type = prompts_type
class NurcSPDataset(GeneratorBasedBuilder):
def _info(self):
return DatasetInfo(
features=datasets.Features(
{
"path": datasets.Value("string"),
"name": datasets.Value("string"),
"speaker": datasets.Value("string"),
"start_time": datasets.Value("string"),
"end_time": datasets.Value("string"),
"normalized_text": datasets.Value("string"),
"text": datasets.Value("string"),
"audio": datasets.Audio(sampling_rate=16_000),
}
)
)
def _split_generators(self, dl_manager):
prompts_path = dl_manager.download(_PROMPTS_URLS)
archive = dl_manager.download(_ARCHIVES)
return [
{
"prompts_path": prompts_path["all"],
"audio_files": dl_manager.iter_archive(archive["all"]),
}
]
def _generate_examples(self, prompts_path, path_to_clips, audio_files):
examples = {}
with open(prompts_path, "r") as f:
csv_reader = csv.DictReader(f)
for row in csv_reader:
path = row['path']
name = row['name']
speaker = row['speaker']
start_time = row['start_time']
end_time = row['end_time']
normalized_text = row['normalized_text']
text = row['text']
examples[path] = {
"name": name,
"speaker": speaker,
"start_time": start_time,
"end_time": end_time,
"normalized_text": normalized_text,
"text": text,
}
inside_clips_dir = False
id_ = 0
for path, f in audio_files:
if path.startswith(path_to_clips):
inside_clips_dir = True
if path in examples:
audio = {"path": path, "bytes": f.read()}
yield id_, {**examples[path], "audio": audio}
id_ += 1
elif inside_clips_dir:
break