-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathtest.py
34 lines (27 loc) · 1.23 KB
/
test.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
# encoding: utf-8
from utils import audio
from hparams import hparams
import numpy as np
from griffin_lim import inv_spectrogram, tf
import os
if __name__ == '__main__':
data_foler = "data"
wavs = [os.path.join(data_foler, file[:-4]) for file in os.listdir(data_foler) if file.endswith(".wav")]
outputs_py = [file + ".py.gen.wav" for file in wavs]
outputs_tf = [file + ".tf.gen.wav" for file in wavs]
wavs = [audio.load_wav(wav_path + ".wav", hparams.sample_rate) for wav_path in wavs]
spectrogram = [audio.spectrogram(wav).astype(np.float32) for wav in wavs]
print("Linear spectrograms dim: ")
print(spectrogram[0].shape)
# --------------------------------- librosa Version ---------------------------------
# convert back
gens = [audio.inv_spectrogram(s) for s in spectrogram]
for gen, output in zip(gens, outputs_py):
audio.save_wav(gen, output)
# --------------------------------- TensorFlow Version ---------------------------------
samples = [inv_spectrogram(spec) for spec in spectrogram]
with tf.Session() as sess:
samples = [sess.run(sample) for sample in samples]
for gen, output in zip(samples, outputs_tf):
audio.save_wav(gen, output)
print("Done!")