|
|
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 = { |
|
|
"su_id_asr_train": "https://drive.google.com/file/d/1-9oCkIQSok_STemyNBLx2EDQXfmWabsU/view?usp=sharing", |
|
|
"su_id_asr_dev": "https://drive.google.com/file/d/1IkqEuGrIyKbCSDo9q6F6_r_vkeJ1pcrp/view?usp=sharing", |
|
|
"su_id_asr_test": "https://drive.google.com/file/d/1-7aLW9Tzs4lxm9ImWho91FjpgpVC6wAc/view?usp=sharing", |
|
|
} |
|
|
|
|
|
_SUPPORTED_TASKS = [Tasks.SPEECH_RECOGNITION] |
|
|
|
|
|
_SOURCE_VERSION = "1.0.0" |
|
|
|
|
|
_SEACROWD_VERSION = "2024.06.20" |
|
|
|
|
|
def download_from_gdrive(url, output_dir): |
|
|
"""Download a file from Google Drive and save it to the specified directory.""" |
|
|
file_id = url.split("/d/")[-1].split("/")[0] |
|
|
gdrive_url = f"https://drive.google.com/uc?id={file_id}" |
|
|
output_path = os.path.join(output_dir, f"{file_id}.zip") |
|
|
gdown.download(gdrive_url, output_path, quiet=False) |
|
|
return output_path |
|
|
|
|
|
|
|
|
class JvIdASR(datasets.GeneratorBasedBuilder): |
|
|
"""Javanese ASR training data set containing ~185K utterances.""" |
|
|
|
|
|
SOURCE_VERSION = datasets.Version(_SOURCE_VERSION) |
|
|
SEACROWD_VERSION = datasets.Version(_SEACROWD_VERSION) |
|
|
|
|
|
BUILDER_CONFIGS = [ |
|
|
SEACrowdConfig( |
|
|
name="su_id_asr_source", |
|
|
version=SOURCE_VERSION, |
|
|
description="su_id_asr source schema", |
|
|
schema="source", |
|
|
subset_id="su_id_asr", |
|
|
), |
|
|
SEACrowdConfig( |
|
|
name="su_id_asr_seacrowd_sptext", |
|
|
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 _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]: |
|
|
"""Returns SplitGenerators.""" |
|
|
|
|
|
def download_from_gdrive(url, name): |
|
|
|
|
|
with tempfile.TemporaryDirectory() as temp_dir: |
|
|
file_id = url.split("/d/")[-1].split("/")[0] |
|
|
output_path = os.path.join(temp_dir, f"{name}.zip") |
|
|
|
|
|
|
|
|
gdown.download(url, output_path, fuzzy=True) |
|
|
|
|
|
|
|
|
extracted_path = dl_manager.extract(output_path) |
|
|
return extracted_path |
|
|
|
|
|
|
|
|
paths = { |
|
|
"train": download_from_gdrive(_URLs["su_id_asr_train"], 'asr_sundanese_train'), |
|
|
"dev": download_from_gdrive(_URLs["su_id_asr_dev"], 'asr_sundanese_dev'), |
|
|
"test": download_from_gdrive(_URLs["su_id_asr_test"], 'asr_sundanese_test') |
|
|
} |
|
|
|
|
|
return [ |
|
|
datasets.SplitGenerator( |
|
|
name=datasets.Split.TRAIN, |
|
|
gen_kwargs={"filepath": paths["train"]}, |
|
|
), |
|
|
datasets.SplitGenerator( |
|
|
name=datasets.Split.VALIDATION, |
|
|
gen_kwargs={"filepath": paths["dev"]}, |
|
|
), |
|
|
datasets.SplitGenerator( |
|
|
name=datasets.Split.TEST, |
|
|
gen_kwargs={"filepath": paths["test"]}, |
|
|
), |
|
|
] |
|
|
|
|
|
def _info(self) -> datasets.DatasetInfo: |
|
|
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, |
|
|
) |
|
|
|
|
|
def _generate_examples(self, filepath: str): |
|
|
tsv_file = os.path.join(filepath, "asr_sundanese", "utt_spk_text.tsv") |
|
|
with open(tsv_file, "r") as f: |
|
|
tsv_file = csv.reader(f, delimiter="\t") |
|
|
for line in tsv_file: |
|
|
audio_id, sp_id, text = line[0], line[1], line[2] |
|
|
wav_path = os.path.join(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": sp_id, |
|
|
"path": wav_path, |
|
|
"audio": wav_path, |
|
|
"text": text, |
|
|
} |
|
|
yield audio_id, ex |
|
|
elif self.config.schema == "seacrowd_sptext": |
|
|
ex = { |
|
|
"id": audio_id, |
|
|
"speaker_id": sp_id, |
|
|
"path": wav_path, |
|
|
"audio": wav_path, |
|
|
"text": text, |
|
|
"metadata": { |
|
|
"speaker_age": None, |
|
|
"speaker_gender": None, |
|
|
}, |
|
|
} |
|
|
yield audio_id, ex |
|
|
f.close() |