Upload wwTTS.py
Browse files
wwTTS.py
ADDED
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import random
|
3 |
+
import datasets
|
4 |
+
|
5 |
+
|
6 |
+
_DOMAIN = "https://pan.ai-hobbyist.com/d/Wuthering Waves Datasets"
|
7 |
+
|
8 |
+
_URLS = {
|
9 |
+
"zh": "中文 - Chinese",
|
10 |
+
"jp": "日语 - Japanese",
|
11 |
+
"en": "英语 - English",
|
12 |
+
"kr": "韩语 - Korean",
|
13 |
+
}
|
14 |
+
|
15 |
+
|
16 |
+
class wwTTS(datasets.GeneratorBasedBuilder):
|
17 |
+
def _info(self):
|
18 |
+
if self.config.name == "default":
|
19 |
+
self.config.name = "椿"
|
20 |
+
|
21 |
+
return datasets.DatasetInfo(
|
22 |
+
features=datasets.Features(
|
23 |
+
{
|
24 |
+
"speech": datasets.Audio(sampling_rate=44_100),
|
25 |
+
"text": datasets.Value("string"),
|
26 |
+
}
|
27 |
+
),
|
28 |
+
supervised_keys=("speech", "text"),
|
29 |
+
homepage=f"https://www.modelscope.cn/datasets/Genius-Society/{os.path.basename(__file__)[:-3]}",
|
30 |
+
license="CC-BY-NC-ND",
|
31 |
+
version="0.0.1",
|
32 |
+
)
|
33 |
+
|
34 |
+
def _get_txt(self, file_path: str):
|
35 |
+
lab_path = file_path.replace(".wav", ".lab")
|
36 |
+
with open(lab_path, "r", encoding="utf-8") as file:
|
37 |
+
content = file.read()
|
38 |
+
|
39 |
+
return content.strip()
|
40 |
+
|
41 |
+
def _split_generators(self, dl_manager):
|
42 |
+
datasplits = []
|
43 |
+
for region in _URLS:
|
44 |
+
url = f"{_DOMAIN}/{_URLS[region]}/{self.config.name}.7z"
|
45 |
+
try:
|
46 |
+
data_files = dl_manager.download_and_extract(url)
|
47 |
+
except Exception as e:
|
48 |
+
print(f"{e}, retrying...")
|
49 |
+
data_files = dl_manager.download_and_extract(url)
|
50 |
+
|
51 |
+
if os.path.isdir(data_files):
|
52 |
+
files = []
|
53 |
+
for path in dl_manager.iter_files([data_files]):
|
54 |
+
if os.path.basename(path).endswith(".wav"):
|
55 |
+
files.append(
|
56 |
+
{
|
57 |
+
"speech": path,
|
58 |
+
"text": self._get_txt(path),
|
59 |
+
}
|
60 |
+
)
|
61 |
+
|
62 |
+
random.shuffle(files)
|
63 |
+
datasplits.append(
|
64 |
+
datasets.SplitGenerator(
|
65 |
+
name=region,
|
66 |
+
gen_kwargs={"files": files},
|
67 |
+
)
|
68 |
+
)
|
69 |
+
|
70 |
+
return datasplits
|
71 |
+
|
72 |
+
def _generate_examples(self, files):
|
73 |
+
for i, path in enumerate(files):
|
74 |
+
yield i, path
|