-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathcopy_synth_SSRN_GL.py
70 lines (47 loc) · 1.91 KB
/
copy_synth_SSRN_GL.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
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
# -*- coding: utf-8 -*-
# /usr/bin/python2
from __future__ import print_function
import os
import glob
import numpy as np
from utils import spectrogram2wav
from data_load import load_data
import soundfile
from tqdm import tqdm
from configuration import load_config
from argparse import ArgumentParser
from libutil import basename, safe_makedir
from synthesize import synth_mel2mag, list2batch, restore_latest_model_parameters
from architectures import SSRNGraph
import tensorflow as tf
def copy_synth_SSRN_GL(hp, outdir):
safe_makedir(outdir)
dataset = load_data(hp, mode="synthesis")
fnames, texts = dataset['fpaths'], dataset['texts']
bases = [basename(fname) for fname in fnames]
mels = [np.load(os.path.join(hp.coarse_audio_dir, base + '.npy')) for base in bases]
lengths = [a.shape[0] for a in mels]
mels = list2batch(mels, 0)
g = SSRNGraph(hp, mode="synthesize"); print("Graph (ssrn) loaded")
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
ssrn_epoch = restore_latest_model_parameters(sess, hp, 'ssrn')
print('Run SSRN...')
Z = synth_mel2mag(hp, mels, g, sess)
for i, mag in enumerate(Z):
print("Working on %s"%(bases[i]))
mag = mag[:lengths[i]*hp.r,:] ### trim to generated length
wav = spectrogram2wav(hp, mag)
soundfile.write(outdir + "/%s.wav"%(base), wav, hp.sr)
def main_work():
#################################################
# ============= Process command line ============
a = ArgumentParser()
a.add_argument('-c', dest='config', required=True, type=str)
a.add_argument('-o', dest='outdir', required=True, type=str)
opts = a.parse_args()
# ===============================================
hp = load_config(opts.config)
copy_synth_SSRN_GL(hp, opts.outdir)
if __name__=="__main__":
main_work()