
    o i                         d Z ddlZddlZddlZddlmZmZ ddlZddlZ		 	 ddee
ef         dedefd	Zd
 ZddZd ZddddedefdZdS )aE  We use the PyAV library to decode the audio: https://github.com/PyAV-Org/PyAV

The advantage of PyAV is that it bundles the FFmpeg libraries so there is no additional
system dependencies. FFmpeg does not need to be installed on the system.

However, the API is quite low-level so we need to manipulate audio frames directly.
    N)BinaryIOUnion>  F
input_filesampling_ratesplit_stereoc                    t           j        j                            d|sdnd|          }t	          j                    }d}t          j        | dd          5 }|                    d	
          }t          |          }t          |d          }t          ||          }|D ]2}|                                }	|	j        }|                    |	           3	 ddd           n# 1 swxY w Y   ~t          j                     t!          j        |                                |          }
|
                    t           j                  dz  }
|r|
d	dd         }|
ddd         }||fS |
S )a}  Decodes the audio.

    Args:
      input_file: Path to the input file or a file-like object.
      sampling_rate: Resample the audio to this sample rate.
      split_stereo: Return separate left and right channels.

    Returns:
      A float32 Numpy array.

      If `split_stereo` is enabled, the function returns a 2-tuple with the
      separated left and right channels.
    s16monostereo)formatlayoutrateNrignore)modemetadata_errorsr   )audioi  )dtypeg      @      )avr   	resamplerAudioResamplerioBytesIOopendecode_ignore_invalid_frames_group_frames_resample_frames
to_ndarrayr   writegccollectnp
frombuffer	getbufferastypefloat32)r   r   r   r   
raw_bufferr   	containerframesframearrayr   left_channelright_channels                T/var/www/html/auto_sub_bot/venv/lib/python3.11/site-packages/faster_whisper/audio.pydecode_audior3      s   $ "11)7vvx 2  I JE	#x	@	@	@ 	$I!!!**'//vv..!&)44 	$ 	$E$$&&EKEU####	$	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$" 	JLLLM*..00>>>E LL$$w.E +QTT{add]**Ls   A;C  C$'C$c              #      K   t          |           }	 	 t          |          V  n&# t          $ r Y d S t          j        j        $ r Y 6w xY w:N)iternextStopIterationr   errorInvalidDataError)r-   iterators     r2   r   r   O   ss      F||H	x..     	 	 	EEx( 	 	 	H	s   & 
A	A	A	c              #     K   t           j        j                                        }| D ]A}d |_        |                    |           |!|j        |k    r|                                V  B|j        dk    r|                                V  d S d S )Nr   )r   r   fifo	AudioFifoptsr#   samplesread)r-   num_samplesr=   r.   s       r2   r    r    [   s      8=""$$D  	

5"t|{'B'B))++|aiikk     c              #   r   K   t          j        | d g          D ]}|                    |          E d {V  d S r5   )	itertoolschainresample)r-   r   r.   s      r2   r!   r!   i   sV      $00 - -%%e,,,,,,,,,,- -rC     )axislengthrJ   c                    | j         |         |k    r$|                     t          |          |          } | j         |         |k     r5dg| j        z  }d|| j         |         z
  f||<   t	          j        | |          } | S )zQ
    Pad or trim the Mel features array to 3000, as expected by the encoder.
    )indicesrJ   )r   r   r   )shapetakerangendimr&   pad)r/   rK   rJ   
pad_widthss       r2   pad_or_trimrT   o   s     {46!!

5==t
<<{46!!X
*
vD(99:
4uj))LrC   )r   Fr5   )rH   )__doc__r$   r   rE   typingr   r   r   numpyr&   strintboolr3   r   r    r!   rT    rC   r2   <module>r\      s    
			 				     " " " " " " " " 				    
 9 9c8m$99 9 9 9 9x	 	 	   - - -"   s C      rC   