o
    i                  	   @   s.   d Z 					ddededed	efd
dZdS )a  Audio Partitioning Tool for CTC Segmentation.

Sometimes, The inference of the model is too slow and uses too much memory.
Use RNN-based ASR networks that grow linearly in complexity with longer
audio files. Inference complexity increases on long audio files quadratically
for Transformer-based architectures. To solve this, it is possible to partition
the audio into several parts. This file includes a helper function.
順       @>         t	max_len_sfsoverlapc                 C   sh  |d }t || }t || }||| 8 }||| 8 }t td|}|| |d|  kr;td| d| d| dg }g }	d}
t || }d}| |kr|||  }t td|}||d|   d }t || }|||fg7 }|
|7 }
t|D ]}|	|
| |
d|  g7 }	qy| |8 } ||7 }| |ksM|||  }t td|}||d	fg7 }|||	||||d
}|S )a  Obtain partitions.

    Note that this is implemented for frontends that discard trailing data.
    Note that the partitioning strongly depends on your architecture.
    A note on audio indices:
        Based on the ratio of audio sample points to lpz indices (here called
        frame), the start index of block N is:
        0 + N * samples_to_frames_ratio
        Due to the discarded trailing data, the end is then in the range of:
        [N * samples_to_frames_ratio - 1 .. (1+N) * samples_to_frames_ratio]
    g      ?r      z5Pick a larger time value for partitions. time value: z, overlap: z	, ratio: .   N)
partitionsr	   delete_overlap_listsamples_to_frames_ratio
max_length
cut_length
cut_time_s)intmax
ValueErrorrange)r   r   r   r   r	   r   r   r   r   duplicate_framescumulative_lpz_lengthcut_length_lpz_framespartition_startstartendipartition_dict r   Q/home/ubuntu/.local/lib/python3.10/site-packages/ctc_segmentation/partitioning.pyget_partitions   s`   
	r!   N)r   r   r   r   r   )__doc__r   floatr!   r   r   r   r    <module>   s   