� L�g�,��\�ddlZddlZddlZddlmZmZmZmZmZm Z ddl m Z ddl m Z mZejdkreZed���Zedd ���Zedd ���Zed d���Zed!d���Zed"d���Zed���Zed���Zed���Zed#d���ZdS)$�N�)� db_to_float� ratio_to_db�register_pydub_effect� make_chunks�audioop�get_min_max_value)�split_on_silence)�TooManyMissingFrames�InvalidDuration)�rc�:��|j}|���}�fd�|D��}|���}t|��D]9\}}t|�����D]\}}||z|z} ||| <��:|�|��S)Nc�&��g|] }�|����S�r)�.0� channel_seg� filter_fns ��]/home/asafur/pinokio/api/open-webui.git/app/env/lib/python3.11/site-packages/pydub/effects.py� <listcomp>z5apply_mono_filter_to_each_channel.<locals>.<listcomp>s#���K�K�K�{�I�I�k�*�*�K�K�K�)�channels� split_to_mono�get_array_of_samples� enumerate�_spawn) �segr� n_channels� channel_segs�out_data� channel_ir�sample_i�sample�indexs ` r�!apply_mono_filter_to_each_channelr$s������J��$�$�&�&�L�K�K�K�K�l�K�K�K�L��'�'�)�)�H�"+�L�"9�"9�%�%�� �;� )�+�*J�*J�*L�*L� M� M� %� %� �H�f�� �*�i�7�E�$�H�U�O�O� %� �:�:�h� � �r皙�����?c��|j}|dkr|S|jt| ��z}t||z ��}|�|��S)za headroom is how close to the maximum volume to boost the signal up to (specified in dB) r)�max�max_possible_amplituderr� apply_gain)r�headroom�peak_sample_val� target_peak� needed_boosts r� normalizer.#sX�� �g�O��!���� ��,�{�H�9�/E�/E�E�K��{�_�<�=�=�L� �>�>�,� '� '�'r��?��c� � �d|z }|dkrt|d|z z|z ��� n't|��� t||zd|z z ��}t|� dz ��}t||� z��}t|��dkr)t d�|||j������ |z� |d}� fd�|dd�D��}|d}|dd�D]}|�||� ��}�||z }|S) N��?�@r�zwCould not speed up AudioSegment, it was too short {2:0.2f}s for the current settings: {0}ms chunks at {1:0.1f}x speedup�����c�&��g|] }|d� ���S�Nr)r�chunk�ms_to_remove_per_chunks �rrzspeedup.<locals>.<listcomp>Ws(��� G� G� G�%�e�,�,�,�,�-� G� G� Grr�� crossfade)�int�minr�len� Exception�format�duration_seconds�append) r�playback_speed� chunk_sizer<�atk�chunks� last_chunk�outr9r:s @r�speeduprJ4sV��� �� �C�����!$�Z�1�s�7�%;�c�%A�!B�!B���"%�Z������z�)�Q��W�5�6�6� ��I�5��9�:�:�I� ��j�+A�A� B� B�F� �6�{�{�Q����S�Z�Z� ���(<�>�>�?�?� ?� �i�'�����J� G� G� G� G�6�#�2�#�;� G� G� G�F� ��)�C������5�5���j�j��)�j�4�4����:��C� �Jr��������dc���||krtd���t||||��}|dz }t|��s |dd�S|d}|dd�D]}|�||���}�|S)Nz)padding cannot be longer than silence_lenr5rrr;)r r r?rC)r� silence_len�silence_thresh�paddingrGr<r9s r� strip_silencerRas��������I�J�J�J� �c�;��� H� H�F��!� �I� �v�;�;���1�Q�3�x�� ��)�C������5�5���j�j��)�j�4�4��� �Jr�4��@�@�I@c������jt|��z�t��|��������fd�}�fd�}g}d}��|���} ��|���} t t��������D]�} || ��} dd|z z || ��z} | | z }| | z }| �kr|| kr||z }t || ��}n||z}t |d��}��| ��}|dkr)tj |�j t| ����}|� |������ d� |��� ��S) aL Keyword Arguments: threshold - default: -20.0 Threshold in dBFS. default of -20.0 means -20dB relative to the maximum possible volume. 0dBFS is the maximum possible value so all values for this argument sould be negative. ratio - default: 4.0 Compression ratio. Audio louder than the threshold will be reduced to 1/ratio the volume. A ratio of 4.0 is equivalent to a setting of 4:1 in a pro-audio compressor like the Waves C1. attack - default: 5.0 Attack in milliseconds. How long it should take for the compressor to kick in once the audio has exceeded the threshold. release - default: 50.0 Release in milliseconds. How long it should take for the compressor to stop compressing after the audio has falled below the threshold. For an overview of Dynamic Range Compression, and more detailed explanation of the related terminology, see: http://en.wikipedia.org/wiki/Dynamic_range_compression )�msc�@����|�z |��jSr8)�get_sample_slice�rms)�frame_i� look_framesrs ��r�rms_atz&compress_dynamic_range.<locals>.rms_at�s!����#�#�G�k�$9�7�C�C�G�Grc�X��|dkrdSt|�z ��}t|d��S)Nr�)rr')r[�db� thresh_rmss �r�db_over_thresholdz1compress_dynamic_range.<locals>.db_over_threshold�s0��� �!�8�8�C�C� ��z�)� *� *���2�q�z�z�rr`rr3rr��data)r(rr=� frame_count�xranger>r'� get_framer�mul� sample_widthrCr�join)r� threshold�ratio�attack�releaser^rc�output� attenuation� attack_frames�release_frames�i�rms_now�max_attenuation�attenuation_inc�attenuation_dec�framer]rbs` @@r�compress_dynamic_rangerzss������<�+�k�)�.D�.D�D�J��c�o�o��o�0�0�1�1�K�H�H�H�H�H�H������ �F��K��O�O�v�O�.�.�M��_�_��_�0�0�N� �C����)�)�*�*� +� +�����&��)�)����e� �,�0A�0A�'�0J�0J�J��)�M�9��)�N�:�� �Z� � �K�?�$B�$B� �?� *�K��k�?�;�;�K�K� �?� *�K��k�1�-�-�K�� � �a� � �� �#� � ��K�� #� 0� +�[�L� 9� 9�;�;�E� � � �e����� �:�:�3�8�8�F�+�+�:� ,� ,�,r�rrc��|dkr6tj|j|jd��}|�|���S|jdkr|���\}}n'tdt|j��zdz���|dkr|� ��}n|� ��}|� ||��S)z� channels- specifies which channel (left or right) to reverse the phase of. Note that mono AudioSegments will become stereo. r{��rdr5z.Can't implicitly convert an AudioSegment with z channels to stereo.)rr) rri�_datarjrrrr@�str� invert_phase�from_mono_audiosegments)rr�inverted�left�rights rr�r��s����6����;�s�y�#�*:�D�A�A���z�z�x�z�(�(�(� �<�1� � ��+�+�-�-�K�D�%�%��L�s�SV�S_�O`�O`�`�cy�y�z�z� z� �v� � ��$�$�&�&�D�D��&�&�(�(�E��*�*�4��7�7�7rc�\�d|dztjzz }d|jz }|||zz }|���}t j|j|��}t |�����}dg|jz}t|j��D]} || x|| <|| <�td|��D]^} t|j��D]G} | |jz| z} || ||| || z zz|| <t || ��|| <�H�_|� |���S)z� cutoff - Frequency (in Hz) where higher frequency signal will begin to be reduced by 6dB per octave (doubling in frequency) above this point r3r5rrrd) �math�pi� frame_rater�array� array_typer=rfr�ranger) r�cutoff�RC�dt�alpha�original� filteredArrayrf�last_valrt�j�offsets r�low_pass_filterr��sJ�� ��� �T�W�$� %�B� �s�~� �B� �"�r�'�N�E��'�'�)�)�H��K����9�9�M��c�o�o�'�'�(�(�K��s�S�\�!�H� �3�<� � �5�5��)1�!��4��� �m�A�&�&� �1�k� "� "�5�5���s�|�$�$� 5� 5�A��#�,�&�!�+�F�"�1�+��(�6�2B�X�a�[�2P�)Q�R�H�Q�K�$'��� �$4�$4�M�&� !� !� 5� �:�:�=�:� )� )�)rc ���d|dztjzz }d|jz }|||zz }t|jdz��\}}|���}t j|j|��}t|� ����} dg|j z} t|j ��D]} || x| | <|| <�td| ��D]�} t|j ��D]s} | |j z| z} | dz |j z| z}|| | || z||z z| | <ttt| | |��|����|| <�t��|�|���S)z� cutoff - Frequency (in Hz) where lower frequency signal will begin to be reduced by 6dB per octave (doubling in frequency) below this point r3r5�rrrd)r�r�r�r rjrr�r�r=rfrr�r>r'r)rr�r�r�r��minval�maxvalr�r�rfr�rtr�r��offset_minus_1s r�high_pass_filterr��s��� ��� �T�W�$� %�B� �s�~� �B� �"�r�'�N�E�&�s�'7�!�';�<�<�N�F�F��'�'�)�)�H��K����9�9�M��c�o�o�'�'�(�(�K��s�S�\�!�H� �3�<� � �5�5��)1�!��4��� �m�A�&�&� �1�k� "� "�O�O���s�|�$�$� O� O�A��#�,�&�!�+�F� ��s�c�l�2�a�7�N��8�A�;��&�1A�#A�H�^�D\�#\�]�H�Q�K�$'��C��� �V�,D�,D�f�(M�(M�$N�$N�M�&� !� !�  O� �:�:�=�:� )� )�)rc�N�d|cxkrdksntd���td��}t|��|z}t|��}t|��|z }t|��}|dz }|dkr|�||��S|�||��S)as pan_amount should be between -1.0 (100% left) and +1.0 (100% right) When pan_amount == 0.0 the left/right balance is not changed. Panning does not alter the *perceived* loundness, but since loudness is decreasing on one side, the other side needs to get louder to compensate. When panned hard left, the left channel will be 3dB louder. r}r3zCpan_amount should be between -1.0 (100% left) and +1.0 (100% right)r4r)� ValueErrorr�absr�apply_gain_stereo)r� pan_amount� max_boost_db�boost_db� boost_factor� reduce_factor� reduce_dbs r�panr�s��� �:� $� $� $� $�� $� $� $� $��^�_�_�_��s�#�#�L��:����-�H��x�(�(�L�� �-�-� �<�M��M�*�*�I��#�~�H��A�~�~��$�$�X�y�9�9�9��$�$�Y��9�9�9rr`c� �|jdkr|x}}n"|jdkr|���\}}t|��}t|��}tj|j|j|��}tj||jdd��}tj|j|j|��}tj||jdd��}tj|||j��} |� | dd|jzd����S)z� left_gain - amount of gain to apply to the left channel (in dB) right_gain - amount of gain to apply to the right channel (in dB) note: mono audio segments will be converted to stereo rr5r)r� frame_width)re� overrides) rrrrrir~rj�tostereo�addr) r� left_gain� right_gainr�r�� l_mult_factor� r_mult_factor� left_data� right_datarps rr�r�;s �� �|�q������u�u� ��� � ��'�'�)�)� ��e�� �*�*�M�� �+�+�M�� �D�J��(9�=�I�I�I�� ��D�,=�q�!�D�D�I���U�[�%�*<�m�L�L�J��!�*�e�.@�!�Q�G�G�J� �[��J��0@� A� A�F� �:�:�6�'(�*+�c�.>�*>�@�@� � A� A�Ar)r%)r/r0r1)rKrLrM)rSrTrUrV)r{)r`r`)�sysr�r��utilsrrrrrr �silencer � exceptionsr r � version_infor�rgr$r.rJrRrzr�r�r�r�r�rrr�<module>r�s��� � � � � � � � � � � � �����������������&�%�%�%�%�%�=�=�=�=�=�=�=�=���v��� �F��  �  ���  �� (� (� (��� (� �)�)�)���)�X�������"�G-�G-�G-���G-�X�8�8�8���8�6�*�*���*�8�*�*���*�@�:�:���:�>�A�A�A���A�A�Ar
Memory