Exemplo n.º 1
0
def test_preemphasis():
    for dtype in [np.float32, np.float64]:
        np.random.seed(1234)
        x = np.random.rand(16000 * 5).astype(dtype)
        y = preemphasis(x, 0.97)
        assert x.shape == y.shape
        assert x.dtype == y.dtype
        x_hat = inv_preemphasis(y, 0.97)
        assert x_hat.dtype == x.dtype
        assert np.allclose(x_hat, x, atol=1e-5)

    x = np.random.rand(16000)
    assert np.allclose(P.preemphasis(x, 0), x)
    assert np.allclose(P.inv_preemphasis(P.preemphasis(x, 0), 0), x)
Exemplo n.º 2
0
def inv_spectrogram(spectrogram):
    '''Converts spectrogram to waveform using librosa'''
    S = _db_to_amp(_denormalize(spectrogram) + hparams.ref_level_db)  # Convert back to linear
    processor = _lws_processor()
    D = processor.run_lws(S.astype(np.float64).T ** hparams.power)
    y = processor.istft(D).astype(np.float32)
    return inv_preemphasis(y)
Exemplo n.º 3
0
def inv_preemphasis(x):
    # allow disable preemphasis
    if hparams.preemphasis == -1.0:
        return x
    else:
        from nnmnkwii.preprocessing import inv_preemphasis
        return inv_preemphasis(x, hparams.preemphasis)
Exemplo n.º 4
0
def inv_mel_spectrogram(mel_spectrogram):
    D = _denormalize(mel_spectrogram)
    S = _mel_to_linear(
        _db_to_amp(D + hparams.ref_level_db))  # Convert back to linear
    processor = _lws_processor()
    D = processor.run_lws(S.astype(np.float64).T**hparams.power)
    y = processor.istft(D).astype(np.float32)
    return inv_preemphasis(y)
Exemplo n.º 5
0
def inv_spectrogram(spectrogram):
    '''Converts spectrogram to waveform using librosa'''
    S = _db_to_amp(_denormalize(spectrogram) +
                   hparams.spec_ref_level_db)  # Convert back to linear
    #S = librosa.db_to_amplitude(_denormalize(spectrogram) + hparams.spec_ref_level_db)
    D = librosa.griffinlim(S**hparams.power,
                           hop_length=hparams.hop_size,
                           win_length=hparams.fft_wsize)
    return inv_preemphasis(D)
Exemplo n.º 6
0
def inv_preemphasis(x):
    from nnmnkwii.preprocessing import inv_preemphasis
    return inv_preemphasis(x, hparams.preemphasis)
Exemplo n.º 7
0
def inv_preemphasis(x, coef=0.85):
    return P.inv_preemphasis(x, coef)
Exemplo n.º 8
0
 def _inv_preemphasis(self, x):
     from nnmnkwii.preprocessing import inv_preemphasis
     return inv_preemphasis(x, self.hparams.preemphasis)
Exemplo n.º 9
0
def inv_preemphasis(x):
    from nnmnkwii.preprocessing import inv_preemphasis
    return inv_preemphasis(x, preemphasis_factor)