TTS/utils/data.py

22 lines
547 B
Python
Raw Normal View History

2018-01-22 09:48:59 +00:00
import numpy as np
2018-03-27 16:21:53 +00:00
def pad_data(x, length):
2018-01-22 09:48:59 +00:00
_pad = 0
assert x.ndim == 1
return np.pad(x, (0, length - x.shape[0]),
mode='constant',
constant_values=_pad)
2018-01-22 09:48:59 +00:00
def prepare_data(inputs):
max_len = max((len(x) for x in inputs))
2018-03-27 16:21:53 +00:00
return np.stack([pad_data(x, max_len) for x in inputs])
2018-03-22 19:34:16 +00:00
2018-02-13 09:45:52 +00:00
def pad_per_step(inputs, pad_len):
2018-01-22 09:48:59 +00:00
timesteps = inputs.shape[-1]
return np.pad(inputs, [[0, 0], [0, 0],
2018-02-13 09:45:52 +00:00
[0, pad_len]],
2018-01-22 09:48:59 +00:00
mode='constant', constant_values=0.0)