forked from ga642381/FastSpeech2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvocoder.py
More file actions
executable file
·45 lines (36 loc) · 1.18 KB
/
Copy pathvocoder.py
File metadata and controls
executable file
·45 lines (36 loc) · 1.18 KB
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
import torch
import torch.nn as nn
import torch.nn.functional as F
import numpy as np
import matplotlib
import matplotlib
matplotlib.use("Agg")
from matplotlib import pyplot as plt
from scipy.io import wavfile
import os
import librosa
import text
import hparams as hp
import soundfile
## Vocoders ##
def get_waveglow():
waveglow = torch.hub.load('nvidia/DeepLearningExamples:torchhub', 'nvidia_waveglow')
waveglow = waveglow.remove_weightnorm(waveglow)
waveglow.eval()
for m in waveglow.modules():
if 'Conv' in str(type(m)):
setattr(m, 'padding_mode', 'zeros')
return waveglow
def waveglow_infer(mel, waveglow, path):
with torch.no_grad():
wav = waveglow.infer(mel, sigma=1.0) * hp.max_wav_value
wav = wav.squeeze().cpu().numpy()
soundfile.write(path, wav, hp.sampling_rate)
def get_melgan():
melgan = torch.hub.load('descriptinc/melgan-neurips', 'load_melgan')
return melgan
def melgan_infer(mel, melgan, path):
wav = melgan.inverse(mel).squeeze(0).detach().cpu().numpy()
soundfile.write(path, wav, hp.sampling_rate)
def melgan_infer_batch(mel, melgan):
return melgan.inverse(mel).cpu().numpy()