def cut_segments(
    input_dir, output_dir, target_len_sec=30, n_process=32, out_extension=".wav"
):
    """Main function to cut segments from audio files"""

    pathlib.Path(output_dir).mkdir(exist_ok=True, parents=True)
    list_dir = pathlib.Path(input_dir).glob("*/*")
    list_dir = [x for x in list_dir if x.is_dir()]

    print(f"{len(list_dir)} directories detected")
    print(f"Launching {n_process} processes")

    # Create tasks for multiprocessing
    tasks = [
        (path_book, output_dir, target_len_sec, out_extension) for path_book in list_dir
    ]

    # Process tasks in parallel using multiprocessing
    with multiprocessing.Pool(processes=n_process) as pool:
        for _ in tqdm.tqdm(pool.imap_unordered(cut_book, tasks), total=len(tasks)):
            pass
Main function to cut segments from audio files
utils/cut_by_vad.py