aedocw / epub2tts-edge

epub2tts-edge uses Microsoft Edge cloud-based TTS to create a full featured audiobook m4b from an epub or text file
GNU General Public License v3.0
77 stars 13 forks source link

script crashed due to a fail in ffmpeg as processing the txt to audio always at the same spot #5

Closed AriaShishegaran closed 5 months ago

AriaShishegaran commented 6 months ago
(base) ➜  epub2tts_edge git:(main) ✗ python epub2tts_edge.py --speaker en-CA-LiamNeural ../../../HBR’s\ 10\ Must\ Reads\ on\ Strengthening\ Your\ Soft\ Skills.txt
Namespace(sourcefile='../../../HBR’s 10 Must Reads on Strengthening Your Soft Skills.txt', speaker='en-CA-LiamNeural', cover=None)
Chapter: Part 1

Chapter: Part 2

Chapter: Part 3

Chapter: Part 4

Chapter: Part 5

Chapter: Part 6

Traceback (most recent call last):
  File "/Users/lucifer/Downloads/Codes/epub2tts-edge/epub2tts_edge/epub2tts_edge.py", line 311, in <module>
    main()
  File "/Users/lucifer/Downloads/Codes/epub2tts-edge/epub2tts_edge/epub2tts_edge.py", line 304, in main
    files = read_book(book_contents, args.speaker)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/lucifer/Downloads/Codes/epub2tts-edge/epub2tts_edge/epub2tts_edge.py", line 158, in read_book
    combined += AudioSegment.from_mp3(file)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/lucifer/.pyenv/versions/3.11.5/lib/python3.11/site-packages/pydub/audio_segment.py", line 796, in from_mp3
    return cls.from_file(file, 'mp3', parameters=parameters)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/lucifer/.pyenv/versions/3.11.5/lib/python3.11/site-packages/pydub/audio_segment.py", line 773, in from_file
    raise CouldntDecodeError(
pydub.exceptions.CouldntDecodeError: Decoding failed. ffmpeg returned error code: 234

Output from ffmpeg/avlib:

ffmpeg version 7.0 Copyright (c) 2000-2024 the FFmpeg developers
  built with Apple clang version 15.0.0 (clang-1500.3.9.4)
  configuration: --prefix=/opt/homebrew/Cellar/ffmpeg/7.0 --enable-shared --enable-pthreads --enable-version3 --cc=clang --host-cflags= --host-ldflags='-Wl,-ld_classic' --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libaribb24 --enable-libbluray --enable-libdav1d --enable-libharfbuzz --enable-libjxl --enable-libmp3lame --enable-libopus --enable-librav1e --enable-librist --enable-librubberband --enable-libsnappy --enable-libsrt --enable-libssh --enable-libsvtav1 --enable-libtesseract --enable-libtheora --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopenvino --enable-libspeex --enable-libsoxr --enable-libzmq --enable-libzimg --disable-libjack --disable-indev=jack --enable-videotoolbox --enable-audiotoolbox --enable-neon
  libavutil      59.  8.100 / 59.  8.100
  libavcodec     61.  3.100 / 61.  3.100
  libavformat    61.  1.100 / 61.  1.100
  libavdevice    61.  1.100 / 61.  1.100
  libavfilter    10.  1.100 / 10.  1.100
  libswscale      8.  1.100 /  8.  1.100
  libswresample   5.  1.100 /  5.  1.100
  libpostproc    58.  1.100 / 58.  1.100
[mp3 @ 0x1447057b0] Failed to read frame size: Could not seek to 1026.
[in#0 @ 0x6000011e0900] Error opening input: Invalid argument
Error opening input file paras3.mp3.
Error opening input files: Invalid argument
aedocw commented 5 months ago

I think this is the result of an "empty" paragraph being created. I saw this when I had a text file that had " *" between sections of the book, which would cause the script to send that to edgeTTS to be read, but then there's nothing to actually read, so it just skips it. Later on though, the script is looking for that specific paragraph, and there's nothing to be found.

I would appreciate it if you could take a look at your source text and see if you notice anything like that. If you do find that, try deleting those instances (paragraph breaks with no text) from the txt file, and run again to see if that was the issue. Let me know, and I'll try to detect empty paragraphs like that during ingest and skip them entirely.

aedocw commented 5 months ago

This might be the same as https://github.com/aedocw/epub2tts-edge/issues/2

aedocw commented 5 months ago

Please do a git pull and pip install . --upgrade when you can. I've added something that should result in skipping past anything it can't read. This might address your issue.

danielw97 commented 5 months ago

Upon looking into this, it appears this is the same issue as I'm experiencing that I made note of in the ffmpeg on linux discussion. I've tried with the most recent version, and unfortunately it's not made any difference. Interestingly, the problematic file which is one of the paragraphs is 0 kB, so suspect it is indeed including empty paragraphs for some reason as you suspect. Would be interesting if the most recent commit solved this for the original poster, and if so I'm happy to discuss this in another issue.

aedocw commented 5 months ago

I have some very clumsy try/except loops now in the handle-edge-failure branch. I haven't found any good way to actually simulate edge-tts sometimes failing to send back any data, so I don't really know if what I slapped together will work. But if it does, it should notice when an mp3 is zero bytes and try again (up to 3 times before giving up and exiting).

aedocw commented 5 months ago

Latest merge to main catches when there's an empty sentence file, and tries again. In my tests I hit that a few times, and it always had something on the second try. This might fix this issue, please try git pull && pip install . --upgrade to get the latest version, and try encoding the book again if you can, thanks!

AriaShishegaran commented 5 months ago

@aedocw I can confirm that after upgrading the problem is gone. I tested it over the same version of book I was originally using when faced with the error above. It now functions correctly.

danielw97 commented 5 months ago

This also seems to have fixed the problem for me as well, thanks.

aedocw commented 5 months ago

Excellent! Thank you @AriaShishegaran and @danielw97 for testing and letting me know, I appreciate the feedback!