forked from dome272/Diffusion-Models-pytorch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathepoch_testing.py
36 lines (26 loc) · 892 Bytes
/
epoch_testing.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
import librosa
import librosa.display
import matplotlib.pyplot as plt
import numpy as np
import soundfile as sf
import data_transformation.audio_utils as utils
# M_db = utils.load_and_convert_to_db(, n_mels=128, time_steps=512)
with open("S:/Code/_Uni/Diffusion-Spectrograms/results/DDPM_Uncondtional/7.npy", 'rb') as f:
test = np.load(f)
M_db = []
# convert back to db
for idx in range(0, len(test)):
M_db.append([])
for r, g, b in test[idx]:
M_db[idx].append(r * 80 - 80)
M_db = np.array(M_db)
fig = plt.figure()
fig.set_size_inches(128 / 100, 128 / 100, forward=False)
ax = plt.Axes(fig, [0., 0., 1., 1.])
ax.set_axis_off()
fig.add_axes(ax)
librosa.display.specshow(M_db, ax=ax, cmap='Greys_r')
plt.show()
M = librosa.db_to_power(M_db)
audio = librosa.feature.inverse.mel_to_audio(M, sr=44100, hop_length=1023)
sf.write("result_7.wav", audio, 44100, "PCM_16")