Spaces:
Running
Running
"""Utilities""" | |
import numpy as np | |
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 | |