File size: 5,710 Bytes
b5a72fa de5541d 7d2e23d de5541d 7d2e23d 659f386 7d2e23d de5541d b5a72fa 659f386 b5a72fa dcf2982 7d2e23d dcf2982 b5a72fa 620caaa dcf2982 620caaa 7d2e23d dcf2982 b5a72fa dcf2982 b5a72fa dcf2982 7d2e23d dcf2982 b5a72fa 659f386 de5541d 7d2e23d de5541d b5a72fa dcf2982 b5a72fa dcf2982 b5a72fa dcf2982 7d2e23d dcf2982 7d2e23d dcf2982 de5541d dcf2982 de5541d dcf2982 de5541d dcf2982 659f386 dcf2982 b5a72fa 7d2e23d b5a72fa dcf2982 b5a72fa dcf2982 b5a72fa dcf2982 b5a72fa dcf2982 b5a72fa dcf2982 b5a72fa 7d2e23d b5a72fa 0bae7d4 7d2e23d dcf2982 7d2e23d 659f386 7d2e23d dcf2982 7d2e23d dcf2982 7d2e23d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
import os
import csv
import datasets
from datasets import Audio, BuilderConfig
# Konfiguratsiya sinfi: til qisqartmasi va ma'lumotlar joylashgan papkani belgilaydi.
class STTConfig(BuilderConfig):
def __init__(self, language_abbr, data_dir, **kwargs):
"""
Args:
language_abbr (str): Masalan, "uz".
data_dir (str): Dataset joylashgan asosiy papka, masalan "Dataset_STT".
**kwargs: Qolgan parametrlar.
"""
super().__init__(**kwargs)
self.language_abbr = language_abbr
self.data_dir = data_dir
# Dataset yuklash skripti
class MySTTDataset(datasets.GeneratorBasedBuilder):
"""
Uzbek STT dataset yuklash skripti:
- Audio fayllar .tar arxiv ichida joylashgan.
- Transkripsiya ma'lumotlari mos TSV faylda.
- "audio" ustuni Audio() tipida aniqlangan, shuning uchun Hub Viewer "play" tugmasini ko'rsatadi.
"""
VERSION = datasets.Version("1.0.0")
BUILDER_CONFIGS = [
STTConfig(
name="uz",
version=datasets.Version("1.0.0"),
description="Uzbek subset of the STT dataset",
language_abbr="uz",
data_dir="Dataset_STT", # Asosiy papka nomi
)
]
DEFAULT_CONFIG_NAME = "uz"
def _info(self):
"""
Dataset ustunlarini aniqlaydi.
"audio" ustuni Audio() tipida belgilangan – bu orqali Viewer audio faylni avtomatik dekodlaydi.
"""
return datasets.DatasetInfo(
description="Uzbek STT dataset: audio fayllar .tar arxivda, transcriptions esa TSV faylda saqlanadi.",
features=datasets.Features({
"id": datasets.Value("string"),
"audio": Audio(sampling_rate=None), # Asl sampling rate saqlanadi
"sentence": datasets.Value("string"),
"duration": datasets.Value("float"),
"age": datasets.Value("string"),
"gender": datasets.Value("string"),
"accents": datasets.Value("string"),
"locale": datasets.Value("string"),
}),
supervised_keys=None,
version=self.VERSION,
)
def _split_generators(self, dl_manager):
"""
Har bir split uchun: tar arxiv va mos TSV fayllarining yo'llari aniqlanadi,
va tar fayllar dl_manager.extract() orqali ochiladi.
"""
config = self.config
base_dir = config.data_dir # Misol: "Dataset_STT"
lang = config.language_abbr # Misol: "uz"
train_tar = os.path.join(base_dir, "audio", lang, "train.tar")
train_tsv = os.path.join(base_dir, "transcript", lang, "train.tsv")
test_tar = os.path.join(base_dir, "audio", lang, "test.tar")
test_tsv = os.path.join(base_dir, "transcript", lang, "test.tsv")
val_tar = os.path.join(base_dir, "audio", lang, "validation.tar")
val_tsv = os.path.join(base_dir, "transcript", lang, "validation.tsv")
# Tar arxiv extract qilinadi:
train_tar_extracted = dl_manager.extract(train_tar)
test_tar_extracted = dl_manager.extract(test_tar)
val_tar_extracted = dl_manager.extract(val_tar)
return [
datasets.SplitGenerator(
name=datasets.Split.TRAIN,
gen_kwargs={
"archive_dir": train_tar_extracted,
"tsv_path": train_tsv,
},
),
datasets.SplitGenerator(
name=datasets.Split.TEST,
gen_kwargs={
"archive_dir": test_tar_extracted,
"tsv_path": test_tsv,
},
),
datasets.SplitGenerator(
name=datasets.Split.VALIDATION,
gen_kwargs={
"archive_dir": val_tar_extracted,
"tsv_path": val_tsv,
},
),
]
def _generate_examples(self, archive_dir, tsv_path):
"""
TSV faylini qatorma-qator o'qiydi va metadata lug'atini tuzadi.
Keyin, archive papkasidan mos .mp3 faylni topib,
audio ustunini quyidagicha shakllantiradi:
{"path": <relative file name>, "bytes": <audio file baytlari>}
Bu shakl Dataset Viewer tomonidan Audio() sifatida aniqlanib, "play" tugmasini ko'rsatishga imkon beradi.
"""
with open(tsv_path, "r", encoding="utf-8") as f:
reader = csv.DictReader(f, delimiter="\t")
for idx, row in enumerate(reader):
audio_id = row["id"]
mp3_file = audio_id + ".mp3"
full_path = os.path.join(archive_dir, mp3_file)
if os.path.isfile(full_path):
with open(full_path, "rb") as audio_file:
audio_bytes = audio_file.read()
# MUHIM: "path" qiymatini lokal extract qilingan papka o'rniga, faqat fayl nomi sifatida uzatamiz
yield idx, {
"id": audio_id,
"audio": {"path": mp3_file, "bytes": audio_bytes},
"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", ""),
}
else:
continue
|