tibetan_voice / tibetan_voice.py
TenzinGayche's picture
wavpath issue fixed
e4147e9
raw
history blame
5.13 kB
# coding=utf-8
# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Lint as: python3
"""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",
}
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 ",
),
]
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"),
}
),
# No default supervised_keys (as we have to pass both question
# and context as input).
supervised_keys=None,
homepage="https://huggingface.co/datasets/TenzinGayche/Demo-datasets/",
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)
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