� L�g9��B�dZddlZddlmZdd�Zdd�Z dd �Zdd �ZdS)zE Various functions for finding/manipulating silence in AudioSegments �N�)� db_to_float�������c��t|��}||krgSt|��|jz}g}||z }td|dz|��}||zrt j||g��}|D]/}||||z�} | j|kr|�|���0|sgSg} |�d��} | } |D]6} | | |zk}| | |zk}|s|r| �| | |zg��| } | } �7| �| | |zg��| S)ay Returns a list of all silent sections [start, end] in milliseconds of audio_segment. Inverse of detect_nonsilent() audio_segment - the segment to find silence in min_silence_len - the minimum length for any silent section silence_thresh - the upper bound for how quiet is silent in dFBS seek_step - step size for interating over the segment in ms rr) �lenr�max_possible_amplitude�range� itertools�chain�rms�append�pop)� audio_segment�min_silence_len�silence_thresh� seek_step�seg_len�silence_starts�last_slice_start� slice_starts�i� audio_slice� silent_ranges�prev_i�current_range_start�silence_start_i� continuous�silence_has_gaps �]/home/asafur/pinokio/api/open-webui.git/app/env/lib/python3.11/site-packages/pydub/silence.py�detect_silencer! s����-� � �G��� � �� �!��0�0�=�3W�W�N��N���0����,�q�0�)�<�<�L��)�#�I� ��|�6F�5G�H�H� � �%�%��#�A�a�/�&9�$9�:� � �?�n� ,� ,� � !� !�!� $� $� $�� ��� ��M� � � �� "� "�F� ��)� !� !��%��)�);�;� � *�V�o�-E�F��� 2�o� 2� � � �"5�"(�?�":�"<� =� =� =�"1� � ������-� �?�2�4�5�5�5� ��c�l�t||||��}t|��}|sd|ggS|dddkr|dd|krgSd}g}|D]\}} |�||g��| }�| |kr|�||g��|dddgkr|�d��|S)ay Returns a list of all nonsilent sections [start, end] in milliseconds of audio_segment. Inverse of detect_silent() audio_segment - the segment to find silence in min_silence_len - the minimum length for any silent section silence_thresh - the upper bound for how quiet is silent in dFBS seek_step - step size for interating over the segment in ms rr)r!rrr) rrrrr�len_seg� prev_end_i�nonsilent_ranges�start_i�end_is r �detect_nonsilentr)Ls���#�=�/�>�S\�]�]�M��-� � �G� ���G� �~���Q����a���M�!�$4�Q�$7�7�$B�$B�� ��J���'����������W� 5�6�6�6�� � � ��������W� 5�6�6�6����q�!�f�$�$����Q���� �r"�dc�.���d�}t�t��r�rt���nd��fd�t�|||��D��}||��D]1\}}|d} |d} | | kr| | zdz|d<|d|d<�2�fd�|D��S)am Returns list of audio segments from splitting audio_segment on silent sections audio_segment - original pydub.AudioSegment() object min_silence_len - (in ms) minimum length of a silence to be used for a split. default: 1000ms silence_thresh - (in dBFS) anything quieter than this will be considered silence. default: -16dBFS keep_silence - (in ms or True/False) leave some silence at the beginning and end of the chunks. Keeps the sound from sounding like it is abruptly cut off. When the length of the silence is less than the keep_silence duration it is split evenly between the preceding and following non-silent segments. If True is specified, all the silence is kept, if False none is kept. default: 100ms seek_step - step size for interating over the segment in ms c�p�tj|��\}}t|d��t||��S)z$s -> (s0,s1), (s1,s2), (s2, s3), ...N)r �tee�next�zip)�iterable�a�bs r �pairwisez"split_on_silence.<locals>.pairwise�s0���}�X�&�&���1� �Q�� � � ��1�a�y�y�r"rc�*��g|]\}}|�z |�zg��S�r5)�.0�start�end� keep_silences �r � <listcomp>z$split_on_silence.<locals>.<listcomp>�s<������ �U�3� �,� ��l� 2�4���r"r�c �|��g|]8\}}�t|d��t|t��������9S)r)�max�minr)r6r7r8rs �r r:z$split_on_silence.<locals>.<listcomp>�sQ��� � � � �E�#� �s�5��|�|�c�#�c�-�.@�.@�&A�&A�A�C� � � r")� isinstance�boolrr)) rrrr9rr3� output_ranges�range_i�range_ii�last_end� next_starts ` ` r �split_on_silencerFps����4��� �,��%�%�A�-9�@�s�=�)�)�)�q� ����� � ���PY�Z�Z����M� &�X�m�4�4�%�%�����1�:���a�[� � �� � �"�:�-��1�G�A�J�!�!�*�H�Q�K�� � � � �&� � � �r"�I�� c���d}|dksJ�||||z�j|krA|t|��kr.||z }||||z�j|kr|t|��k�.t|t|����S)a Returns the millisecond/index that the leading silence ends. audio_segment - the segment to find silence in silence_threshold - the upper bound for how quiet is silent in dFBS chunk_size - chunk size for interating over the segment in ms r)�dBFSrr>)�sound�silence_threshold� chunk_size�trim_mss r �detect_leading_silencerO�s����G� ��>�>�>�>� ��� �*�*� +� 0�3D� D� D��SV�W\�S]�S]�I]�I]��:��� ��� �*�*� +� 0�3D� D� D��SV�W\�S]�S]�I]�I]� �w��E� � � #� #�#r")rrr)rrr*r)rGrH)�__doc__r �utilsrr!r)rFrOr5r"r �<module>rRs���������������@�@�@�@�F!�!�!�!�H\_� �3�3�3�3�l$�$�$�$�$�$r"
Memory