mirror of
https://github.com/santinic/audiblez.git
synced 2025-08-05 16:48:55 +00:00
skip empty
This commit is contained in:
parent
75cb3d1a64
commit
2cea380d75
1 changed files with 10 additions and 5 deletions
15
audiblez.py
15
audiblez.py
|
@ -21,7 +21,7 @@ from pydub import AudioSegment
|
||||||
from pick import pick
|
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
|
filename = Path(file_path).name
|
||||||
with warnings.catch_warnings():
|
with warnings.catch_warnings():
|
||||||
book = epub.read_epub(file_path)
|
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')
|
print(f'File for chapter {i} already exists. Skipping')
|
||||||
i += 1
|
i += 1
|
||||||
continue
|
continue
|
||||||
|
if len(text.strip()) < 10:
|
||||||
|
print(f'Skipping empty chapter {i}')
|
||||||
|
i += 1
|
||||||
|
continue
|
||||||
print(f'Reading chapter {i} ({len(text):,} characters)...')
|
print(f'Reading chapter {i} ({len(text):,} characters)...')
|
||||||
if i == 1:
|
if i == 1:
|
||||||
text = intro + '.\n\n' + text
|
text = intro + '.\n\n' + text
|
||||||
|
@ -96,9 +100,9 @@ def is_chapter(c):
|
||||||
part = r"part\d{1,3}"
|
part = r"part\d{1,3}"
|
||||||
if re.search(part, name):
|
if re.search(part, name):
|
||||||
return True
|
return True
|
||||||
ch = r"ch\d{1,3}"
|
# ch = r"ch\d{1,3}"
|
||||||
if re.search(ch, name):
|
# if re.search(ch, name):
|
||||||
return True
|
# return True
|
||||||
if 'chapter' in name:
|
if 'chapter' in name:
|
||||||
return True
|
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('-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',
|
parser.add_argument('-p', '--pick', default=False, help=f'Manually select which chapters to read in the audiobook',
|
||||||
action='store_true')
|
action='store_true')
|
||||||
|
parser.add_argument('-g', '--gpu', default=False, help=f'Use GPU for inference', action='store_true')
|
||||||
if len(sys.argv) == 1:
|
if len(sys.argv) == 1:
|
||||||
parser.print_help(sys.stderr)
|
parser.print_help(sys.stderr)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
args = parser.parse_args()
|
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__':
|
if __name__ == '__main__':
|
||||||
|
|
Loading…
Add table
Reference in a new issue