File size: 1,050 Bytes
bd3a23c 0dabde8 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
import numpy as np
import matplotlib.pyplot as plt
from scipy.io import wavfile
import torch
def minmax_norm_diff(tensor: torch.Tensor, vmax: float = 2.5, vmin: float = -12) -> torch.Tensor:
tensor = torch.clip(tensor, vmin, vmax)
tensor = 2 * (tensor - vmin) / (vmax - vmin) - 1
return tensor
def reverse_minmax_norm_diff(tensor: torch.Tensor, vmax: float = 2.5, vmin: float = -12) -> torch.Tensor:
tensor = torch.clip(tensor, -1.0, 1.0)
tensor = (tensor + 1) / 2
tensor = tensor * (vmax - vmin) + vmin
return tensor
def scale_shift(x, scale, shift):
return (x+shift) * scale
def scale_shift_re(x, scale, shift):
return (x/scale) - shift
def align_seq(source, target_length, mapping_method='hard'):
source_len = source.shape[1]
if mapping_method == 'hard':
mapping_idx = np.round(np.arange(target_length) * source_len / target_length)
output = source[:, mapping_idx]
else:
# TBD
raise NotImplementedError
return output |