This commit is contained in:
Claudio Santini 2025-01-23 22:14:50 +01:00
parent fb583a2902
commit 1f99440f37

View file

@ -28,6 +28,11 @@ VOICES_FILE = 'voices.json'
config.MAX_PHONEME_LENGTH = 128 config.MAX_PHONEME_LENGTH = 128
def print_eta(total_chars, processed_chars, chars_per_sec):
remaining_time = (total_chars - processed_chars) / chars_per_sec
print(f'Estimated time remaining: {strfdelta(remaining_time)}')
def main(kokoro, file_path, lang, voice, pick_manually, speed, providers): def main(kokoro, file_path, lang, voice, pick_manually, speed, providers):
# Set ONNX providers if specified # Set ONNX providers if specified
if providers: if providers:
@ -68,6 +73,7 @@ def main(kokoro, file_path, lang, voice, pick_manually, speed, providers):
print('Started at:', time.strftime('%H:%M:%S')) print('Started at:', time.strftime('%H:%M:%S'))
print(f'Total characters: {total_chars:,}') print(f'Total characters: {total_chars:,}')
print('Total words:', len(' '.join(texts).split())) print('Total words:', len(' '.join(texts).split()))
print_eta(total_chars, processed_chars, 20) # assume 20 chars per second at the beginning
chapter_mp3_files = [] chapter_mp3_files = []
durations = {} durations = {}
@ -93,9 +99,7 @@ def main(kokoro, file_path, lang, voice, pick_manually, speed, providers):
delta_seconds = end_time - start_time delta_seconds = end_time - start_time
chars_per_sec = len(text) / delta_seconds chars_per_sec = len(text) / delta_seconds
processed_chars += len(text) processed_chars += len(text)
remaining_chars = total_chars - processed_chars print_eta(total_chars, processed_chars, chars_per_sec)
remaining_time = remaining_chars / chars_per_sec
print(f'Estimated time remaining: {strfdelta(remaining_time)}')
print('Chapter written to', chapter_filename) print('Chapter written to', chapter_filename)
print(f'Chapter {i} read in {delta_seconds:.2f} seconds ({chars_per_sec:.0f} characters per second)') print(f'Chapter {i} read in {delta_seconds:.2f} seconds ({chars_per_sec:.0f} characters per second)')
progress = processed_chars * 100 // total_chars progress = processed_chars * 100 // total_chars
@ -189,14 +193,14 @@ def create_m4b(chapter_files, filename, title, author, cover_image):
'ffmpeg', 'ffmpeg',
'-i', f'{tmp_filename}', '-i', f'{tmp_filename}',
'-i', 'chapters.txt', '-i', 'chapters.txt',
# '-map', '0', '-map', '0',
# '-map_metadata', '1', '-map_metadata', '1',
*cover_image_args, # *cover_image_args,
'-c:a', 'copy', '-c:a', 'copy',
'-c:v', 'copy', '-c:v', 'copy',
'-disposition:v', 'attached_pic', '-disposition:v', 'attached_pic',
'-metadata:s:v', f'title={title}', # '-metadata:s:v', f'title={title}',
'-metadata', f'artist={author}', # '-metadata', f'artist={author}',
'-c', 'copy', '-c', 'copy',
'-f', 'mp4', '-f', 'mp4',
f'{final_filename}' f'{final_filename}'