skip empty

This commit is contained in:
Claudio Santini 2025-01-16 15:19:45 +01:00
parent 75cb3d1a64
commit 2cea380d75

View file

@ -21,7 +21,7 @@ from pydub import AudioSegment
from pick import pick
def main(kokoro, file_path, lang, voice, pick_manually):
def main(kokoro, file_path, lang, voice, pick_manually, use_gpu):
filename = Path(file_path).name
with warnings.catch_warnings():
book = epub.read_epub(file_path)
@ -55,6 +55,10 @@ def main(kokoro, file_path, lang, voice, pick_manually):
print(f'File for chapter {i} already exists. Skipping')
i += 1
continue
if len(text.strip()) < 10:
print(f'Skipping empty chapter {i}')
i += 1
continue
print(f'Reading chapter {i} ({len(text):,} characters)...')
if i == 1:
text = intro + '.\n\n' + text
@ -96,9 +100,9 @@ def is_chapter(c):
part = r"part\d{1,3}"
if re.search(part, name):
return True
ch = r"ch\d{1,3}"
if re.search(ch, name):
return True
# ch = r"ch\d{1,3}"
# if re.search(ch, name):
# return True
if 'chapter' in name:
return True
@ -174,11 +178,12 @@ def cli_main():
parser.add_argument('-v', '--voice', default=default_voice, help=f'Choose narrating voice: {voices_str}')
parser.add_argument('-p', '--pick', default=False, help=f'Manually select which chapters to read in the audiobook',
action='store_true')
parser.add_argument('-g', '--gpu', default=False, help=f'Use GPU for inference', action='store_true')
if len(sys.argv) == 1:
parser.print_help(sys.stderr)
sys.exit(1)
args = parser.parse_args()
main(kokoro, args.epub_file_path, args.lang, args.voice, args.pick)
main(kokoro, args.epub_file_path, args.lang, args.voice, args.pick, args.gpu)
if __name__ == '__main__':