
    q	h
                    ,    S SK Jr  SSKJr  S/rSS jrg)    )annotations   )
AudioFramecombine_audio_framesc                V   [        U [        5      (       d  U $ U (       d  [        S5      eU S   R                  nU S   R                  nSnSnU  H  nUR                  U:w  a  [        SU SUR                   35      eUR                  U:w  a  [        SU SUR                   35      eU[        UR                  5      -  nXER                  -  nM     [        U5      nSnU  H;  nUR                  R                  S5      nXXw[        U5      -   & U[        U5      -  nM=     [        UUUUS9$ )a  
Combines one or more `rtc.AudioFrame` objects into a single `rtc.AudioFrame`.

This function concatenates the audio data from multiple frames, ensuring that
all frames have the same sample rate and number of channels. It efficiently
merges the data by preallocating the necessary memory and copying the frame
data without unnecessary reallocations.

Args:
    buffer: A single `rtc.AudioFrame` or a list of `rtc.AudioFrame`
        objects to be combined.

Returns:
    rtc.AudioFrame: A new `rtc.AudioFrame` containing the combined audio data.

Raises:
    ValueError: If the buffer is empty.
    ValueError: If frames have differing sample rates.
    ValueError: If frames have differing numbers of channels.

Example:
    >>> frame1 = rtc.AudioFrame(
    ...     data=b"", sample_rate=48000, num_channels=2, samples_per_channel=1
    ... )
    >>> frame2 = rtc.AudioFrame(
    ...     data=b"", sample_rate=48000, num_channels=2, samples_per_channel=1
    ... )
    >>> combined_frame = combine_audio_frames([frame1, frame2])
    >>> combined_frame.data
    b''
    >>> combined_frame.sample_rate
    48000
    >>> combined_frame.num_channels
    2
    >>> combined_frame.samples_per_channel
    2
zbuffer is emptyr   zSample rate mismatch: expected z, got z!Channel count mismatch: expected b)datasample_ratenum_channelssamples_per_channel)
isinstancelist
ValueErrorr
   r   lenr	   r   	bytearraycastr   )	bufferr
   r   total_data_lengthtotal_samples_per_channelframer	   offset
frame_datas	            C/var/www/html/env/lib/python3.13/site-packages/livekit/rtc/utils.pyr   r   	   sL   L fd##*++)''K!9))L !+1+fUEVEVDWX  -3L>HZHZG[\  	S_,!%>%>>!  &'DFZZ__S)
2<Vs:./#j/! 
 !5	     N)r   zAudioFrame | list[AudioFrame]returnr   )
__future__r   audio_framer   __all__r    r   r   <module>r       s    " # "
"Lr   