+
    ~j3                       ^ RI Ht ^ RIt^ RIt^ RIHt ^ RIHtHtH	t	 ^RI
HtHt ^RIHt ^RIHt ^RIHt ^R	IHtHt ^R
IHt ^RIHt ^RIHt ^RIHt ^RIH t  ] ! R R4      4       t!] ! R R4      4       t" ! R R4      t#R# )    )annotationsN)	dataclass)AnyAsyncIteratorOptional)	FfiClient	FfiHandle)audio_frame_pb2)ffi_pb2)TrackSource)	RingQueuetask_done_logger)
AudioFrame)logger)Participant)Track)FrameProcessorc                  &    ] tR t^"t$ RtR]R&   RtR# )AudioFrameEventzmAn event representing a received audio frame.

Attributes:
    frame (AudioFrame): The received audio frame.
r   frame N)__name__
__module____qualname____firstlineno____doc____annotations____static_attributes__r       m/Users/mitch_tango/dev/rabbit-r1-livekit/agent/.venv/lib/python3.14/site-packages/livekit/rtc/audio_stream.pyr   r   "   s     r   r   c                  ,    ] tR t^-t$ R]R&   R]R&   RtR# )NoiseCancellationOptionsstr	module_idzdict[str, Any]optionsr   N)r   r   r   r   r   r   r   r   r    r"   r"   -   s    Nr   r"   c                      ] tR t^3tRtR R R llt]RRR^ RRR	^R
RRR/R R ll4       t]RRR^ RRR	^R
RRR/R R ll4       tR R lt	R R lt
R R ltR tR R ltR R ltR R ltR R ltRtR# )!AudioStreama?  An asynchronous audio stream for receiving audio frames from a participant or track.

The `AudioStream` class provides an asynchronous iterator over audio frames received from
a specific track or participant. It allows you to receive audio frames in real-time with
customizable sample rates and channel configurations.
N逻  c               8    V ^8  d   QhRRRRRRRRRRR	R
RRRR/# )   trackr   loop#Optional[asyncio.AbstractEventLoop]capacityintsample_ratenum_channelsframe_size_ms
int | Nonenoise_cancellation?Optional[NoiseCancellationOptions | FrameProcessor[AudioFrame]]returnNoner   )formats   "r    __annotate__AudioStream.__annotate__;   se     J! J!J! 2J! 	J!
 J! J! "J! \J! 
