From b468b2f9268cae843cb0c29cd8fc54a8e0e6d8b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleix=20Conchillo=20Flaqu=C3=A9?= Date: Wed, 22 May 2024 13:04:09 -0700 Subject: [PATCH] audio: clamp normalized volume --- src/pipecat/utils/audio.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/pipecat/utils/audio.py b/src/pipecat/utils/audio.py index ad0813ecd..bafccc825 100644 --- a/src/pipecat/utils/audio.py +++ b/src/pipecat/utils/audio.py @@ -13,7 +13,9 @@ def compute_rms(audio: np.ndarray): def normalize_value(value, min_value, max_value): - return (value - min_value) / (max_value - min_value) + normalized = (value - min_value) / (max_value - min_value) + normalized_clamped = max(0, min(1, normalized)) + return normalized_clamped def calculate_audio_volume(audio: bytes, sample_rate: int) -> float: