@@ -262,6 +262,7 @@ def __init__(
262262 self ._channels = num_channels
263263 self ._blocksize = blocksize
264264 self ._delay_estimator : Optional [_APMDelayEstimator ] = None
265+ self ._apm : Optional [AudioProcessingModule ] = None
265266
266267 # Device enumeration
267268 def list_input_devices (self ) -> list [dict [str , Any ]]:
@@ -314,9 +315,9 @@ def open_input(
314315 an `AudioProcessingModule` is created and applied to each frame before it
315316 is queued for `AudioSource.capture_frame`.
316317
317- To enable AEC end-to-end, pass the returned `apm` to
318- `open_output(apm_for_reverse=...)` and route remote audio through
319- that player so reverse frames are provided to APM .
318+ To enable AEC end-to-end, call `open_output()` after opening the input
319+ device. The output player will automatically use the input's APM for
320+ reverse stream processing, enabling echo cancellation .
320321
321322 Args:
322323 enable_aec: Enable acoustic echo cancellation.
@@ -344,8 +345,9 @@ def open_input(
344345 delay_estimator : Optional [_APMDelayEstimator ] = (
345346 _APMDelayEstimator () if apm is not None else None
346347 )
347- # Store the shared estimator on the device helper so the output player can reuse it
348+ # Store the shared estimator and APM on the device helper so the output player can reuse them
348349 self ._delay_estimator = delay_estimator
350+ self ._apm = apm
349351
350352 # Queue from callback to async task
351353 q : asyncio .Queue [AudioFrame ] = asyncio .Queue (maxsize = queue_capacity )
@@ -432,20 +434,21 @@ async def _pump() -> None:
432434 def open_output (
433435 self ,
434436 * ,
435- apm_for_reverse : Optional [AudioProcessingModule ] = None ,
436437 output_device : Optional [int ] = None ,
437438 ) -> OutputPlayer :
438439 """Create an `OutputPlayer` for rendering and (optionally) AEC reverse.
439440
441+ If an input device was opened with AEC enabled, the output player will
442+ automatically feed the APM's reverse stream for echo cancellation.
443+
440444 Args:
441- apm_for_reverse: Pass the APM used by the audio input device to enable AEC.
442445 output_device: Optional output device index (default system device if None).
443446 """
444447 return OutputPlayer (
445448 sample_rate = self ._out_sr ,
446449 num_channels = self ._channels ,
447450 blocksize = self ._blocksize ,
448- apm_for_reverse = apm_for_reverse ,
451+ apm_for_reverse = self . _apm ,
449452 output_device = output_device ,
450453 delay_estimator = self ._delay_estimator ,
451454 )
0 commit comments