Datasets:

License:
File size: 2,578 Bytes
ac33116
 
 
 
 
 
 
 
5883636
 
 
 
 
 
 
 
ac33116
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5883636
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
import os
import random
import datasets


_DOMAIN = "https://pan.ai-hobbyist.com"

_URLS = {
    "genshin_zh": "Genshin Datasets/中文",
    "genshin_jp": "Genshin Datasets/日语",
    "genshin_en": "Genshin Datasets/英语",
    "genshin_kr": "Genshin Datasets/韩语",
    "starail_zh": "StarRail Datasets/分角色包/中文",
    "starail_jp": "StarRail Datasets/分角色包/日语",
    "starail_en": "StarRail Datasets/分角色包/英语",
    "starail_kr": "StarRail Datasets/分角色包/韩语",
}


class hoyoTTS(datasets.GeneratorBasedBuilder):
    def _info(self):
        if self.config.name == "default":
            self.config.name = "黑塔"

        return datasets.DatasetInfo(
            features=datasets.Features(
                {
                    "speech": datasets.Audio(sampling_rate=44_100),
                    "text": datasets.Value("string"),
                }
            ),
            supervised_keys=("speech", "text"),
            homepage=f"https://www.modelscope.cn/datasets/Genius-Society/{os.path.basename(__file__)[:-3]}",
            license="CC-BY-NC-ND",
            version="0.0.1",
        )

    def _get_txt(self, file_path: str):
        lab_path = file_path.replace(".wav", ".lab")
        with open(lab_path, "r", encoding="utf-8") as file:
            content = file.read()

        return content.strip()

    def _split_generators(self, dl_manager):
        datasplits = []
        for region in _URLS:
            url = f"{_DOMAIN}/d/{_URLS[region]}/{self.config.name}.7z"
            try:
                data_files = dl_manager.download_and_extract(url)
            except Exception as e:
                print(f"{e}, retrying...")
                data_files = dl_manager.download_and_extract(url)

            if os.path.isdir(data_files):
                files = []
                for path in dl_manager.iter_files([data_files]):
                    if os.path.basename(path).endswith(".wav"):
                        files.append(
                            {
                                "speech": path,
                                "text": self._get_txt(path),
                            }
                        )

                random.shuffle(files)
                datasplits.append(
                    datasets.SplitGenerator(
                        name=region,
                        gen_kwargs={"files": files},
                    )
                )

        return datasplits

    def _generate_examples(self, files):
        for i, path in enumerate(files):
            yield i, path