0

I'm trying to split a 15-hour-long audiobook into shorter one-hour-long .mp3 files. Here's the function I made for this:

from pydub import AudioSegment
import re, os, math

def process(fname, title):
    
    head_dir = title + ' (split)'
    if head_dir not in os.listdir():
        os.mkdir(head_dir)
    
    book = AudioSegment.from_file(fname)
    seconds = book.duration_seconds
    iters = math.ceil(seconds / 3600)
    
    one_hour = 3600_000
    thirty_sec = 30_000
    left_off = 0
    
    for i in range(1,iters+1):
        
        last_iter = i == iters
        
        if not last_iter:
            segment = book[left_off:one_hour+thirty_sec].fade_in(1_500).fade_out(3_000)
            left_off += one_hour
            
        else:
            segment = book[left_off:].fade_in(1_500)
            
        segment.export(f'{head_dir}/{i:02d}.mp3')

I've tried this with a file that's around one and a half hours long, and it worked, splitting it into one hour-long file and one thirty-minute-long one, and taking about 5-6 minutes. But running it with a 15-hour-long file doesn't work. It just keeps going forever it seems.

Are there other libraries I could use for this task?

  • Is Python a requirement? https://unix.stackexchange.com/questions/280767/how-do-i-split-an-audio-file-into-multiple https://superuser.com/questions/525210/splitting-an-audio-file-into-chunks-of-a-specified-length – Hendrik Nov 02 '20 at 14:18

1 Answers1

-1

If it helps you can use a tool called LightWorks to upload your audio and then split into 60min intervals.

  • The question concerned audio splitting with Python code. A website is not the answer that the original poster wanted. I downvoted your response since it does not address the issue. – SyMo7amed May 29 '23 at 20:11