Datasets:
Delete loading script
Browse files
vctk.py
DELETED
|
@@ -1,133 +0,0 @@
|
|
| 1 |
-
# coding=utf-8
|
| 2 |
-
# Copyright 2021 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors.
|
| 3 |
-
#
|
| 4 |
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
-
# you may not use this file except in compliance with the License.
|
| 6 |
-
# You may obtain a copy of the License at
|
| 7 |
-
#
|
| 8 |
-
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
-
#
|
| 10 |
-
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
-
# See the License for the specific language governing permissions and
|
| 14 |
-
# limitations under the License.
|
| 15 |
-
|
| 16 |
-
# Lint as: python3
|
| 17 |
-
"""VCTK dataset."""
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
import os
|
| 21 |
-
import re
|
| 22 |
-
|
| 23 |
-
import datasets
|
| 24 |
-
from datasets.tasks import AutomaticSpeechRecognition
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
_CITATION = """\
|
| 28 |
-
@inproceedings{Veaux2017CSTRVC,
|
| 29 |
-
title = {CSTR VCTK Corpus: English Multi-speaker Corpus for CSTR Voice Cloning Toolkit},
|
| 30 |
-
author = {Christophe Veaux and Junichi Yamagishi and Kirsten MacDonald},
|
| 31 |
-
year = 2017
|
| 32 |
-
}
|
| 33 |
-
"""
|
| 34 |
-
|
| 35 |
-
_DESCRIPTION = """\
|
| 36 |
-
The CSTR VCTK Corpus includes speech data uttered by 110 English speakers with various accents.
|
| 37 |
-
"""
|
| 38 |
-
|
| 39 |
-
_URL = "https://datashare.ed.ac.uk/handle/10283/3443"
|
| 40 |
-
_DL_URL = "https://datashare.is.ed.ac.uk/bitstream/handle/10283/3443/VCTK-Corpus-0.92.zip"
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
class VCTK(datasets.GeneratorBasedBuilder):
|
| 44 |
-
"""VCTK dataset."""
|
| 45 |
-
|
| 46 |
-
VERSION = datasets.Version("0.9.2")
|
| 47 |
-
|
| 48 |
-
BUILDER_CONFIGS = [
|
| 49 |
-
datasets.BuilderConfig(name="main", version=VERSION, description="VCTK dataset"),
|
| 50 |
-
]
|
| 51 |
-
|
| 52 |
-
def _info(self):
|
| 53 |
-
return datasets.DatasetInfo(
|
| 54 |
-
description=_DESCRIPTION,
|
| 55 |
-
features=datasets.Features(
|
| 56 |
-
{
|
| 57 |
-
"speaker_id": datasets.Value("string"),
|
| 58 |
-
"audio": datasets.features.Audio(sampling_rate=48_000),
|
| 59 |
-
"file": datasets.Value("string"),
|
| 60 |
-
"text": datasets.Value("string"),
|
| 61 |
-
"text_id": datasets.Value("string"),
|
| 62 |
-
"age": datasets.Value("string"),
|
| 63 |
-
"gender": datasets.Value("string"),
|
| 64 |
-
"accent": datasets.Value("string"),
|
| 65 |
-
"region": datasets.Value("string"),
|
| 66 |
-
"comment": datasets.Value("string"),
|
| 67 |
-
}
|
| 68 |
-
),
|
| 69 |
-
supervised_keys=("file", "text"),
|
| 70 |
-
homepage=_URL,
|
| 71 |
-
citation=_CITATION,
|
| 72 |
-
task_templates=[AutomaticSpeechRecognition(audio_column="audio", transcription_column="text")],
|
| 73 |
-
)
|
| 74 |
-
|
| 75 |
-
def _split_generators(self, dl_manager):
|
| 76 |
-
root_path = dl_manager.download_and_extract(_DL_URL)
|
| 77 |
-
|
| 78 |
-
return [
|
| 79 |
-
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"root_path": root_path}),
|
| 80 |
-
]
|
| 81 |
-
|
| 82 |
-
def _generate_examples(self, root_path):
|
| 83 |
-
"""Generate examples from the VCTK corpus root path."""
|
| 84 |
-
|
| 85 |
-
meta_path = os.path.join(root_path, "speaker-info.txt")
|
| 86 |
-
txt_root = os.path.join(root_path, "txt")
|
| 87 |
-
wav_root = os.path.join(root_path, "wav48_silence_trimmed")
|
| 88 |
-
# NOTE: "comment" is handled separately in logic below
|
| 89 |
-
fields = ["speaker_id", "age", "gender", "accent", "region"]
|
| 90 |
-
|
| 91 |
-
key = 0
|
| 92 |
-
with open(meta_path, encoding="utf-8") as meta_file:
|
| 93 |
-
_ = next(iter(meta_file))
|
| 94 |
-
for line in meta_file:
|
| 95 |
-
data = {}
|
| 96 |
-
line = line.strip()
|
| 97 |
-
search = re.search(r"\(.*\)", line)
|
| 98 |
-
if search is None:
|
| 99 |
-
data["comment"] = ""
|
| 100 |
-
else:
|
| 101 |
-
start, _ = search.span()
|
| 102 |
-
data["comment"] = line[start:]
|
| 103 |
-
line = line[:start]
|
| 104 |
-
values = line.split()
|
| 105 |
-
for i, field in enumerate(fields):
|
| 106 |
-
if field == "region":
|
| 107 |
-
data[field] = " ".join(values[i:])
|
| 108 |
-
else:
|
| 109 |
-
data[field] = values[i] if i < len(values) else ""
|
| 110 |
-
speaker_id = data["speaker_id"]
|
| 111 |
-
speaker_txt_path = os.path.join(txt_root, speaker_id)
|
| 112 |
-
speaker_wav_path = os.path.join(wav_root, speaker_id)
|
| 113 |
-
# NOTE: p315 does not have text
|
| 114 |
-
if not os.path.exists(speaker_txt_path):
|
| 115 |
-
continue
|
| 116 |
-
for txt_file in sorted(os.listdir(speaker_txt_path)):
|
| 117 |
-
filename, _ = os.path.splitext(txt_file)
|
| 118 |
-
_, text_id = filename.split("_")
|
| 119 |
-
for i in [1, 2]:
|
| 120 |
-
wav_file = os.path.join(speaker_wav_path, f"{filename}_mic{i}.flac")
|
| 121 |
-
# NOTE: p280 does not have mic2 files
|
| 122 |
-
if not os.path.exists(wav_file):
|
| 123 |
-
continue
|
| 124 |
-
with open(os.path.join(speaker_txt_path, txt_file), encoding="utf-8") as text_file:
|
| 125 |
-
text = text_file.readline().strip()
|
| 126 |
-
more_data = {
|
| 127 |
-
"file": wav_file,
|
| 128 |
-
"audio": wav_file,
|
| 129 |
-
"text": text,
|
| 130 |
-
"text_id": text_id,
|
| 131 |
-
}
|
| 132 |
-
yield key, {**data, **more_data}
|
| 133 |
-
key += 1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|