
    Cj                        S SK Jr  S SKrS SKrS SKrS SKrS SKJr  SSKJ	r	  SSK
JrJr  Sr\SS4         SS	 jjr\ " S
 S5      5       r " S S5      rg)    )annotationsN)	dataclass   )	UserError   )npnpti]  c                b   U R                   [        R                  :X  a;  [        R                  " U SS5      n U S-  R	                  [        R
                  5      n O)U R                   [        R
                  :w  a  [        S5      e[        R                  " 5       n[        R                  " US5       nUR                  U5        UR                  U5        UR                  U5        UR                  U R                  5       5        UR!                  S5        S S S 5        SUS4$ ! , (       d  f       N= f)	N            ?  0Buffer must be a numpy array of int16 or float32wr   z	audio.wavz	audio/wav)dtyper   float32clipastypeint16r   ioBytesIOwaveopensetnchannelssetsampwidthsetframeratewriteframestobytesseek)buffer
frame_ratesample_widthchannels
audio_filewav_files         d/home/rurouni/.local/share/pipx/venvs/strix-agent/lib/python3.13/site-packages/agents/voice/input.py_buffer_to_audio_filer&      s     ||rzz!s+5.((2		!JKKJ	:s	#xh'l+j)V^^-. 
$ [11 
$	#s   /A$D  
D.c                  j    \ rS rSr% SrS\S'    \rS\S'    SrS\S'    S	r	S\S
'    SS jr
SS jrSrg)
AudioInput(   z7Static audio to be used as input for the VoicePipeline.z"npt.NDArray[np.int16 | np.float32]r   intr    r   r!   r   r"   c                n    [        U R                  U R                  U R                  U R                  5      $ )z2Returns a tuple of (filename, bytes, content_type))r&   r   r    r!   r"   selfs    r%   to_audio_fileAudioInput.to_audio_file:   s(    $T[[$//4CTCTVZVcVcdd    c                   U R                   R                  [        R                  :X  aY  [        R                  " U R                   SS5      U l         U R                   S-  R                  [        R                  5      U l         O3U R                   R                  [        R                  :w  a  [        S5      e[        R                  " U R                   R                  5       5      R                  S5      $ )z2Returns the audio data as a base64 encoded string.r   r   r   r   zutf-8)r   r   r   r   r   r   r   r   base64	b64encoder   decoder,   s    r%   	to_base64AudioInput.to_base64>   s    ;;

*''$++tS9DK;;.66rxx@DK[["((*NOO 3 3 56==gFFr0   )r   N)returntuple[str, io.BytesIO, str])r7   str)__name__
__module____qualname____firstlineno____doc____annotations__DEFAULT_SAMPLE_RATEr    r!   r"   r.   r5   __static_attributes__ r0   r%   r(   r(   (   sE    A.. *J)?L#<HcBe	Gr0   r(   c                  (    \ rS rSrSrS rSS jrSrg)StreamedAudioInputJ   zAudio input represented as a stream of audio data. You can pass this to the `VoicePipeline`
and then push audio data into the queue using the `add_audio` method.
c                8    [         R                  " 5       U l        g )N)asyncioQueuequeuer,   s    r%   __init__StreamedAudioInput.__init__O   s    OV}}
r0   c                V   #    U R                   R                  U5      I Sh  vN   g N7f)zAdds more audio data to the stream.

Args:
    audio: The audio data to add. Must be a numpy array of int16 or float32 or None.
      If None passed, it indicates the end of the stream.
N)rI   put)r-   audios     r%   	add_audioStreamedAudioInput.add_audioR   s      jjnnU###s   )'))rI   N)rN   z)npt.NDArray[np.int16 | np.float32] | None)r:   r;   r<   r=   r>   rJ   rO   rA   rB   r0   r%   rD   rD   J   s    _$r0   rD   )
r   z/npt.NDArray[np.int16 | np.float32 | np.float64]r    r*   r!   r*   r"   r*   r7   r8   )
__future__r   rG   r2   r   r   dataclassesr   
exceptionsr   importsr   r	   r@   r&   r(   rD   rB   r0   r%   <module>rU      s    "   	  ! "  
 *	2;22 2 	2
 !22 G G GB$ $r0   