Here is my code to synthesize audio from mel spectrogram
pad_fn = torch.nn.ReplicationPad1d(self.config_gan[“generator_params”].get(“aux_context_window”, 0)).to(torch.device(“cuda”))
#Generative
with torch.no_grad():
c = self.scaler.transform(mels[0])
x = ()
z = torch.randn(1, 1, len(c ) * self.config_gan[“hop_size”]).to(torch.device(“cuda”))
x += (z,)
b = torch.from_numpy(c ).unsqueeze(0).transpose(2, 1).to(torch.device(“cuda”))
c = pad_fn(b)
x += (c,)
y = self.model_gan(*x).view(-1).cpu().numpy()
y = y[:len(y)-3000]
del z
torch.cuda.empty_cache()
del b
torch.cuda.empty_cache()
del c
torch.cuda.empty_cache()
out = io.BytesIO()
audio.save_wav(y, out, sr=hparams.sample_rate)
del y
torch.cuda.empty_cache()
del pad_fn
torch.cuda.empty_cache()
gc.collect()
with open(‘fmemory.txt’, ‘a’) as f:
f.writelines(‘del all ’ + str(torch.cuda.memory_allocated()/10242)+"\n") #5.27490234375
f.writelines(str(torch.cuda.memory_cached()/10242) +’\n’) #6.0
self.model_gan.remove_weight_norm()
return out.getvalue()