J!r   c                b   Wn         W@n        WPn        W`n        T;'       g    \        P
                  ! 4       V n        \        P                  P                  P                  V P                  R R7      V n        \        V4      V n        RV n        RV n        RV n        \#        V\$        4      '       d$   VP&                  V n        VP(                  V n        M\#        V\*        4      '       d   Wpn        V P                  P-                  V P/                  4       4      V n        V P0                  P3                  \4        4       Rp	RV9   d#   V P7                  VR,          VR,          R7      p	MV P9                  4       p	\;        V	P<                  P>                  4      V n         V	PB                  V n"        R# )a  Initialize an `AudioStream` instance.

Args:
    track (Optional[Track]): The audio track from which to receive audio. If not provided,
        you must specify `participant` and `track_source` in `kwargs`.
    loop (Optional[asyncio.AbstractEventLoop], optional): The event loop to use.
        Defaults to the current event loop.
    capacity (int, optional): The capacity of the internal frame queue. Defaults to 0 (unbounded).
    sample_rate (int, optional): The sample rate for the audio stream in Hz.
        Defaults to 48000.
    num_channels (int, optional): The number of audio channels. Defaults to 1.
    noise_cancellation (Optional[NoiseCancellationOptions | FrameProcessor[AudioFrame]], optional):
        If noise cancellation is used, pass a `NoiseCancellationOptions` or `FrameProcessor[AudioFrame]` instance
        created by the noise cancellation module.

Example:
    ```python
    audio_stream = AudioStream(
        track=audio_track,
        sample_rate=44100,
        num_channels=2,
    )

    audio_stream = AudioStream.from_track(
        track=audio_track,
        sample_rate=44100,
        num_channels=2,
    )
    ```
c                *    V P                  R 4      R8H  # )messageaudio_stream_event)
WhichOneof)es   &r    <lambda>&AudioStream.__init__.<locals>.<lambda>m   s    Y 7;O Or   )	filter_fnNparticipanttrack_source)rD   rE   )#_track_sample_rate_num_channels_frame_size_msasyncioget_event_loop_loopr   instancequeue	subscribe
_ffi_queuer   _queue_audio_filter_module_audio_filter_options
_processor
isinstancer"   r$   r%   r   create_task_run_taskadd_done_callbackr   %_create_owned_stream_from_participant_create_owned_streamr	   handleid_ffi_handleinfo_info)
selfr+   r,   r.   r0   r1   r2   r4   kwargsstreams
   &&&&&&&&, r    __init__AudioStream.__init__;   sZ   R %*')+55W335
 $,,22<<JJO = 
 :C89L04!<@"=A(*BCC(:(D(DD%);)C)CD&*N;;0OZZ++DIIK8


$$%56F"??"=1~@V @ F ..0F$V]]%5%56[[
r   r,   r.   r0   r1   r2   r4   c               <    V ^8  d   QhRRRRRRRRR	RR
RRRRRRR/	# )r*   rD   r   rE   TrackSource.ValueTyper,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r'   r   )r8   s   "r    r9   r:      sg     0
 0
 !0
 ,	0

 20
 0
 0
 0
 "0
 \0
 
0
r   c               *    \        VVVVRVVVVR7	      # )a  Create an `AudioStream` from a participant's audio track.

Args:
    participant (Participant): The participant from whom to receive audio.
    track_source (TrackSource.ValueType): The source of the audio track (e.g., microphone, screen share).
    loop (Optional[asyncio.AbstractEventLoop], optional): The event loop to use. Defaults to the current event loop.
    capacity (int, optional): The capacity of the internal frame queue. Defaults to 0 (unbounded).
    sample_rate (int, optional): The sample rate for the audio stream in Hz. Defaults to 48000.
    num_channels (int, optional): The number of audio channels. Defaults to 1.
    noise_cancellation (Optional[NoiseCancellationOptions], optional):
        If noise cancellation is used, pass a `NoiseCancellationOptions` instance
        created by the noise cancellation module.

Returns:
    AudioStream: An instance of `AudioStream` that can be used to receive audio frames.

Example:
    ```python
    audio_stream = AudioStream.from_participant(
        participant=participant,
        track_source=TrackSource.MICROPHONE,
        sample_rate=24000,
        num_channels=1,
    )
    ```
N)	rD   rE   r,   r.   r+   r0   r1   r4   r2   r'   )	clsrD   rE   r,   r.   r0   r1   r2   r4   s	   &$$$$$$$$r    from_participantAudioStream.from_participant   s-    N #%#%1'

 
	
r   c               8    V ^8  d   QhRRRRRRRRRRR	R
RRRR/# )r*   r+   r   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r'   r   )r8   s   "r    r9   r:      s]     +
 +
 +
 2	+

 +
 +
 +
 "+
 \+
 
+
r   c          
     &    \        VVVVVVVR7      # )a  Create an `AudioStream` from an existing audio track.

Args:
    track (Track): The audio track from which to receive audio.
    loop (Optional[asyncio.AbstractEventLoop], optional): The event loop to use. Defaults to the current event loop.
    capacity (int, optional): The capacity of the internal frame queue. Defaults to 0 (unbounded).
    sample_rate (int, optional): The sample rate for the audio stream in Hz. Defaults to 48000.
    num_channels (int, optional): The number of audio channels. Defaults to 1.
    noise_cancellation (Optional[NoiseCancellationOptions], optional):
        If noise cancellation is used, pass a `NoiseCancellationOptions` instance
        created by the noise cancellation module.

Returns:
    AudioStream: An instance of `AudioStream` that can be used to receive audio frames.

Example:
    ```python
    audio_stream = AudioStream.from_track(
        track=audio_track,
        sample_rate=44100,
        num_channels=2,
    )
    ```
)r+   r,   r.   r0   r1   r4   r2   ri   )rj   r+   r,   r.   r0   r1   r2   r4   s   &$$$$$$$r    
from_trackAudioStream.from_track   s'    H #%1'
 	
r   c                   V ^8  d   QhRR/# r*   r6   r7   r   )r8   s   "r    r9   r:      s     > > >r   c                	l    \         P                  P                  P                  V P                  4       R # N)r   rM   rN   unsubscriberP   ra   s   &r    __del__AudioStream.__del__   s       ,,T__=r   c                   V ^8  d   QhRR/# )r*   r6   r   r   )r8   s   "r    r9   r:      s     , ,c ,r   c                	   V P                   f   Q h\        P                  ! 4       pVP                  pV P                   P                  P
                  Vn        V P                  Vn        V P                  Vn
        ^ Vn        V P                  '       d   V P                  Vn        \        P                  P                   Vn        V P$                  e   V P$                  Vn        V P(                  e&   \*        P,                  ! V P(                  4      Vn        \0        P2                  P5                  V4      pVP                  P6                  # rt   )rF   	proto_ffi
FfiRequestnew_audio_streamr^   r\   track_handlerG   r0   rH   r1   queue_size_framesrI   r2   proto_audio_frameAudioStreamTypeAUDIO_STREAM_NATIVEtyperR   audio_filter_module_idrS   jsondumpsaudio_filter_optionsr   rM   requestrc   )ra   reqr}   resps   &   r    r[    AudioStream._create_owned_stream   s   {{&&&""$//(,(?(?(F(F%'+'8'8$(,(:(:%-.*-1-@-@* 1 A A U U$$06:6O6O3%%148JJt?Y?Y4Z1!!))#.$$+++r   c               $    V ^8  d   QhRRRRRR/# )r*   rD   r   rE   rg   r6   r   r   )r8   s   "r    r9   r:      s$     9 9&96K9	9r   c                	j   \         P                  ! 4       pVP                  pVP                  P                  Vn        V P                  Vn        V P                  Vn	        ^ Vn
        \        P                  P                  Vn        W$n        V P                   '       d   V P                   Vn        V P$                  e   V P$                  Vn        V P(                  e&   \*        P,                  ! V P(                  4      Vn        \0        P2                  P5                  V4      pVP                  P6                  # )r   )r{   r|   audio_stream_from_participantr^   r\   participant_handlerG   r0   rH   r1   r   r   r   r   r   rE   rI   r2   rR   r   rS   r   r   r   r   rM   r   rc   )ra   rD   rE   r   r   r   s   &&&   r    rZ   1AudioStream._create_owned_stream_from_participant   s     ""$(+(I(I%;F;R;R;Y;Y%8484E4E%1595G5G%2:;%7->-N-N-b-b%*5A2:>:M:M)7$$0CGC\C\)@%%1AE**B)> !!))#.11888r   c                	  "    V P                   P                  V P                  4      G Rj  xL
 pVP                  pVP	                  R4      '       d   VP
                  P                  p\        P                  ! V4      pV P                  e9   V P                  P                  '       d    V P                  P                  V4      p\        V4      pV P                   P#                  V4       K  VP	                  R4      '       g   EK  V P                   P#                  R4        \$        P&                  P(                  P+                  T P                   4       R#  EL-  \         d    \        P                  ! RR R7        Li ; i5i)TNframe_receivedz7Frame processing failed, passing through original frame)exc_infoeos)rP   wait_for	_is_eventr>   HasFieldr   r   r   _from_owned_inforT   enabled_process	Exceptionr   warningr   rQ   putr   rM   rN   ru   )ra   eventaudio_eventowned_buffer_infor   s   &    r    rW   AudioStream._run  s    //224>>BBE>C>V>VK##$455$/$>$>$D$D!"334EF??.4??3J3J3J $ 8 8 ? (.&%%e,,%  ,,T__=) C % U%)sA   *FE&FAF+E <FAF#F?FFFc                   V ^8  d   QhRR/# rr   r   )r8   s   "r    r9   r:   ,  s      d r   c                n   "   V P                   P                  4        V P                  G Rj  xL
  R#  L5i)zAsynchronously close the audio stream.

This method cleans up resources associated with the audio stream and waits for
any pending operations to complete.
N)r^   disposerX   rv   s   &r    acloseAudioStream.aclose,  s&      	  "jjs   *535c                    V ^8  d   QhRRRR/# )r*   r@   zproto_ffi.FfiEventr6   boolr   )r8   s   "r    r9   r:   5  s     M M- M$ Mr   c                	\    VP                   P                  V P                  P                  8H  # rt   )r>   stream_handler^   r\   )ra   r@   s   &&r    r   AudioStream._is_event5  s%    ##11T5E5E5L5LLLr   c                   V ^8  d   QhRR/# )r*   r6   zAsyncIterator[AudioFrameEvent]r   )r8   s   "r    r9   r:   8  s      9 r   c                	    V # rt   r   rv   s   &r    	__aiter__AudioStream.__aiter__8  s    r   c                   V ^8  d   QhRR/# )r*   r6   r   r   )r8   s   "r    r9   r:   ;  s       r   c                	   "   V P                   P                  4       '       d   \        hV P                  P	                  4       G R j  xL
 pVf   \        hV#  L5irt   )rX   doneStopAsyncIterationrQ   get)ra   items   & r    	__anext__AudioStream.__anext__;  sD     ::??$$[[__&&<$$	 's   AAAA)rR   rS   r^   rP   rI   r`   rL   rH   rT   rQ   rG   rX   rF   )Nr   r(      NN)r   r   r   r   r   rd   classmethodrk   ro   rw   r[   rZ   rW   r   r   r   r   r   r   r   r    r'   r'   3   s    J!X 0

 590
 0
 !0
 0
 %)0
 _c0
 0
d +
 59	+

 +
 !+
 +
 %)+
 _c+
 +
Z>,$9.>0M r   r'   )$
__future__r   rJ   r   dataclassesr   typingr   r   r   _ffi_clientr   r	   _protor
   r   r   r{   _proto.track_pb2r   _utilsr   r   audio_framer   logr   rD   r   r+   r   frame_processorr   r   r"   r'   r   r   r    <module>r      su    #   ! / / - 8 ( ) / #  $  +      
P Pr   