3030
3131@dataclass
3232class AudioFrameEvent :
33+ """An event representing a received audio frame.
34+
35+ Attributes:
36+ frame (AudioFrame): The received audio frame.
37+ """
38+
3339 frame : AudioFrame
3440
3541
3642class AudioStream :
37- """AudioStream is a stream of audio frames received from a RemoteTrack."""
43+ """An asynchronous audio stream for receiving audio frames from a participant or track.
44+
45+ The `AudioStream` class provides an asynchronous iterator over audio frames received from
46+ a specific track or participant. It allows you to receive audio frames in real-time with
47+ customizable sample rates and channel configurations.
48+ """
3849
3950 def __init__ (
4051 self ,
@@ -45,6 +56,32 @@ def __init__(
4556 num_channels : int = 1 ,
4657 ** kwargs ,
4758 ) -> None :
59+ """Initialize an `AudioStream` instance.
60+
61+ Args:
62+ track (Optional[Track]): The audio track from which to receive audio. If not provided,
63+ you must specify `participant` and `track_source` in `kwargs`.
64+ loop (Optional[asyncio.AbstractEventLoop], optional): The event loop to use.
65+ Defaults to the current event loop.
66+ capacity (int, optional): The capacity of the internal frame queue. Defaults to 0 (unbounded).
67+ sample_rate (int, optional): The sample rate for the audio stream in Hz.
68+ Defaults to 48000.
69+ num_channels (int, optional): The number of audio channels. Defaults to 1.
70+ Example:
71+ ```python
72+ audio_stream = AudioStream(
73+ track=audio_track,
74+ sample_rate=44100,
75+ num_channels=2,
76+ )
77+
78+ audio_stream = AudioStream.from_track(
79+ track=audio_track,
80+ sample_rate=44100,
81+ num_channels=2,
82+ )
83+ ```
84+ """
4885 self ._track : Track | None = track
4986 self ._sample_rate = sample_rate
5087 self ._num_channels = num_channels
@@ -76,6 +113,29 @@ def from_participant(
76113 sample_rate : int = 48000 ,
77114 num_channels : int = 1 ,
78115 ) -> AudioStream :
116+ """Create an `AudioStream` from a participant's audio track.
117+
118+ Args:
119+ participant (Participant): The participant from whom to receive audio.
120+ track_source (TrackSource.ValueType): The source of the audio track (e.g., microphone, screen share).
121+ loop (Optional[asyncio.AbstractEventLoop], optional): The event loop to use. Defaults to the current event loop.
122+ capacity (int, optional): The capacity of the internal frame queue. Defaults to 0 (unbounded).
123+ sample_rate (int, optional): The sample rate for the audio stream in Hz. Defaults to 48000.
124+ num_channels (int, optional): The number of audio channels. Defaults to 1.
125+
126+ Returns:
127+ AudioStream: An instance of `AudioStream` that can be used to receive audio frames.
128+
129+ Example:
130+ ```python
131+ audio_stream = AudioStream.from_participant(
132+ participant=participant,
133+ track_source=TrackSource.MICROPHONE,
134+ sample_rate=24000,
135+ num_channels=1,
136+ )
137+ ```
138+ """
79139 return AudioStream (
80140 participant = participant ,
81141 track_source = track_source ,
@@ -96,6 +156,27 @@ def from_track(
96156 sample_rate : int = 48000 ,
97157 num_channels : int = 1 ,
98158 ) -> AudioStream :
159+ """Create an `AudioStream` from an existing audio track.
160+
161+ Args:
162+ track (Track): The audio track from which to receive audio.
163+ loop (Optional[asyncio.AbstractEventLoop], optional): The event loop to use. Defaults to the current event loop.
164+ capacity (int, optional): The capacity of the internal frame queue. Defaults to 0 (unbounded).
165+ sample_rate (int, optional): The sample rate for the audio stream in Hz. Defaults to 48000.
166+ num_channels (int, optional): The number of audio channels. Defaults to 1.
167+
168+ Returns:
169+ AudioStream: An instance of `AudioStream` that can be used to receive audio frames.
170+
171+ Example:
172+ ```python
173+ audio_stream = AudioStream.from_track(
174+ track=audio_track,
175+ sample_rate=44100,
176+ num_channels=2,
177+ )
178+ ```
179+ """
99180 return AudioStream (
100181 track = track ,
101182 loop = loop ,
@@ -152,6 +233,11 @@ async def _run(self):
152233 FfiClient .instance .queue .unsubscribe (self ._ffi_queue )
153234
154235 async def aclose (self ) -> None :
236+ """Asynchronously close the audio stream.
237+
238+ This method cleans up resources associated with the audio stream and waits for
239+ any pending operations to complete.
240+ """
155241 self ._ffi_handle .dispose ()
156242 await self ._task
157243
0 commit comments