context.modules = [
    {   name = libpipewire-module-echo-cancel
        args = {
            # Standard mode: Acts as a virtual sink/source pair
            monitor.mode = false
            library.name = aec/libspa-aec-webrtc
            node.description = "Voice Engine (AEC)"
            
            # 1. The Virtual Sink (Reference)
            # Route your Game/Desktop audio here so it gets cancelled from the mic.
            # It will automatically pass through to your default speakers.
            sink.props = {
                node.name = "voice_engine_reference"
                node.description = "Voice Engine Reference (Sink)"
            }
            
            # 2. The Processed Source (Mic)
            # This is the output of the echo canceller. We feed this into RNNoise below.
            source.props = {
                node.name = "voice_engine_aec_source"
                node.description = "Voice Engine AEC Output"
            }
            
            aec.args = {
                # CRITICAL: Fixes robotic audio by handling clock drift between USB devices
                webrtc.drift_compensation_enabled = true
                
                # We use RNNoise separately for better quality, so disable this
                webrtc.noise_suppression = false
                
                webrtc.voice_detection = true
                webrtc.extended_filter = true
            }
        }
    },
    {   name = libpipewire-module-filter-chain
        args = {
            node.description = "Voice Engine (Final)"
            media.name = "Voice Engine (Final)"
            
            filter.graph = {
                nodes = [
                    {
                        type = ladspa
                        name = rnnoise
                        plugin = "/usr/lib/ladspa/librnnoise_ladspa.so"
                        label = noise_suppressor_mono
                        control = {
                            "VAD Threshold (%)" = 50.0
                            "VAD Grace Period (ms)" = 200
                            "Retroactive VAD Grace (ms)" = 20
                        }
                    }
                ]
            }
            
            # Automatically grabs the output from the AEC module above
            capture.props = {
                node.name = "voice_engine_rnnoise_in"
                node.passive = true
                "target.object" = "voice_engine_aec_source"
            }
            
            # This is the FINAL device you select in Discord/Zoom/etc.
            playback.props = {
                node.name = "voice_engine_final"
                node.description = "Voice Engine (Final)"
                media.class = "Audio/Source"
            }
        }
    }
]