add mel sharpen (before soft-gate): restore aspiration detail
Browse files- python/infer_board.py +16 -0
python/infer_board.py
CHANGED
|
@@ -129,6 +129,21 @@ def mel_soft_gate(mel, thr_lo=MEL_GATE_LO, thr_hi=MEL_GATE_HI, floor=-11.5):
|
|
| 129 |
return out
|
| 130 |
|
| 131 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 132 |
def tail_stretch(mel, n_old=TAIL_STRETCH_OLD, n_new=TAIL_STRETCH_NEW):
|
| 133 |
"""句尾 mel 拉伸:最后 n_old 帧线性插值到 n_new 帧。
|
| 134 |
模型对句尾音节 duration 预测偏短(如 11 帧 vs 参考 43 帧),
|
|
@@ -212,6 +227,7 @@ def synthesize(acoustic, vocoder, text, noise_scale=0.3, seed=0):
|
|
| 212 |
for s in sents:
|
| 213 |
x, x_lengths, noise_z = text_to_inputs(s, noise_scale, seed)
|
| 214 |
mel = acoustic_to_mel(acoustic, x, x_lengths, noise_z)
|
|
|
|
| 215 |
mel = mel_soft_gate(mel)
|
| 216 |
mel = tail_stretch(mel)
|
| 217 |
pieces.append(vocoder_chunked(vocoder, mel))
|
|
|
|
| 129 |
return out
|
| 130 |
|
| 131 |
|
| 132 |
+
def mel_sharpen(mel, alpha=0.5, k=5):
|
| 133 |
+
"""Spectral contrast boost along the mel-band axis: m + alpha*(m - smooth(m))."""
|
| 134 |
+
if alpha <= 0 or k <= 1:
|
| 135 |
+
return mel
|
| 136 |
+
m = mel[0] if mel.ndim == 3 else mel
|
| 137 |
+
pad = k // 2
|
| 138 |
+
mp = np.pad(m, ((pad, pad), (0, 0)), mode="reflect")
|
| 139 |
+
smooth = np.zeros_like(m)
|
| 140 |
+
for i in range(k):
|
| 141 |
+
smooth += mp[i:i + m.shape[0]]
|
| 142 |
+
smooth /= k
|
| 143 |
+
sharp = m + alpha * (m - smooth)
|
| 144 |
+
return (sharp if mel.ndim == 2 else sharp[None]).astype(np.float32)
|
| 145 |
+
|
| 146 |
+
|
| 147 |
def tail_stretch(mel, n_old=TAIL_STRETCH_OLD, n_new=TAIL_STRETCH_NEW):
|
| 148 |
"""句尾 mel 拉伸:最后 n_old 帧线性插值到 n_new 帧。
|
| 149 |
模型对句尾音节 duration 预测偏短(如 11 帧 vs 参考 43 帧),
|
|
|
|
| 227 |
for s in sents:
|
| 228 |
x, x_lengths, noise_z = text_to_inputs(s, noise_scale, seed)
|
| 229 |
mel = acoustic_to_mel(acoustic, x, x_lengths, noise_z)
|
| 230 |
+
mel = mel_sharpen(mel)
|
| 231 |
mel = mel_soft_gate(mel)
|
| 232 |
mel = tail_stretch(mel)
|
| 233 |
pieces.append(vocoder_chunked(vocoder, mel))
|