import csv import os from typing import Dict, List import datasets from seacrowd.utils import schemas from seacrowd.utils.configs import SEACrowdConfig from seacrowd.utils.constants import (DEFAULT_SEACROWD_VIEW_NAME, DEFAULT_SOURCE_VIEW_NAME, Tasks) _DATASETNAME = "su_id_asr" _SOURCE_VIEW_NAME = DEFAULT_SOURCE_VIEW_NAME _UNIFIED_VIEW_NAME = DEFAULT_SEACROWD_VIEW_NAME _LANGUAGES = ["sun"] _LOCAL = False _CITATION = """\ @inproceedings{sodimana18_sltu, author={Keshan Sodimana and Pasindu {De Silva} and Supheakmungkol Sarin and Oddur Kjartansson and Martin Jansche and Knot Pipatsrisawat and Linne Ha}, title={{A Step-by-Step Process for Building TTS Voices Using Open Source Data and Frameworks for Bangla, Javanese, Khmer, Nepali, Sinhala, and Sundanese}}, year=2018, booktitle={Proc. 6th Workshop on Spoken Language Technologies for Under-Resourced Languages (SLTU 2018)}, pages={66--70}, doi={10.21437/SLTU.2018-14} } """ _DESCRIPTION = """\ Sundanese ASR training data set containing ~220K utterances. This dataset was collected by Google in Indonesia. """ _HOMEPAGE = "https://indonlp.github.io/nusa-catalogue/card.html?su_id_asr" _LICENSE = "Attribution-ShareAlike 4.0 International." _URLs = { "train": "https://univindonesia-my.sharepoint.com/personal/fathan_naufal_office_ui_ac_id/_layouts/15/download.aspx?share=EXnxiynWF0BBhhJS7_1xPT4BInHRARnyP4nqbpLOZwKuLg", "validation": "https://univindonesia-my.sharepoint.com/personal/fathan_naufal_office_ui_ac_id/_layouts/15/download.aspx?SourceUrl=/personal/fathan_naufal_office_ui_ac_id/Documents/ES0-kCylYWtDqlpGq428pJYBK4u83a53Dl_zLmY7tg9ycw?e=PqW0tX", "test": "https://univindonesia-my.sharepoint.com/personal/fathan_naufal_office_ui_ac_id/_layouts/15/download.aspx?SourceUrl=/personal/fathan_naufal_office_ui_ac_id/Documents/EfNmlx62QRVDrBmCRxQvgzEB13AqeJNESYy_pSbjVZV9yg?e=VU2g90", } _SUPPORTED_TASKS = [Tasks.SPEECH_RECOGNITION] _SOURCE_VERSION = "1.0.0" _SEACROWD_VERSION = "2024.06.20" class SuIdASR(datasets.GeneratorBasedBuilder): """su_id contains ~220K utterances for Sundanese ASR training data.""" BUILDER_CONFIGS = [ SEACrowdConfig( name="su_id_asr_source", version=datasets.Version(_SOURCE_VERSION), description="SU_ID_ASR source schema", schema="source", subset_id="su_id_asr", ), SEACrowdConfig( name="su_id_asr_seacrowd_sptext", version=datasets.Version(_SEACROWD_VERSION), description="SU_ID_ASR Nusantara schema", schema="seacrowd_sptext", subset_id="su_id_asr", ), ] DEFAULT_CONFIG_NAME = "su_id_asr_source" def _info(self): if self.config.schema == "source": features = datasets.Features( { "id": datasets.Value("string"), "speaker_id": datasets.Value("string"), "path": datasets.Value("string"), "audio": datasets.Audio(sampling_rate=16_000), "text": datasets.Value("string"), } ) elif self.config.schema == "seacrowd_sptext": features = schemas.speech_text_features return datasets.DatasetInfo( description=_DESCRIPTION, features=features, homepage=_HOMEPAGE, license=_LICENSE, citation=_CITATION, # task_templates=[datasets.AutomaticSpeechRecognition(audio_column="audio", transcription_column="text")], ) def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]: # Mengunduh dataset dari tiga tautan yang berbeda (train, validation, test) train_path = dl_manager.download_and_extract(_URLs["train"]) validation_path = dl_manager.download_and_extract(_URLs["validation"]) test_path = dl_manager.download_and_extract(_URLs["test"]) # Membagi dataset ke dalam split train, validation, dan test return [ datasets.SplitGenerator( name=datasets.Split.TRAIN, gen_kwargs={"filepath": train_path, "split": "train"}, ), datasets.SplitGenerator( name=datasets.Split.VALIDATION, gen_kwargs={"filepath": validation_path, "split": "validation"}, ), datasets.SplitGenerator( name=datasets.Split.TEST, gen_kwargs={"filepath": test_path, "split": "test"}, ), ] def _generate_examples(self, filepath: Dict, split: str): """ Generate examples from the dataset, supporting multiple splits (train, validation, test). """ if self.config.schema == "source" or self.config.schema == "seacrowd_sptext": for key, each_filepath in filepath.items(): tsv_file = os.path.join(each_filepath, "asr_sundanese", "utt_spk_text.tsv") with open(tsv_file, "r") as file: tsv_file = csv.reader(file, delimiter="\t") for line in tsv_file: audio_id, speaker_id, transcription_text = line[0], line[1], line[2] # Menentukan path untuk file audio wav_path = os.path.join(each_filepath, "asr_sundanese", "data", "{}".format(audio_id[:2]), "{}.flac".format(audio_id)) if os.path.exists(wav_path): if self.config.schema == "source": ex = { "id": audio_id, "speaker_id": speaker_id, "path": wav_path, "audio": wav_path, "text": transcription_text, "split": split, # Menyimpan info split } yield audio_id, ex elif self.config.schema == "seacrowd_sptext": ex = { "id": audio_id, "speaker_id": speaker_id, "path": wav_path, "audio": wav_path, "text": transcription_text, "metadata": { "speaker_age": None, "speaker_gender": None, }, "split": split, # Menyimpan info split } yield audio_id, ex else: raise ValueError(f"Invalid config: {self.config.name}")