def cut_sequence(path, vad, path_out, target_len_sec, out_extension):
    """cut audio sequences based on VAD"""
    data, samplerate = sf.read(path)

    assert len(data.shape) == 1
    assert samplerate == 16000

    to_stitch = []
    length_accumulated = 0.0

    i = 0
    # Iterate over VAD segments
    for start, end in vad:
        start_index = int(start * samplerate)
        end_index = int(end * samplerate)
        slice = data[start_index:end_index]

        # Save slices that exceed the target length or if there's already accumulated audio
        if (
            length_accumulated + (end - start) > target_len_sec
            and length_accumulated > 0
        ):
            save(to_stitch, path_out, i, out_extension)
            to_stitch = []
            i += 1
            length_accumulated = 0

        # Add the current slice to the list to be stitched
        to_stitch.append(slice)
        length_accumulated += end - start

    # Save any remaining slices
    if to_stitch:
        save(to_stitch, path_out, i, out_extension)
cut audio sequences based on VAD
utils/cut_by_vad.py