@@ -40,6 +40,12 @@ class AudioFrameEvent:
4040 frame : AudioFrame
4141
4242
43+ @dataclass
44+ class NoiseCancellationOptions :
45+ module_id : str
46+ options : dict [str , Any ]
47+
48+
4349class AudioStream :
4450 """An asynchronous audio stream for receiving audio frames from a participant or track.
4551
@@ -55,7 +61,7 @@ def __init__(
5561 capacity : int = 0 ,
5662 sample_rate : int = 48000 ,
5763 num_channels : int = 1 ,
58- noise_cancellation : Optional [Tuple [ str , dict [ str , Any ]] ] = None ,
64+ noise_cancellation : Optional [NoiseCancellationOptions ] = None ,
5965 ** kwargs ,
6066 ) -> None :
6167 """Initialize an `AudioStream` instance.
@@ -69,6 +75,10 @@ def __init__(
6975 sample_rate (int, optional): The sample rate for the audio stream in Hz.
7076 Defaults to 48000.
7177 num_channels (int, optional): The number of audio channels. Defaults to 1.
78+ noise_cancellation (Optional[NoiseCancellationOptions], optional):
79+ If noise cancellation is used, pass a `NoiseCancellationOptions` instance
80+ created by the noise cancellation module.
81+
7282 Example:
7383 ```python
7484 audio_stream = AudioStream(
@@ -94,8 +104,8 @@ def __init__(
94104 self ._audio_filter_module = None
95105 self ._audio_filter_options = None
96106 if noise_cancellation is not None :
97- self ._audio_filter_module = noise_cancellation [ 0 ]
98- self ._audio_filter_options = noise_cancellation [ 1 ]
107+ self ._audio_filter_module = noise_cancellation . module_id
108+ self ._audio_filter_options = noise_cancellation . options
99109 self ._task = self ._loop .create_task (self ._run ())
100110 self ._task .add_done_callback (task_done_logger )
101111
@@ -119,7 +129,7 @@ def from_participant(
119129 capacity : int = 0 ,
120130 sample_rate : int = 48000 ,
121131 num_channels : int = 1 ,
122- noise_cancellation : Optional [Tuple [ str , dict [ str , Any ]] ] = None ,
132+ noise_cancellation : Optional [NoiseCancellationOptions ] = None ,
123133 ) -> AudioStream :
124134 """Create an `AudioStream` from a participant's audio track.
125135
@@ -130,6 +140,9 @@ def from_participant(
130140 capacity (int, optional): The capacity of the internal frame queue. Defaults to 0 (unbounded).
131141 sample_rate (int, optional): The sample rate for the audio stream in Hz. Defaults to 48000.
132142 num_channels (int, optional): The number of audio channels. Defaults to 1.
143+ noise_cancellation (Optional[NoiseCancellationOptions], optional):
144+ If noise cancellation is used, pass a `NoiseCancellationOptions` instance
145+ created by the noise cancellation module.
133146
134147 Returns:
135148 AudioStream: An instance of `AudioStream` that can be used to receive audio frames.
@@ -164,7 +177,7 @@ def from_track(
164177 capacity : int = 0 ,
165178 sample_rate : int = 48000 ,
166179 num_channels : int = 1 ,
167- noise_cancellation : Optional [Tuple [ str , dict [ str , Any ]] ] = None ,
180+ noise_cancellation : Optional [NoiseCancellationOptions ] = None ,
168181 ) -> AudioStream :
169182 """Create an `AudioStream` from an existing audio track.
170183
@@ -174,6 +187,9 @@ def from_track(
174187 capacity (int, optional): The capacity of the internal frame queue. Defaults to 0 (unbounded).
175188 sample_rate (int, optional): The sample rate for the audio stream in Hz. Defaults to 48000.
176189 num_channels (int, optional): The number of audio channels. Defaults to 1.
190+ noise_cancellation (Optional[NoiseCancellationOptions], optional):
191+ If noise cancellation is used, pass a `NoiseCancellationOptions` instance
192+ created by the noise cancellation module.
177193
178194 Returns:
179195 AudioStream: An instance of `AudioStream` that can be used to receive audio frames.
0 commit comments