DrewThomasson/ebook2audiobook

blank fragment crash

Closed this issue · 6 comments

Hi I've been ancountering a strange error when trying to use the python script

Traceback (most recent call last):
  File "/Users/rihcus/ebook2audiobookXTTS/ebook2audiobook.py", line 460, in <module>
    convert_chapters_to_audio(chapters_directory, output_audio_directory, target_voice, language)
  File "/Users/rihcus/ebook2audiobookXTTS/ebook2audiobook.py", line 424, in convert_chapters_to_audio
    tts.tts_to_file(text=fragment, file_path=fragment_file_path, speaker_wav=speaker_wav_path, language=language_code)
  File "/opt/homebrew/Caskroom/miniconda/base/envs/ebook2audiobookXTTS/lib/python3.10/site-packages/TTS/api.py", line 334, in tts_to_file
    wav = self.tts(
  File "/opt/homebrew/Caskroom/miniconda/base/envs/ebook2audiobookXTTS/lib/python3.10/site-packages/TTS/api.py", line 276, in tts
    wav = self.synthesizer.tts(
  File "/opt/homebrew/Caskroom/miniconda/base/envs/ebook2audiobookXTTS/lib/python3.10/site-packages/TTS/utils/synthesizer.py", line 290, in tts
    raise ValueError(
ValueError: You need to define either `text` (for sythesis) or a `reference_wav` (for voice conversion) to use the Coqui TTS API.

Command used to run:
python ebook2audiobook.py "./sample.epub" "./4.wav" "en"

Book used Spice and wolf Volume 17

I have attached a zip of my working directory which contains a trimed version of the book, csv, and audio generated up to crash.

Regarding the bookt is 1 one page with crash area only, I removed all spoilers and altered the cover with calibre quick start cover

ebook2audiobookXTTS.zip

Any help would be greatly apreciated

Hardware:
OS: macOS 14.2.1 23C71 arm64
Host: MacBookPro18,1
CPU: Apple M1 Pro
GPU: Apple M1 Pro
Memory: 2303MiB / 16384MiB

So I found the sent_tokenize() function can occasionally give a blank output (I'm not sure why)

sentences = sent_tokenize(chapter_text, language='italian' if language == 'it' else 'english')

This causes issues around the loop in line 419 since if a blank fragment is put line 424 tts.tts_to_file will crash since no text is present to convert.

Solution (I think):

add a if fragment != "": under for fragment in fragments:

Disclamer I have very minimal python knowledge and this might not be the most elegant solution.

158d006

Made a pull request (first time making one)

I think I botched the request (wasn't sure if I need to keep a forked repo to make one)

hm, tried to figure out how to merge for 10 min, I can't seem to figure it out lol

But i'll create a new commit with you mentioned in the title with your changes added, sorry still new at this. :/

All I could find was a button to review your fork pull request??? idk man I'm confused lol

hm, tried to figure out how to merge for 10 min, I can't seem to figure it out lol

But i'll create a new commit with you mentioned in the title with your changes added, sorry still new at this. :/

All I could find was a button to review your fork pull request??? idk man I'm confused lol

So when making the edit I first forked the repo, made the edit and tried making a pull request (idk if I did it on the forked repo instead of main).

To make sure the pull was for the main repo I then tried going to your repo (the main one) and using the edit button:

image

and made a pull request.

I thought my fork would be redundant and decided to delete it which ended up with this:

image

TLDR: I somehow botched the pull quest process, but glad you were able to merge it :)

yeah no prob, THX FOR THE FIX!

Also testing your code made me realize that I should change the readme to better reflect how to use the program cause apparently at some point I made it so that you have to include all three parameters when calling the program

python ebook2audiobook.py <path_to_ebook_file> [path_to_voice_file] [language_code]

Idk why but if you don't include all of the parameters then it outputs a empty audio file