Kamtera commited on
Commit
27102cb
·
1 Parent(s): 9168540

Upload ParsiGoo.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. ParsiGoo.py +50 -0
ParsiGoo.py ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import datasets
3
+
4
+ class ParsiGoo(datasets.GeneratorBasedBuilder):
5
+ VERSION = datasets.Version("1.0.0")
6
+
7
+ def _info(self):
8
+ features = datasets.Features(
9
+ {
10
+ "text": datasets.Value("string"),
11
+ "audio_file": datasets.Value("string"),
12
+ "speaker_name": datasets.Value("string"),
13
+ "root_path": datasets.Value("string")
14
+ }
15
+ )
16
+ return datasets.DatasetInfo(
17
+ description="ParsiGoo dataset",
18
+ features=features,
19
+ homepage="https://example.com",
20
+ citation="",
21
+ )
22
+
23
+ def _split_generators(self, dl_manager):
24
+ data_dir = "datasets"#dl_manager.download_and_extract("https://example.com/datasets/parsigoo.zip")
25
+ splits = []
26
+ for speaker_name in os.listdir(data_dir):
27
+ if not os.path.isdir(os.path.join(data_dir, speaker_name)):
28
+ continue
29
+ root_path = os.path.join(data_dir, speaker_name)
30
+ meta_file = os.path.join(root_path, "metadata.csv")
31
+ splits.append(
32
+ datasets.SplitGenerator(
33
+ name=speaker_name,
34
+ gen_kwargs={
35
+ "txt_file": meta_file,
36
+ "speaker_name": speaker_name,
37
+ "root_path": root_path
38
+ }
39
+ )
40
+ )
41
+ return splits
42
+
43
+ def _generate_examples(self, txt_file, speaker_name, root_path):
44
+ with open(txt_file, "r", encoding="utf-8") as ttf:
45
+ for i, line in enumerate(ttf):
46
+ cols = line.split("|")
47
+ wav_file = cols[1].strip()
48
+ text = cols[0].strip()
49
+ wav_file = os.path.join(root_path, "wavs", wav_file)
50
+ yield i, {"text": text, "audio_file": wav_file, "speaker_name": speaker_name, "root_path": root_path}