pwr-azon-speech-dataset / pwr-azon-speech-dataset_depr.py
czyzi0's picture
Depracate data script
08bd38b
# coding=utf-8
"""PWr AZON Speech Dataset"""
import pathlib
import datasets
_DESCRIPTION = """\
TODO
"""
_HOMEPAGE = ""
_CITATION = ""
_LICENSE = "CC BY-SA 4.0"
class PWrAZON(datasets.GeneratorBasedBuilder):
def _info(self):
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=datasets.Features(
{
"audio": datasets.Audio(sampling_rate=44_100),
"transcript": datasets.Value("string"),
"gender": datasets.Value("string"),
"id": datasets.Value("string"),
"id_og": datasets.Value("string"),
},
),
supervised_keys=None,
homepage=_HOMEPAGE,
citation=_CITATION,
license=_LICENSE,
)
def _split_generators(self, dl_manager):
metadata_train_path = dl_manager.download_and_extract(
"https://huggingface.co/datasets/czyzi0/pwr-azon-speech-dataset/raw/main/metadata_train.tsv"
)
metadata_unsup_path = dl_manager.download_and_extract(
"https://huggingface.co/datasets/czyzi0/pwr-azon-speech-dataset/raw/main/metadata_unsup.tsv"
)
wavs_train_path = dl_manager.download_and_extract(
"https://huggingface.co/datasets/czyzi0/pwr-azon-speech-dataset/resolve/main/wavs_train.tar.gz"
)
wavs_unsup_path = dl_manager.download_and_extract(
"https://huggingface.co/datasets/czyzi0/pwr-azon-speech-dataset/resolve/main/wavs_unsup.tar.gz"
)
return [
datasets.SplitGenerator(
name="train",
gen_kwargs={
"metadata_path": metadata_train_path,
"wavs_path": pathlib.Path(wavs_train_path) / "wavs_train",
},
),
datasets.SplitGenerator(
name="unsup",
gen_kwargs={
"metadata_path": metadata_unsup_path,
"wavs_path": pathlib.Path(wavs_unsup_path) / "wavs_unsup",
},
),
]
def _generate_examples(self, metadata_path, wavs_path):
with open(metadata_path, "r") as fh:
header = next(fh).strip().split("\t")
for item_idx, line in enumerate(fh):
line = line.strip().split("\t")
id_ = line[header.index("id")]
transcript = line[header.index("transcript")]
gender = line[header.index("gender")]
id_og = line[header.index("id_og")]
wav_path = wavs_path / f"{id_}.wav"
with open(wav_path, "rb") as fh_:
item = {
"audio": {"path": str(wav_path.absolute()), "bytes": fh_.read()},
"transcript": transcript,
"gender": gender,
"id": id_,
"id_og": id_og,
}
yield item_idx, item