|
|
@ -14,9 +14,8 @@ class TextMelLoader(torch.utils.data.Dataset): |
|
|
|
2) normalizes text and converts them to sequences of one-hot vectors |
|
|
|
3) computes mel-spectrograms from audio files. |
|
|
|
""" |
|
|
|
def __init__(self, audiopaths_and_text, hparams, shuffle=True): |
|
|
|
self.audiopaths_and_text = load_filepaths_and_text( |
|
|
|
audiopaths_and_text, hparams.sort_by_length) |
|
|
|
def __init__(self, audiopaths_and_text, hparams): |
|
|
|
self.audiopaths_and_text = load_filepaths_and_text(audiopaths_and_text) |
|
|
|
self.text_cleaners = hparams.text_cleaners |
|
|
|
self.max_wav_value = hparams.max_wav_value |
|
|
|
self.sampling_rate = hparams.sampling_rate |
|
|
@ -26,8 +25,7 @@ class TextMelLoader(torch.utils.data.Dataset): |
|
|
|
hparams.n_mel_channels, hparams.sampling_rate, hparams.mel_fmin, |
|
|
|
hparams.mel_fmax) |
|
|
|
random.seed(1234) |
|
|
|
if shuffle: |
|
|
|
random.shuffle(self.audiopaths_and_text) |
|
|
|
random.shuffle(self.audiopaths_and_text) |
|
|
|
|
|
|
|
def get_mel_text_pair(self, audiopath_and_text): |
|
|
|
# separate filename and text |
|
|
@ -38,7 +36,10 @@ class TextMelLoader(torch.utils.data.Dataset): |
|
|
|
|
|
|
|
def get_mel(self, filename): |
|
|
|
if not self.load_mel_from_disk: |
|
|
|
audio = load_wav_to_torch(filename, self.sampling_rate) |
|
|
|
audio, sampling_rate = load_wav_to_torch(filename) |
|
|
|
if sampling_rate != self.stft.sampling_rate: |
|
|
|
raise ValueError("{} {} SR doesn't match target {} SR".format( |
|
|
|
sampling_rate, self.stft.sampling_rate)) |
|
|
|
audio_norm = audio / self.max_wav_value |
|
|
|
audio_norm = audio_norm.unsqueeze(0) |
|
|
|
audio_norm = torch.autograd.Variable(audio_norm, requires_grad=False) |
|
|
@ -87,9 +88,9 @@ class TextMelCollate(): |
|
|
|
text = batch[ids_sorted_decreasing[i]][0] |
|
|
|
text_padded[i, :text.size(0)] = text |
|
|
|
|
|
|
|
# Right zero-pad mel-spec with extra single zero vector to mark the end |
|
|
|
# Right zero-pad mel-spec |
|
|
|
num_mels = batch[0][1].size(0) |
|
|
|
max_target_len = max([x[1].size(1) for x in batch]) + 1 |
|
|
|
max_target_len = max([x[1].size(1) for x in batch]) |
|
|
|
if max_target_len % self.n_frames_per_step != 0: |
|
|
|
max_target_len += self.n_frames_per_step - max_target_len % self.n_frames_per_step |
|
|
|
assert max_target_len % self.n_frames_per_step == 0 |
|
|
@ -103,7 +104,7 @@ class TextMelCollate(): |
|
|
|
for i in range(len(ids_sorted_decreasing)): |
|
|
|
mel = batch[ids_sorted_decreasing[i]][1] |
|
|
|
mel_padded[i, :, :mel.size(1)] = mel |
|
|
|
gate_padded[i, mel.size(1):] = 1 |
|
|
|
gate_padded[i, mel.size(1)-1:] = 1 |
|
|
|
output_lengths[i] = mel.size(1) |
|
|
|
|
|
|
|
return text_padded, input_lengths, mel_padded, gate_padded, \ |
|
|
|