fixed crash if audio volume has wrong type

This commit is contained in:
DJ2LS 2022-11-29 08:45:14 +01:00
parent 1c00fcd13b
commit 65cab5fa3c

View file

@ -1014,6 +1014,13 @@ def set_audio_volume(datalist, volume: float) -> np.int16:
:return: Scaled audio samples
:rtype: np.int16
"""
# make sure we have float as data type to avoid crash
try:
volume = float(volume)
except Exception as e:
print(f"[MDM] changing audio volume failed with error: {e}")
volume = 100.0
# Clip volume provided to acceptable values
volume = np.clip(volume, 0, 200) # limit to max value of 255
# Scale samples by the ratio of volume / 100.0