
    .h^                        d dl mZ d dlZd dlZd dlZd dlZd dlmZ ddlm	Z	 ddl
mZmZ dZeddfddZe G d d                      Z G d d          ZdS )    )annotationsN)	dataclass   )	UserError   )npnpti]  buffer"npt.NDArray[np.int16 | np.float32]
frame_rateintsample_widthchannelsreturntuple[str, io.BytesIO, str]c                f   | j         t          j        k    r9t          j        | dd          } | dz                      t          j                  } n$| j         t          j        k    rt          d          t          j                    }t          j
        |d          5 }|                    |           |                    |           |                    |           |                    |                                            |                    d           d d d            n# 1 swxY w Y   d|dfS )	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)r
   r   r   r   
audio_filewav_files         O/var/www/FlaskApp/flask-venv/lib/python3.11/site-packages/agents/voice/input.py_buffer_to_audio_filer*      sI    |rz!!s++5.((22		!	!JKKKJ	:s	#	# xh'''l+++j)))V^^--...               [11s   A<D##D'*D'c                  `    e Zd ZU dZded<   	 eZded<   	 dZded<   	 dZded	<   	 ddZ	ddZ
dS )
AudioInputz7Static audio to be used as input for the VoicePipeline.r   r
   r   r   r   r   r   r   r   r   c                N    t          | j        | j        | j        | j                  S )z2Returns a tuple of (filename, bytes, content_type))r*   r
   r   r   r   selfs    r)   to_audio_filezAudioInput.to_audio_file:   s!    $T[$/4CTVZVcddd    strc                   | j         j        t          j        k    rMt          j        | j         dd          | _         | j         dz                      t          j                  | _         n)| j         j        t          j        k    rt          d          t          j	        | j         
                                                              d          S )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_base64zAudioInput.to_base64>   s    ;
**'$+tS99DK;.66rx@@DKK["(**NOOO 3 3 5 566==gFFFr1   N)r   r   )r   r2   )__name__
__module____qualname____doc____annotations__DEFAULT_SAMPLE_RATEr   r   r   r0   r7    r1   r)   r,   r,   (   s         AA.... *J))))?L<HBe e e e	G 	G 	G 	G 	G 	Gr1   r,   c                       e Zd ZdZd ZddZdS )StreamedAudioInputzAudio 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                6    t          j                    | _        d S )N)asyncioQueuequeuer.   s    r)   __init__zStreamedAudioInput.__init__O   s    HO


r1   audior   c                J   K   | j                             |           d{V  dS )zAdds more audio data to the stream.

        Args:
            audio: The audio data to add. Must be a numpy array of int16 or float32.
        N)rD   put)r/   rF   s     r)   	add_audiozStreamedAudioInput.add_audioR   s4       jnnU###########r1   N)rF   r   )r8   r9   r:   r;   rE   rI   r>   r1   r)   r@   r@   J   sD         X X X$ $ $ $ $ $r1   r@   )
r
   r   r   r   r   r   r   r   r   r   )
__future__r   rB   r4   r   r   dataclassesr   
exceptionsr   importsr   r	   r=   r*   r,   r@   r>   r1   r)   <module>rN      s   " " " " " "   				  ! ! ! ! ! ! " " " " " "         
 *	2 2 2 2 22 G G G G G G G GB$ $ $ $ $ $ $ $ $ $r1   