forked from ming024/FastSpeech2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
preprocess.py
37 lines (33 loc) · 1.31 KB
/
preprocess.py
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
import os
from data import ljspeech, blizzard2013
import hparams as hp
def write_metadata(train, val, out_dir):
with open(os.path.join(out_dir, 'train.txt'), 'w', encoding='utf-8') as f:
for m in train:
f.write(m + '\n')
with open(os.path.join(out_dir, 'val.txt'), 'w', encoding='utf-8') as f:
for m in val:
f.write(m + '\n')
def main():
in_dir = hp.data_path
out_dir = hp.preprocessed_path
mel_out_dir = os.path.join(out_dir, "mel")
if not os.path.exists(mel_out_dir):
os.makedirs(mel_out_dir, exist_ok=True)
ali_out_dir = os.path.join(out_dir, "alignment")
if not os.path.exists(ali_out_dir):
os.makedirs(ali_out_dir, exist_ok=True)
f0_out_dir = os.path.join(out_dir, "f0")
if not os.path.exists(f0_out_dir):
os.makedirs(f0_out_dir, exist_ok=True)
energy_out_dir = os.path.join(out_dir, "energy")
if not os.path.exists(energy_out_dir):
os.makedirs(energy_out_dir, exist_ok=True)
if hp.dataset == "LJSpeech":
train, val = ljspeech.build_from_path(in_dir, out_dir)
if hp.dataset == "Blizzard2013":
train, val = blizzard2013.build_from_path(in_dir, out_dir)
train,val = ljspeech.build_from_path(in_dir, out_dir)
write_metadata(train, val, out_dir)
if __name__ == "__main__":
main()