MCPcopy Create free account
hub / github.com/OpenMOSS/MOSS-TTS / loudness_normalize

Function loudness_normalize

moss_tts_delay/llama_cpp/pipeline.py:55–68  ·  view source on GitHub ↗
(
    wav: np.ndarray,
    target_dbfs: float = -20.0,
    gain_range: tuple[float, float] = (-3.0, 3.0),
)

Source from the content-addressed store, hash-verified

53# ---------------------------------------------------------------------------
54
55def loudness_normalize(
56 wav: np.ndarray,
57 target_dbfs: float = -20.0,
58 gain_range: tuple[float, float] = (-3.0, 3.0),
59) -> np.ndarray:
60 wav = wav.astype(np.float32)
61 if wav.size == 0:
62 return wav
63 rms = np.sqrt(np.mean(wav ** 2) + 1e-9)
64 current_dbfs = 20.0 * np.log10(rms)
65 gain = float(target_dbfs - current_dbfs)
66 gain = max(gain_range[0], min(gain, gain_range[1]))
67 factor = 10.0 ** (gain / 20.0)
68 return wav * factor
69
70
71def _detect_torch() -> bool:

Callers 2

generateMethod · 0.85
_load_reference_wavMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected