Download dreamvoice/train_utils/src/utils.py from myshell-ai/DreamVoice: direct link, hf CLI and curl.
- Browser
- Download file 1.05 kB
-
https://huggingface.co/myshell-ai/DreamVoice/resolve/main/dreamvoice/train_utils/src/utils.py
- Command line
-
hf download hf://myshell-ai/DreamVoice/dreamvoice/train_utils/src/utils.py
-
curl -L -o utils.py https://huggingface.co/myshell-ai/DreamVoice/resolve/main/dreamvoice/train_utils/src/utils.py
1.05 kB
| 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 |