File size: 2,531 Bytes
27102cb
 
fbab1c4
12ff40f
dea6f80
7ff0400
27102cb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fbab1c4
dea6f80
ab0f7f1
fbab1c4
f61a984
ab0f7f1
2034205
004b0af
dea6f80
7ff0400
dea6f80
004b0af
05205c2
12ff40f
 
27102cb
dea6f80
 
 
 
27102cb
dea6f80
 
27102cb
 
dea6f80
27102cb
dea6f80
12ff40f
dea6f80
 
 
27102cb
 
 
 
 
dea6f80
 
 
 
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
import os
import datasets
logger = datasets.logging.get_logger(__name__)
datasets.logging.set_verbosity(20)


class ParsiGoo(datasets.GeneratorBasedBuilder):
    VERSION = datasets.Version("1.0.0")

    def _info(self):
        features = datasets.Features(
            {
                "text": datasets.Value("string"),
                "audio_file": datasets.Value("string"),
                "speaker_name": datasets.Value("string"),
                "root_path": datasets.Value("string")
            }
        )
        return datasets.DatasetInfo(
            description="ParsiGoo dataset",
            features=features,
            homepage="https://example.com",
            citation="",
        )

    def _split_generators(self, dl_manager):
        logger.info("| >  ")
        print("4544444")
        print(dl_manager.manual_dir)
        # logger.info(os.path.join(os.path.dirname(os.path.abspath(__file__)), "datasets"))
        data_dir = dl_manager.download_and_extract("https://huggingface.co/datasets/Kamtera/ParsiGoo/resolve/main/datasets.zip")
        # data_dir="datasets"
        data_dir = os.path.join(data_dir, "datasets")
        print("| >  data_dir =",data_dir)
        meta_files = []
        speaker_names = os.listdir(data_dir)
        root_path = ""
        print("| >  listdir =",os.listdir(data_dir))
        for speaker_name in os.listdir(data_dir):
            # if not os.path.isdir(os.path.join(data_dir, speaker_name)):
                # continue
            root_path = os.path.join(data_dir, speaker_name)
            meta_files.append(os.path.join(root_path, "metadata.csv"))
 
        return [datasets.SplitGenerator(
                    name="train",
                    gen_kwargs={
                        "txt_files": meta_files,
                        "speaker_names": speaker_names,
                        "root_path": root_path
                    }
                )]

    def _generate_examples(self, txt_files, speaker_names, root_path):
        print(txt_files)
        id=-1
        for ind,txt_file in enumerate(txt_files):
          with open(txt_file, "r", encoding="utf-8") as ttf:
            for i, line in enumerate(ttf):
                cols = line.split("|")
                wav_file = cols[1].strip()
                text = cols[0].strip()
                wav_file = os.path.join(root_path, "wavs", wav_file)
                id+=1
                yield id, {"text": text, "audio_file": wav_file, "speaker_name": speaker_names[ind], "root_path": root_path}