|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"""TibetanVoice: The Stanford Question Answering Dataset.""" |
|
|
|
|
|
import csv |
|
import os |
|
import datasets |
|
from datasets.tasks import QuestionAnsweringExtractive |
|
|
|
|
|
logger = datasets.logging.get_logger(__name__) |
|
|
|
|
|
_CITATION = """\ |
|
@article{2016arXiv160605250R, |
|
author = {spsithar} and {TenzinGayche}, |
|
title = "TibetanVoice: 6.5 hours of validated transcribed speech data from 9 audio book in lhasa dialect ", |
|
journal = {arXiv e-prints}, |
|
year = 2023, |
|
|
|
} |
|
""" |
|
|
|
_DESCRIPTION = """\ |
|
TibetanVoice: 6.5 hours of validated transcribed speech data from 9 audio book in lhasa dialect. The dataset is in tsv format with two columns, path and sentence. The path column contains the path to the audio file and the sentence column contains the corresponding sentence spoken in the audio file. |
|
|
|
|
|
""" |
|
|
|
|
|
_URL = "https://huggingface.co/datasets/openpecha/tibetan_voice/resolve/main/transcripts%20/" |
|
_DataUrl="https://huggingface.co/datasets/openpecha/tibetan_voice/resolve/main/audio/wav.tar" |
|
_URLS = { |
|
"train": _URL + "train-uni.tsv", |
|
"valid": _URL + "valid-uni.tsv", |
|
"test": _URL + "test-uni.tsv", |
|
"train-wylie": _URL + "train-wylie.tsv", |
|
"valid-wylie": _URL + "valid-wylie.tsv", |
|
"test-wylie": _URL + "test-wylie.tsv", |
|
} |
|
|
|
|
|
class TibetanVoiceConfig(datasets.BuilderConfig): |
|
"""BuilderConfig for TibetanVoice.""" |
|
|
|
def __init__(self, **kwargs): |
|
"""BuilderConfig for TibetanVoice. |
|
|
|
Args: |
|
**kwargs: keyword arguments forwarded to super. |
|
""" |
|
super(TibetanVoiceConfig, self).__init__(**kwargs) |
|
|
|
|
|
class TibetanVoice(datasets.GeneratorBasedBuilder): |
|
"""TibetanVoice: The Stanford Question Answering Dataset. Version 1.1.""" |
|
|
|
BUILDER_CONFIGS = [ |
|
TibetanVoiceConfig( |
|
name="lhasa", |
|
version=datasets.Version("1.0.0", ""), |
|
description="The dataset comprises 6.5 hours of validated transcribed speech data from 9 audio book in lhasa dialect ", |
|
), |
|
TibetanVoiceConfig( |
|
name="lhasa-wylie", |
|
version=datasets.Version("1.0.0", ""), |
|
description="The dataset comprises 6.5 hours of validated transcribed speech data (wylie) from 9 audio book in lhasa dialect ", |
|
), |
|
] |
|
|
|
def _info(self): |
|
return datasets.DatasetInfo( |
|
description=_DESCRIPTION, |
|
features=datasets.Features( |
|
{ |
|
"path": datasets.Value("string"), |
|
"audio": datasets.features.Audio(sampling_rate=16_000), |
|
"sentence": datasets.Value("string"), |
|
} |
|
), |
|
|
|
|
|
supervised_keys=None, |
|
homepage="https://huggingface.co/datasets/openpecha/tibetan_voice/", |
|
citation=_CITATION, |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
downloaded_files = dl_manager.download_and_extract(_URLS) |
|
downloaded_wav = dl_manager.download(_DataUrl) |
|
wavs= dl_manager.iter_archive(downloaded_wav) |
|
downloaded_wav = dl_manager.download_and_extract(_DataUrl) |
|
if(self.config.name!='lhasa'): |
|
downloaded_files['train']= downloaded_files['train-wylie'] |
|
downloaded_files['test']= downloaded_files['test-wylie'] |
|
downloaded_files['valid']= downloaded_files['valid-wylie'] |
|
else: |
|
downloaded_files['train']=downloaded_files['train'] |
|
downloaded_files['test']= downloaded_files['test'] |
|
downloaded_files['valid']= downloaded_files['valid'] |
|
|
|
|
|
|
|
return [ |
|
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files["train"],"wavs":wavs,'wavfilepath':downloaded_wav}), |
|
datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"filepath": downloaded_files["valid"],"wavs":wavs,'wavfilepath':downloaded_wav}), |
|
datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": downloaded_files["test"],"wavs":wavs,'wavfilepath':downloaded_wav}), |
|
] |
|
def _generate_examples(self, filepath, wavs,wavfilepath): |
|
|
|
"""This function returns the examples in the raw (text) form.""" |
|
example_map = {} |
|
logger.info("generating examples from = %s", filepath) |
|
with open(filepath, encoding="utf-8") as f: |
|
reader = csv.reader(f, delimiter='\t') |
|
|
|
for row in reader: |
|
if len(row) >= 2: |
|
path = row[1] |
|
sentence = row[2] |
|
if(str(path)!='path'): |
|
example_map[path] = sentence |
|
else : |
|
continue |
|
|
|
|
|
|
|
audio_map = {} |
|
for path, f in wavs: |
|
_, filename = os.path.split(path) |
|
audio_map[filename] = {"path":os.path.join( wavfilepath,path), "bytes": f.read()} |
|
|
|
for key, path in enumerate(example_map.keys()): |
|
filename = path |
|
sentence = example_map.get(filename, "") |
|
audio = audio_map.get(filename, {}) |
|
example = { |
|
"path": path, |
|
"sentence": sentence, |
|
"audio": audio |
|
} |
|
|
|
yield key, example |
|
|
|
|
|
|