diff --git a/macloop/_macloop.pyi b/macloop/_macloop.pyi index 5db45e5..2afd1d9 100644 --- a/macloop/_macloop.pyi +++ b/macloop/_macloop.pyi @@ -20,13 +20,13 @@ class AudioProcessingConfig: def __init__( self, - sample_rate: int = 16000, - channels: int = 1, - enable_aec: bool = True, - enable_ns: bool = True, + sample_rate: int = 48000, + channels: int = 2, + enable_aec: bool = False, + enable_ns: bool = False, sample_format: str = "f32", aec_stream_delay_ms: int = 0, - aec_auto_delay_tuning: bool = True, + aec_auto_delay_tuning: bool = False, aec_max_delay_ms: int = 140, ) -> None: ... diff --git a/src/config.rs b/src/config.rs index 1db0b9a..ca8af88 100644 --- a/src/config.rs +++ b/src/config.rs @@ -25,13 +25,13 @@ pub struct AudioProcessingConfig { impl AudioProcessingConfig { #[new] #[pyo3(signature = ( - sample_rate=16000, - channels=1, - enable_aec=true, - enable_ns=true, + sample_rate=48000, + channels=2, + enable_aec=false, + enable_ns=false, sample_format="f32".to_string(), aec_stream_delay_ms=0, - aec_auto_delay_tuning=true, + aec_auto_delay_tuning=false, aec_max_delay_ms=140 ))] fn new( diff --git a/src/lib.rs b/src/lib.rs index 4ed2b44..e47fba1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -72,13 +72,13 @@ impl AudioEngine { let config = config.unwrap_or_else(|| { config::AudioProcessingConfig { - sample_rate: 16000, - channels: 1, - enable_aec: true, - enable_ns: true, + sample_rate: 48000, + channels: 2, + enable_aec: false, + enable_ns: false, sample_format: "f32".to_string(), aec_stream_delay_ms: 0, - aec_auto_delay_tuning: true, + aec_auto_delay_tuning: false, aec_max_delay_ms: 140, } }); diff --git a/tests/test_config_defaults.py b/tests/test_config_defaults.py new file mode 100644 index 0000000..959a384 --- /dev/null +++ b/tests/test_config_defaults.py @@ -0,0 +1,49 @@ +from __future__ import annotations + +import re +from pathlib import Path + +from macloop._macloop import AudioProcessingConfig + + +def _pyi_defaults() -> dict[str, object]: + pyi_path = Path(__file__).resolve().parents[1] / "macloop" / "_macloop.pyi" + text = pyi_path.read_text(encoding="utf-8") + + patterns = { + "sample_rate": r"sample_rate:\s*int\s*=\s*(\d+)", + "channels": r"channels:\s*int\s*=\s*(\d+)", + "enable_aec": r"enable_aec:\s*bool\s*=\s*(True|False)", + "enable_ns": r"enable_ns:\s*bool\s*=\s*(True|False)", + "sample_format": r"sample_format:\s*str\s*=\s*\"([^\"]+)\"", + "aec_stream_delay_ms": r"aec_stream_delay_ms:\s*int\s*=\s*(-?\d+)", + "aec_auto_delay_tuning": r"aec_auto_delay_tuning:\s*bool\s*=\s*(True|False)", + "aec_max_delay_ms": r"aec_max_delay_ms:\s*int\s*=\s*(\d+)", + } + + result: dict[str, object] = {} + for key, pattern in patterns.items(): + match = re.search(pattern, text) + assert match is not None, f"Could not find default for {key} in _macloop.pyi" + raw = match.group(1) + if raw in {"True", "False"}: + result[key] = raw == "True" + elif key == "sample_format": + result[key] = raw + else: + result[key] = int(raw) + return result + + +def test_audio_processing_config_defaults_match_pyi_and_runtime() -> None: + pyi = _pyi_defaults() + runtime = AudioProcessingConfig() + + assert runtime.sample_rate == pyi["sample_rate"] + assert runtime.channels == pyi["channels"] + assert runtime.enable_aec == pyi["enable_aec"] + assert runtime.enable_ns == pyi["enable_ns"] + assert runtime.sample_format == pyi["sample_format"] + assert runtime.aec_stream_delay_ms == pyi["aec_stream_delay_ms"] + assert runtime.aec_auto_delay_tuning == pyi["aec_auto_delay_tuning"] + assert runtime.aec_max_delay_ms == pyi["aec_max_delay_ms"]