� ;��g� ���dZddlZddlZddlZddlmZmZddlZddlZ ddee efde de fd �Z d �Zdd �Zd �Zddd�de de fd�ZdS)aEWe 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���tjj�d|sdnd|���}t j��}d}tj|dd���5}|�d � ��}t|��}t|d ��}t||��}|D]2}|� ��} | j }|� | ���3 ddd��n #1swxYwY~tj��t!j|���|� ��} | �t j��d z } |r| d dd�} | ddd�} | | fS| 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) rrrr� raw_bufferr� container�frames�frame�arrayr� left_channel� right_channels �d/home/asafur/pinokio/api/open-webui.git/app/env/lib/python3.11/site-packages/faster_whisper/audio.py� decode_audior3s���$��"�1�1��)�7�v�v�x� �2���I� ����J� �E� ���#�x� @� @� @� $�I��!�!��!�*�*��'��/�/���v�v�.�.��!�&�)�4�4��� $� $�E��$�$�&�&�E��K�E� � � �U� #� #� #� #� $� $� $� $� $� $� $� $� $� $� $� $���� $� $� $� $�" ��J�L�L�L� �M�*�.�.�0�0�� >� >� >�E� �L�L��� $� $�w� .�E��+��Q�T��T�{� ��a�d��d� � ��]�*�*� �Ls�A;C � C$�'C$c#�K�t|��} t|��V�n&#t$rYdStjj$rY�6wxYw�:�N)�iter�next� StopIterationr�error�InvalidDataError)r-�iterators r2rrOss�����F�|�|�H�� ��x�.�.� � � � ��� � � � �E�E��x�(� � � � �H� ���� s�&� A �A �A c#�K�tjj���}|D]A}d|_|�|��|�!|j|kr|���V��B|jdkr|���V�dSdS)Nr)rr�fifo� AudioFifo�ptsr#�samples�read)r-� num_samplesr=r.s r2r r [s����� �8�=� "� "� $� $�D������� � � � �5���� � "�t�|�{�'B�'B��)�)�+�+� � � �� �|�a����i�i�k�k��������c#�rK�tj|dg��D]}|�|��Ed{V���dSr5)� itertools�chain�resample)r-rr.s r2r!r!isV�������$��0�0�-�-���%�%�e�,�,�,�,�,�,�,�,�,�,�-�-rC� �����)�axis�lengthrJc���|j||kr$|�t|��|���}|j||kr5dg|jz}d||j|z f||<t j||��}|S)zQ Pad or trim the Mel features array to 3000, as expected by the encoder. )�indicesrJ)rrr)�shape�take�range�ndimr&�pad)r/rKrJ� pad_widthss r2� pad_or_trimrTos��� �{�4��6�!�!�� � �5��=�=�t� �<�<�� �{�4��6�!�!��X�� �*� ��v�� �D�(9�9�:� �4����u�j�)�)�� �LrC)rFr5)rH)�__doc__r$rrE�typingrrr�numpyr&�str�int�boolr3rr r!rT�rCr2�<module>r\s���� � � � � � � � �����"�"�"�"�"�"�"�"� � � � ����� ��9�9��c�8�m�$�9��9��9�9�9�9�x � � � � � � �-�-�-� �"� � � �s� �C� � � � � � rC
Memory