def make_batch_padded(path, num_layers = 14):
rate, data = wavfile.read(path)
#only use the 1st channel
data = data[:, 0]
data_ = normalize(data)
bins, bins_center = mu_law_bins(256)
inputs = np.digitize(data_[0:-1], bins, right=False)
inputs = bins_center[inputs][None, :, None]
#predict sample 1 to end using 0 to end-1
targets = np.digitize(data_[1::], bins, right=False)[None, :]
base = 2 ** num_layers
_, width, _ = inputs.shape
#crop the width to make it multiple of base
width_cropped = int(np.floor(width * 1.0 / base) * base)
inputs_padded = np.pad(inputs[:, 0:width_cropped, :], ((0, 0), (base - 1, 0), (0, 0)), 'constant')
targets_padded = targets[:, 0:width_cropped]
return (inputs_padded, targets_padded)
评论列表
文章目录