Skip to content

Commit 5e499f6

Browse files
committed
add and export NoiseCancellationOptions dataclass
1 parent 2f3efa8 commit 5e499f6

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

livekit-rtc/livekit/rtc/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
from ._proto.video_frame_pb2 import VideoBufferType, VideoCodec, VideoRotation
3737
from .audio_frame import AudioFrame
3838
from .audio_source import AudioSource
39-
from .audio_stream import AudioFrameEvent, AudioStream
39+
from .audio_stream import AudioFrameEvent, AudioStream, NoiseCancellationOptions
4040
from .audio_filter import AudioFilter
4141
from .chat import ChatManager, ChatMessage
4242
from .e2ee import (
@@ -110,6 +110,7 @@
110110
"AudioFrame",
111111
"AudioSource",
112112
"AudioStream",
113+
"NoiseCancellationOptions",
113114
"AudioFilter",
114115
"AudioFrameEvent",
115116
"LocalParticipant",

livekit-rtc/livekit/rtc/audio_stream.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
4349
class 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

Comments
 (0)