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

Fails on >24hr audiobooks & Reader Jumps Around #37

Open
kkrausse opened this issue Oct 25, 2024 · 12 comments
Open

Fails on >24hr audiobooks & Reader Jumps Around #37

kkrausse opened this issue Oct 25, 2024 · 12 comments
Assignees

Comments

@kkrausse
Copy link

kkrausse commented Oct 25, 2024

Seems like the failure at >24hr books is because final wav file gets too big.

Another (somewhat) related issue is that ebook reader randomly pauses and like jump backwards to random places.

Have you considered using m4b-tool instead of combining wav files & making the metadata yourself?

or maybe something with my files messes with the formatting.

edit: willing to work on this myself, but want to know if anyone has ideas first

@DrewThomasson
Copy link
Owner

hm, Ill look into this

but in the meantime I suppose you could try removing the activation of the create_m4b_from_chapters() function?

Then you should just be left with a bunch of chapter wav files located in the Chapter_wav_files dir?

Unless of course your issue comes before the creation of the final giant audiobook file

@DrewThomasson DrewThomasson added the bug Something isn't working label Oct 26, 2024
@ROBERT-MCDOWELL
Copy link
Collaborator

the best is standardize the audio file with a max time, for ex 2 hours, and a consistent naming convention
i.e: chapter-1.1, chapter-1.2 etc...
to split with ffmpeg something like
ffmpeg -i long_audio.wav -f segment -segment_time 7200 chapter%03d.m4b

@kkrausse
Copy link
Author

👍🏻 yeah for now I went the route of just commenting out create_m4b_from_chapters() and use m4b-tool to convert those which works great.

@ROBERT-MCDOWELL
Copy link
Collaborator

@kkrausse v2.0 is out now, but I'm still working on it. If you have already some code for a PR don't hesitate to share it.

@majormer
Copy link

majormer commented Jan 2, 2025

I might have hit something like this.

image

28.4 GB of WAV files were generated for my audiobook. I need to get them combined. I'll look at using m4b-tool to merge them, I suppose, since the conversion took 2 days, but let me know if you need more info:

`Processing 100.00%: : 41039/41039
End of Chapter 41
Combined audio saved to W:\Personal\Repos\ebook2audiobook\tmp\ebook-8fdd5c5b-213b-4214-9e01-0b1c9c69c1c2\chapters_0587d54db0b22fe48ce814b608a119ac\chapter_41.wav
Combining chapter 41 to audio, sentence 39986 to 41038
Processing 100.00%: : 41039/41039
Traceback (most recent call last):
File "W:\Personal\Repos\ebook2audiobook\lib\functions.py", line 709, in assemble_audio
combined_audio.export(assembled_audio, format=audioproc_format)
File "W:\Personal\Repos\ebook2audiobook\python_env\Lib\site-packages\pydub\audio_segment.py", line 895, in export
wave_data.writeframesraw(pcm_for_wav)
File "W:\Personal\Repos\ebook2audiobook\python_env\Lib\wave.py", line 565, in writeframesraw
self._ensure_header_written(len(data))
File "W:\Personal\Repos\ebook2audiobook\python_env\Lib\wave.py", line 606, in _ensure_header_written
self._write_header(datasize)
File "W:\Personal\Repos\ebook2audiobook\python_env\Lib\wave.py", line 618, in _write_header
self._file.write(struct.pack('<L4s4sLHHLLHH4s',
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
struct.error: 'L' format requires 0 <= number <= 4294967295
Caught DependencyError: 'L' format requires 0 <= number <= 4294967295
Traceback (most recent call last):
File "W:\Personal\Repos\ebook2audiobook\lib\functions.py", line 709, in assemble_audio
combined_audio.export(assembled_audio, format=audioproc_format)
File "W:\Personal\Repos\ebook2audiobook\python_env\Lib\site-packages\pydub\audio_segment.py", line 895, in export
wave_data.writeframesraw(pcm_for_wav)
File "W:\Personal\Repos\ebook2audiobook\python_env\Lib\wave.py", line 565, in writeframesraw
self._ensure_header_written(len(data))
File "W:\Personal\Repos\ebook2audiobook\python_env\Lib\wave.py", line 606, in _ensure_header_written
self._write_header(datasize)
File "W:\Personal\Repos\ebook2audiobook\python_env\Lib\wave.py", line 618, in _write_header
self._file.write(struct.pack('<L4s4sLHHLLHH4s',
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
struct.error: 'L' format requires 0 <= number <= 4294967295

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "W:\Personal\Repos\ebook2audiobook\lib\functions.py", line 837, in combine_audio_chapters
if assemble_audio():
^^^^^^^^^^^^^^^^
File "W:\Personal\Repos\ebook2audiobook\lib\functions.py", line 713, in assemble_audio
raise DependencyError(e)
lib.functions.DependencyError: 'L' format requires 0 <= number <= 4294967295
Caught DependencyError: 'L' format requires 0 <= number <= 4294967295
convert_ebook() Exception: 'L' format requires 0 <= number <= 4294967295`

@ROBERT-MCDOWELL
Copy link
Collaborator

it's a wav 32bit limited size. we need to add a function assembling the chunks once it reaches the limit which is 4GB.

@ROBERT-MCDOWELL ROBERT-MCDOWELL self-assigned this Jan 2, 2025
@Mr-Jiggledaddy
Copy link

I changed the intermediate file type for the chapters to .mp3 @128kb/s in functions.py and haven't had any failures yet on the same files that previously failed due to the .wav file size limit. Biggest so far is >20h long. No clue if this could have other ramifications, but it's something that's worked for me so far.

@ROBERT-MCDOWELL
Copy link
Collaborator

well, you tried it before any one of us... good to know! :)

@majormer
Copy link

majormer commented Jan 16, 2025 via email

@ROBERT-MCDOWELL
Copy link
Collaborator

@Mr-Jiggledaddy which function you changed to mp3? combine_audio_sentences() or combine_audio_chapters()?

@Mr-Jiggledaddy
Copy link

I changed combine_audio_sentences (line 681): combined_audio.export(chapter_audio_file, format="mp3", bitrate="128k")

functions.txt

Here's the file converted to .txt so it'll let me upload.

I did have to change several other places where it checks for the file format (lines 555, 575, 833, 835), line 706 and 756 to from_mp3 instead of from_wav, and line 709 to format=mp3. I'm pretty sure that's everything I changed, but I did still have a failure on a 36h audiobook.

Pydub has a PR open to implement the following change to audio_segment.py to allow >4gb file sizes, and that new version of audio_segment did work even on the 36h book.

https://github.com/jiaaro/pydub/blob/4eb5818cff1fe65c1cbef40166c36c47df843287/pydub/audio_segment.py

Would probably be more efficient to just replace the use of pydub for chapters and directly combine the chapters using ffmpeg, but I'm not that skilled and my 2 young kids demand the time I'd use to do it for now.

Really awesome project though, hope it can become everything you guys want it to be, it's already getting some really good use for me.

@ROBERT-MCDOWELL
Copy link
Collaborator

ROBERT-MCDOWELL commented Jan 17, 2025

thanks for your encouragements...
yes, it's absolutely what I'm started to do. switch pydub to ffmpeg libraries as it support RF64 wav and so on.
the issue with mp3 is you cannot concatenate mp3 files without to decode an reencode which is a huge loophole for resources and time conversion. > 4GB is the 32bits limitation which almost all audio files are limited to with some exceptions. for example FLAC, which I selected to be the next default audio processing as the compression and quality is remarkable and it can be concatenated without decode/reencode, and the size is even smaller than a good mp3 quality.

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

No branches or pull requests

5 participants