Fork of https://github.com/alokprasad/fastspeech_squeezewave to also fix denoising in squeezewave
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
1.3 KiB

  1. import torch
  2. from librosa.filters import mel as librosa_mel_fn
  3. class LinearNorm(torch.nn.Module):
  4. def __init__(self, in_dim, out_dim, bias=True, w_init_gain='linear'):
  5. super(LinearNorm, self).__init__()
  6. self.linear_layer = torch.nn.Linear(in_dim, out_dim, bias=bias)
  7. torch.nn.init.xavier_uniform_(
  8. self.linear_layer.weight,
  9. gain=torch.nn.init.calculate_gain(w_init_gain))
  10. def forward(self, x):
  11. return self.linear_layer(x)
  12. class ConvNorm(torch.nn.Module):
  13. def __init__(self, in_channels, out_channels, kernel_size=1, stride=1,
  14. padding=None, dilation=1, bias=True, w_init_gain='linear'):
  15. super(ConvNorm, self).__init__()
  16. if padding is None:
  17. assert(kernel_size % 2 == 1)
  18. padding = int(dilation * (kernel_size - 1) / 2)
  19. self.conv = torch.nn.Conv1d(in_channels, out_channels,
  20. kernel_size=kernel_size, stride=stride,
  21. padding=padding, dilation=dilation,
  22. bias=bias)
  23. torch.nn.init.xavier_uniform_(
  24. self.conv.weight, gain=torch.nn.init.calculate_gain(w_init_gain))
  25. def forward(self, signal):
  26. conv_signal = self.conv(signal)
  27. return conv_signal