mirror of https://github.com/rhasspy/piper
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
17 lines
491 B
Python
17 lines
491 B
Python
import numpy as np
|
|
import torch
|
|
|
|
|
|
def to_gpu(x: torch.Tensor) -> torch.Tensor:
|
|
return x.contiguous().cuda(non_blocking=True)
|
|
|
|
|
|
def audio_float_to_int16(
|
|
audio: np.ndarray, max_wav_value: float = 32767.0
|
|
) -> np.ndarray:
|
|
"""Normalize audio and convert to int16 range"""
|
|
audio_norm = audio * (max_wav_value / max(0.01, np.max(np.abs(audio))))
|
|
audio_norm = np.clip(audio_norm, -max_wav_value, max_wav_value)
|
|
audio_norm = audio_norm.astype("int16")
|
|
return audio_norm
|