Reconstruction propre de l'ancien projet Dictée. Bundle id neuf (cloud.mrtechlab.zonza), chemin de build unique vers /Applications (plus jamais de builds /tmp enregistrés dans LaunchServices). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
57 lines
1.5 KiB
Python
57 lines
1.5 KiB
Python
import numpy as np
|
|
|
|
from audio_level import compute_rms, shape_level
|
|
|
|
|
|
def test_silence_is_zero():
|
|
frames = np.zeros(1000, dtype="float32")
|
|
assert compute_rms(frames) == 0.0
|
|
|
|
|
|
def test_empty_is_zero():
|
|
frames = np.zeros(0, dtype="float32")
|
|
assert compute_rms(frames) == 0.0
|
|
|
|
|
|
def test_full_scale_is_one():
|
|
# signal constant à l'amplitude max → RMS normalisé proche de 1.0
|
|
frames = np.ones(1000, dtype="float32")
|
|
assert compute_rms(frames) == 1.0
|
|
|
|
|
|
def test_result_is_bounded():
|
|
# même un signal qui dépasse [-1, 1] reste borné à 1.0
|
|
frames = np.full(1000, 5.0, dtype="float32")
|
|
level = compute_rms(frames)
|
|
assert 0.0 <= level <= 1.0
|
|
|
|
|
|
def test_louder_gives_higher_level():
|
|
quiet = np.full(1000, 0.1, dtype="float32")
|
|
loud = np.full(1000, 0.5, dtype="float32")
|
|
assert compute_rms(loud) > compute_rms(quiet)
|
|
|
|
|
|
def test_shape_level_zero_stays_zero():
|
|
assert shape_level(0.0, gain=8.0) == 0.0
|
|
|
|
|
|
def test_shape_level_boosts_quiet_voice():
|
|
# un RMS vocal typique (~0.05) doit devenir nettement perceptible après mise en forme
|
|
shaped = shape_level(0.05, gain=8.0)
|
|
assert shaped > 0.3
|
|
|
|
|
|
def test_shape_level_is_bounded():
|
|
# un niveau déjà fort reste borné à 1.0 (pas de débordement)
|
|
assert shape_level(0.9, gain=8.0) == 1.0
|
|
|
|
|
|
def test_shape_level_monotonic():
|
|
assert shape_level(0.2, gain=8.0) > shape_level(0.05, gain=8.0)
|
|
|
|
|
|
def test_shape_level_gain_zero_is_zero():
|
|
# gain nul → aucune réaction
|
|
assert shape_level(0.5, gain=0.0) == 0.0
|