77
88
99class AudioProcessingModule :
10+ """
11+ Provides WebRTC audio processing capabilities including echo cancellation, noise suppression,
12+ high-pass filtering, and gain control.
13+ """
14+
1015 def __init__ (
1116 self ,
1217 * ,
@@ -15,6 +20,15 @@ def __init__(
1520 high_pass_filter_enabled : bool = False ,
1621 gain_controller_enabled : bool = False ,
1722 ) -> None :
23+ """
24+ Initialize an AudioProcessingModule instance with the specified audio processing features.
25+
26+ Args:
27+ echo_canceller_enabled (bool, optional): Whether to enable echo cancellation.
28+ noise_suppression_enabled (bool, optional): Whether to enable noise suppression.
29+ high_pass_filter_enabled (bool, optional): Whether to enable a high-pass filter.
30+ gain_controller_enabled (bool, optional): Whether to enable a gain controller.
31+ """
1832 req = proto_ffi .FfiRequest ()
1933 req .new_apm .echo_canceller_enabled = echo_canceller_enabled
2034 req .new_apm .noise_suppression_enabled = noise_suppression_enabled
@@ -25,6 +39,15 @@ def __init__(
2539 self ._ffi_handle = FfiHandle (resp .new_apm .apm .handle .id )
2640
2741 def process_stream (self , data : AudioFrame ) -> None :
42+ """
43+ Process the provided audio frame using the configured audio processing features.
44+
45+ The input audio frame is modified in-place (if applicable) by the underlying audio
46+ processing module (e.g., echo cancellation, noise suppression, etc.).
47+
48+ Important:
49+ Audio frames must be exactly 10 ms in duration.
50+ """
2851 bdata = data .data .cast ("b" )
2952
3053 req = proto_ffi .FfiRequest ()
@@ -37,9 +60,19 @@ def process_stream(self, data: AudioFrame) -> None:
3760 resp = FfiClient .instance .request (req )
3861
3962 if resp .apm_process_stream .error :
40- raise Exception (resp .apm_process_stream .error )
63+ raise RuntimeError (resp .apm_process_stream .error )
4164
4265 def process_reverse_stream (self , data : AudioFrame ) -> None :
66+ """
67+ Process the reverse audio frame (typically used for echo cancellation in a full-duplex setup).
68+
69+ In an echo cancellation scenario, this method is used to process the "far-end" audio
70+ prior to mixing or feeding it into the echo canceller. Like `process_stream`, the
71+ input audio frame is modified in-place by the underlying processing module.
72+
73+ Important:
74+ Audio frames must be exactly 10 ms in duration.
75+ """
4376 bdata = data .data .cast ("b" )
4477
4578 req = proto_ffi .FfiRequest ()
@@ -52,4 +85,4 @@ def process_reverse_stream(self, data: AudioFrame) -> None:
5285 resp = FfiClient .instance .request (req )
5386
5487 if resp .apm_process_stream .error :
55- raise Exception (resp .apm_process_stream .error )
88+ raise RuntimeError (resp .apm_process_stream .error )
0 commit comments