|
import os
|
|
import csv
|
|
import tarfile
|
|
|
|
def _generate_examples(self, prompts_path, audio_tar_path):
|
|
"""
|
|
Yields examples as (key, example) tuples.
|
|
|
|
Args:
|
|
prompts_path (str): transcript/uz/<split>/<split>.tsv – metadata fayl yo'li.
|
|
audio_tar_path (str): audio/uz/<split>/<split>.tar – tar arxiv yo'li (ichida *.mp3).
|
|
"""
|
|
|
|
metadata_map = {}
|
|
with open(prompts_path, encoding="utf-8") as f:
|
|
reader = csv.DictReader(f, delimiter="\t")
|
|
for row in reader:
|
|
|
|
file_name = row["path"].strip()
|
|
if not file_name.endswith(".mp3"):
|
|
file_name += ".mp3"
|
|
metadata_map[file_name] = row
|
|
|
|
|
|
id_ = 0
|
|
with tarfile.open(audio_tar_path, "r") as tar:
|
|
for member in tar.getmembers():
|
|
|
|
file_name = os.path.basename(member.name)
|
|
if file_name in metadata_map:
|
|
row = metadata_map[file_name]
|
|
audio_file = tar.extractfile(member)
|
|
if audio_file is None:
|
|
continue
|
|
audio_bytes = audio_file.read()
|
|
audio = {"path": file_name, "bytes": audio_bytes}
|
|
yield id_, {
|
|
"id": row.get("id", file_name),
|
|
"path": row.get("path", file_name),
|
|
"sentence": row.get("sentence", ""),
|
|
"duration": float(row.get("duration", 0.0)),
|
|
"age": row.get("age", ""),
|
|
"gender": row.get("gender", ""),
|
|
"accents": row.get("accents", ""),
|
|
"locale": row.get("locale", ""),
|
|
"audio": audio,
|
|
}
|
|
id_ += 1 |