44 lines
1.2 KiB
Python
44 lines
1.2 KiB
Python
|
|
"""
|
|
This modules contains normalizers for spectrogram magnitude.
|
|
Normalizers are invertible transformations. They can be used to process
|
|
magnitude of spectrogram before training and can also be used to recover from
|
|
the generated spectrogram so as to be used with vocoders like griffin lim.
|
|
|
|
The base class describe the interface. `transform` is used to perform
|
|
transformation and `inverse` is used to perform the inverse transformation.
|
|
|
|
check issues:
|
|
https://github.com/mozilla/TTS/issues/377
|
|
"""
|
|
import numpy as np
|
|
|
|
class NormalizerBase(object):
|
|
def transform(self, spec):
|
|
raise NotImplementedError("transform must be implemented")
|
|
|
|
def inverse(self, normalized):
|
|
raise NotImplementedError("inverse must be implemented")
|
|
|
|
class LogMagnitude(NormalizerBase):
|
|
"""
|
|
This is a simple normalizer used in Waveglow, Waveflow, tacotron2...
|
|
"""
|
|
def __init__(self, min=1e-7):
|
|
self.min = min
|
|
|
|
def transform(self, x):
|
|
x = np.maximum(x, self.min)
|
|
x = np.log(x)
|
|
return x
|
|
|
|
def inverse(self, x):
|
|
return np.exp(x)
|
|
|
|
|
|
class UnitMagnitude(NormalizerBase):
|
|
# dbscale and (0, 1) normalization
|
|
"""
|
|
This is the normalizer used in the
|
|
"""
|
|
pass |