
    U th                        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mZm	Z	m
Z
mZmZmZ d dlmZmZ ddlmZmZ ddlmZmZ erd dlmZ dZ ed	ej        
          Z G d de
e                   ZdS )    )annotationsN)AnyTypeUnionGenericTypeVarCallableoverload)TYPE_CHECKINGLiteral   )	FileTypesFileContent)numpysounddevicei]  DType)boundc                      e Zd Zdej        ddfddZddZedd            Zed d            Zed!d"d            Zd#d$dZdS )%
Microphone   NchannelsintdtypeType[DType]should_recordUnion[Callable[[], bool], None]timeoutUnion[float, None]c                t    || _         || _        || _        g | _        || _        t          |          | _        d S N)r   r   r   buffer_chunksr   callablehas_record_function)selfr   r   r   r   s        m/var/www/html/mycamper/aliexpress-site/backend/venv/lib/python3.11/site-packages/openai/helpers/microphone.py__init__zMicrophone.__init__   s?     !
*#+M#:#:       
audio_datanpt.NDArray[DType]returnr   c                   t          j                    }t          j        |d          5 }|                    | j                   |                    t          j        | j                  j	                   |
                    t                     |                    |                                           d d d            n# 1 swxY w Y   |                    d           d|dfS )Nwr   z	audio.wavz	audio/wav)ioBytesIOwaveopensetnchannelsr   setsampwidthnpr   itemsizesetframerateSAMPLE_RATEwriteframestobytesseek)r$   r(   bufferwav_files       r%   _ndarray_to_wavzMicrophone._ndarray_to_wav%   s     jllYvs## 	7x!!$-000!!"(4:"6"6"?@@@!!+...  !3!3!5!5666		7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7
 	AV[11s   BCC	Creturn_ndarrayLiteral[True]c                
   K   d S r     r$   r=   s     r%   recordzMicrophone.record/   s      QTQTr'   Literal[False]c                
   K   d S r    r@   rA   s     r%   rB   zMicrophone.record2   s      ILr'   .Nonec                
   K   d S r    r@   rA   s     r%   rB   zMicrophone.record5   s      EHSr'   FUnion[bool, None]$Union[npt.NDArray[DType], FileTypes]c                $   K   t          j                    t          j                    g  _        t	          j                    d fd}t          j        | j        t           j
        	          }|5                                   d {V  d d d            n# 1 swxY w Y   t           j                  d
k    rt          j         j        d
          nt          j        g  j                  }|r|S                      |          S )Nindatar)   _frame_countr   
_time_infor   _statusc                   t          j                    
z
  }	j        |	j        k    nd}|r&                    j                   t
          j        t          	j                  r	                                nd}|s&                    j                   t
          j        	j	        
                    |                                            d S )NFT)timeperf_counterr   call_soon_threadsafesetsdCallbackStopr"   r   r!   appendcopy)rJ   rK   rL   rM   execution_timereached_recording_timeoutshould_be_recordingeventloopr$   
start_times          r%   callbackz#Microphone.record.<locals>.callback>   s     ".00:=NIMIa(E(Egl%( &))%)444o%:B4CU:V:V"`$"4"4"6"6"6\`& &))%)444o%%%fkkmm44444r'   )r]   r   
samplerater   r   )axis)r   )rJ   r)   rK   r   rL   r   rM   r   )asyncioget_event_loopEventr!   rO   rP   rS   InputStreamr   r6   r   waitlenr3   concatenatearrayr<   )r$   r=   r]   streamconcatenated_chunksrZ   r[   r\   s   `    @@@r%   rB   zMicrophone.record8   s{     %''79&((
	5 	5 	5 	5 	5 	5 	5 	5 	5& *"]	
 
 
  	 	**,,	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 4%&&** N4-A6666"DJ/// 	  	=&&''(;<<<s   9B  B$'B$)r   r   r   r   r   r   r   r   )r(   r)   r*   r   )r=   r>   r*   r)   )r=   rC   r*   r   ).)r=   rE   r*   r   )F)r=   rG   r*   rH   )	__name__
__module____qualname__r3   int16r&   r<   r
   rB   r@   r'   r%   r   r      s         X9=&*; ; ; ; ;2 2 2 2 TTT XTLLL XLHHHH XH,= ,= ,= ,= ,= ,= ,=r'   r   )
__future__r   r-   rO   r/   r`   typingr   r   r   r   r   r	   r
   typing_extensionsr   r   _typesr   r   _extrasr   r3   r   rS   numpy.typingnptr6   genericr   r   r@   r'   r%   <module>rv      s0   " " " " " " 				    I I I I I I I I I I I I I I I I I I 4 4 4 4 4 4 4 4 + + + + + + + + 4 4 4 4 4 4 4 4 rz***N= N= N= N= N= N= N= N= N= N=r'   