Spaces:
Sleeping
Sleeping
salomonsky
commited on
Commit
路
77da195
1
Parent(s):
6cad661
Update audio.py
Browse files
audio.py
CHANGED
@@ -11,7 +11,6 @@ def load_wav(path, sr):
|
|
11 |
|
12 |
def save_wav(wav, path, sr):
|
13 |
wav *= 32767 / max(0.01, np.max(np.abs(wav)))
|
14 |
-
#proposed by @dsmiller
|
15 |
wavfile.write(path, sr, wav.astype(np.int16))
|
16 |
|
17 |
def save_wavenet_wav(wav, path, sr):
|
@@ -60,7 +59,6 @@ def _stft(y):
|
|
60 |
else:
|
61 |
return librosa.stft(y=y, n_fft=hp.n_fft, hop_length=get_hop_size(), win_length=hp.win_size)
|
62 |
|
63 |
-
##########################################################
|
64 |
#Those are only correct when using lws!!! (This was messing with Wavenet quality for a long time!)
|
65 |
def num_frames(length, fsize, fshift):
|
66 |
"""Compute number of time frames of spectrogram
|
@@ -81,7 +79,7 @@ def pad_lr(x, fsize, fshift):
|
|
81 |
T = len(x) + 2 * pad
|
82 |
r = (M - 1) * fshift + fsize - T
|
83 |
return pad, pad + r
|
84 |
-
|
85 |
#Librosa correct padding
|
86 |
def librosa_pad_lr(x, fsize, fshift):
|
87 |
return 0, (x.shape[0] // fshift + 1) * fshift - x.shape[0]
|
@@ -97,8 +95,7 @@ def _linear_to_mel(spectogram):
|
|
97 |
|
98 |
def _build_mel_basis():
|
99 |
assert hp.fmax <= hp.sample_rate // 2
|
100 |
-
return librosa.filters.mel(hp.sample_rate, hp.n_fft, n_mels=hp.num_mels,
|
101 |
-
fmin=hp.fmin, fmax=hp.fmax)
|
102 |
|
103 |
def _amp_to_db(x):
|
104 |
min_level = np.exp(hp.min_level_db / 20 * np.log(10))
|
@@ -133,4 +130,4 @@ def _denormalize(D):
|
|
133 |
if hp.symmetric_mels:
|
134 |
return (((D + hp.max_abs_value) * -hp.min_level_db / (2 * hp.max_abs_value)) + hp.min_level_db)
|
135 |
else:
|
136 |
-
return ((D * -hp.min_level_db / hp.max_abs_value) + hp.min_level_db)
|
|
|
11 |
|
12 |
def save_wav(wav, path, sr):
|
13 |
wav *= 32767 / max(0.01, np.max(np.abs(wav)))
|
|
|
14 |
wavfile.write(path, sr, wav.astype(np.int16))
|
15 |
|
16 |
def save_wavenet_wav(wav, path, sr):
|
|
|
59 |
else:
|
60 |
return librosa.stft(y=y, n_fft=hp.n_fft, hop_length=get_hop_size(), win_length=hp.win_size)
|
61 |
|
|
|
62 |
#Those are only correct when using lws!!! (This was messing with Wavenet quality for a long time!)
|
63 |
def num_frames(length, fsize, fshift):
|
64 |
"""Compute number of time frames of spectrogram
|
|
|
79 |
T = len(x) + 2 * pad
|
80 |
r = (M - 1) * fshift + fsize - T
|
81 |
return pad, pad + r
|
82 |
+
|
83 |
#Librosa correct padding
|
84 |
def librosa_pad_lr(x, fsize, fshift):
|
85 |
return 0, (x.shape[0] // fshift + 1) * fshift - x.shape[0]
|
|
|
95 |
|
96 |
def _build_mel_basis():
|
97 |
assert hp.fmax <= hp.sample_rate // 2
|
98 |
+
return librosa.filters.mel(sr=hp.sample_rate, n_fft=hp.n_fft, n_mels=hp.num_mels, fmin=hp.fmin, fmax=hp.fmax)
|
|
|
99 |
|
100 |
def _amp_to_db(x):
|
101 |
min_level = np.exp(hp.min_level_db / 20 * np.log(10))
|
|
|
130 |
if hp.symmetric_mels:
|
131 |
return (((D + hp.max_abs_value) * -hp.min_level_db / (2 * hp.max_abs_value)) + hp.min_level_db)
|
132 |
else:
|
133 |
+
return ((D * -hp.min_level_db / hp.max_abs_value) + hp.min_level_db)
|