Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Large Chapter Save Recommendation #8

Closed
shakenbake15 opened this issue Aug 26, 2024 · 5 comments
Closed

Large Chapter Save Recommendation #8

shakenbake15 opened this issue Aug 26, 2024 · 5 comments

Comments

@shakenbake15
Copy link

Your chapter save method is non-optimal on books with large chapters. I would recommend that you consider changing the save method to combine the wav files. Currently, you're loading the "combined" file to add a smaller file. When your combined file starts to get large, this considerably slows down the process. loading a 1 min wav file to add 10 seconds is not a big deal, but when you are loading an hour long wav file to add 10 seconds, it can take a while to get to 2 hours or 3 hours. I hope that explanation makes sense. I would suggest that you set a batch limit of 256, then combine the batches for each chapter. This is a minor improvement, but it will speed things up when saving large chapter files.

This is how chat gpt recommends doing the update. Seems reasonable that this would work, but I'm using the program right now, so I can't test it at the moment.

def combine_wav_files(chapter_files, output_path, batch_size=256):
# Initialize an empty audio segment
combined_audio = AudioSegment.empty()

# Process the chapter files in batches
for i in range(0, len(chapter_files), batch_size):
    batch_files = chapter_files[i:i + batch_size]
    batch_audio = AudioSegment.empty()  # Initialize an empty AudioSegment for the batch

    # Sequentially append each file in the current batch to the batch_audio
    for chapter_file in batch_files:
        audio_segment = AudioSegment.from_wav(chapter_file)
        batch_audio += audio_segment

    # Combine the batch audio with the overall combined_audio
    combined_audio += batch_audio

# Export the combined audio to the output file path
combined_audio.export(output_path, format='wav')
print(f"Combined audio saved to {output_path}")
@DrewThomasson
Copy link
Owner

DrewThomasson commented Aug 26, 2024

Ooo!

Yeah sure long as this doesn't increase the ram requirements

Your fix looks pretty straight forward tho, if I can find time to test it

or if you give it the okay from your testing I'll slap that edit in

@DrewThomasson
Copy link
Owner

Also I'll add it manually and add your name at my readme and the commit if I implement it.

But if you open a pull request with your fix then we'll be able to get your name on the official GitHub contributors list for this repo

:)

@DrewThomasson
Copy link
Owner

testing your script modification in this space rn

https://huggingface.co/spaces/drewThomasson/ebook2audiobookXTTS-testing-grounds-2?logs=build

@DrewThomasson
Copy link
Owner

Tested and seems to be working will, to be implemented in the next big update with your credit added to the commit

I'm turning all the scripts into one giant script that does everything lol and having them all work in offline docker lol

DrewThomasson added a commit that referenced this issue Oct 9, 2024
@DrewThomasson
Copy link
Owner

DrewThomasson commented Oct 9, 2024

Implemented!

Thank you for the help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants