File size: 4,303 Bytes
e05a5cf 399e131 e05a5cf 399e131 e05a5cf 399e131 e05a5cf 399e131 e05a5cf 399e131 e05a5cf 399e131 e05a5cf 399e131 e05a5cf 399e131 e05a5cf 399e131 e05a5cf 399e131 e05a5cf e7a19a6 e05a5cf e7a19a6 e59284a e7a19a6 e59284a e7a19a6 e59284a 399e131 e05a5cf e59284a e05a5cf 66b0332 e05a5cf 66b0332 47777be 66b0332 e05a5cf 399e131 e05a5cf |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# coding=utf-8
# Copyright 2021 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
"""AudioData dataset."""
import os
from pathlib import Path
import datasets
from datasets.tasks import AutomaticSpeechRecognition
_CITATION = """\
@inproceedings{
title={AudioData Speech Corpus},
author={Your Name},
year={Year}
}
"""
_DESCRIPTION = """\
The AudioData corpus of reading speech has been developed to provide speech data for acoustic-phonetic research studies
and for the evaluation of automatic speech recognition systems.
More info on AudioData dataset can be understood from the "README" which can be found here:
https://example.com/path/to/readme.txt
"""
# _HOMEPAGE = "https://example.com/path/to/dataset"
class AudioDataConfig(datasets.BuilderConfig):
"""BuilderConfig for AudioData."""
def __init__(self, **kwargs):
"""
Args:
data_dir: `string`, the path to the folder containing the audio files
citation: `string`, citation for the data set
url: `string`, url for information about the data set
**kwargs: keyword arguments forwarded to super.
"""
super(AudioDataConfig, self).__init__(version=datasets.Version("1.0.0", ""), **kwargs)
class AudioData(datasets.GeneratorBasedBuilder):
"""AudioData dataset."""
BUILDER_CONFIGS = [AudioDataConfig(name="clean", description="'Clean' speech.")]
def _info(self):
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=datasets.Features(
{
"folder": datasets.Value("string"),
"audio": datasets.Audio(sampling_rate=16_000),
"label": datasets.Value("string"),
}
),
supervised_keys=("folder", "label"),
# homepage=_HOMEPAGE,
citation=_CITATION,
task_templates=[AutomaticSpeechRecognition(audio_column="audio", transcription_column="label")],
)
def _split_generators(self, dl_manager):
data_dir = os.path.abspath(os.path.expanduser(dl_manager.manual_dir))
if not os.path.exists(data_dir):
raise FileNotFoundError(
f"{data_dir} does not exist. Make sure you insert a manual dir via `datasets.load_dataset('timit_asr', data_dir=...)` that includes files unzipped from the TIMIT zip. Manual download instructions: {self.manual_download_instructions}"
)
return [
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"split": "train", "data_dir": data_dir}),
datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"split": "test", "data_dir": data_dir}),
]
def _generate_examples(self, split, data_dir):
"""Generate examples from AudioData based on the test/train csv information."""
# Iterating the contents of the data to extract the relevant information
wav_paths = sorted(Path(data_dir).glob(f"**/{split}/**/*.wav"))
for key, wav_path in enumerate(wav_paths):
# extract transcript
txt_path = with_case_insensitive_suffix(wav_path, ".txt")
with txt_path.open(encoding="utf-8") as op:
transcript = " ".join(op.readlines()[0].split()[2:]) # first two items are sample number
example = {
"file": str(wav_path),
"audio": str(wav_path),
"text": transcript,
}
yield key, example
def with_case_insensitive_suffix(path: Path, suffix: str):
path = path.with_suffix(suffix.lower())
path = path if path.exists() else path.with_suffix(suffix.upper())
return path
|