aboutsummaryrefslogtreecommitdiff
path: root/audiobook.py
diff options
context:
space:
mode:
authorhistoria <historiavg@proton.me>2026-08-24 17:37:34 -0400
committerhistoria <historiavg@proton.me>2026-08-24 17:37:34 -0400
commitd950fc8e64ee508334e608f6045d687d73a464be (patch)
tree87e5539b486c7f15ffba53bbba6ef6bb3a02540e /audiobook.py
parent919544c0931d53bb81904b6212ff14f856549da3 (diff)
downloadtts-audiobook-generator-d950fc8e64ee508334e608f6045d687d73a464be.tar.gz
feat: tui backend server progress and generate script progress
Diffstat (limited to 'audiobook.py')
-rwxr-xr-xaudiobook.py29
1 files changed, 22 insertions, 7 deletions
diff --git a/audiobook.py b/audiobook.py
index 7a9cbda..9a0da29 100755
--- a/audiobook.py
+++ b/audiobook.py
@@ -58,7 +58,9 @@ def convert(backend: str = None, voice: str = None, clone: str = None,
output_format: str = None, debug: bool = False,
model_id: str = None, instructions: str = None,
request_options: dict = None, input_dir: Path = None,
- output_dir: Path = None, api_url: str = None) -> int:
+ output_dir: Path = None, api_url: str = None,
+ progress=None, cancel=None, confirm=None,
+ book_files=None, planned=None) -> int:
"""Run one conversion pass with explicit options (used by the CLI and hub).
Returns the process exit code (0 on success, 1 on failure, 130 on
@@ -68,6 +70,13 @@ def convert(backend: str = None, voice: str = None, clone: str = None,
when given. API_URL, when given, overrides the configured server URL
for the selected backend (used by the hub's "[remote]" entries and
--api-url).
+
+ PROGRESS (a callback taking an event dict), CANCEL (a
+ threading.Event the caller sets to stop between requests), CONFIRM
+ (a (message, default) -> bool callback replacing the console
+ overwrite prompts) and BOOK_FILES/PLANNED (a pre-flight result, so
+ the overwrite prompts are not asked again) wire the conversion into
+ the TUI run view; without them everything behaves like the CLI.
"""
backend = backend or config.BACKEND
output_format = output_format or config.AUDIO_FORMAT
@@ -76,7 +85,9 @@ def convert(backend: str = None, voice: str = None, clone: str = None,
_converter_mod.BOOKS_FOLDER = Path(input_dir)
if output_dir is not None:
_converter_mod.AUDIOBOOKS_FOLDER = Path(output_dir)
- setup_logging(debug=debug)
+ # With a progress callback the run view owns the screen: keep log
+ # records in the file only and let the events carry the state.
+ setup_logging(debug=debug, console=progress is None)
setup_directories()
if backend == BACKEND_FASTER:
@@ -86,11 +97,12 @@ def convert(backend: str = None, voice: str = None, clone: str = None,
else:
voice_mode = VOICE_MODE_CLONE if clone else VOICE_MODE_CUSTOM
- book_files, planned = AudiobookConverter.preflight_overwrites(
- backend=backend, voice=voice, voice_mode=voice_mode,
- voice_clone_ref_audio=clone, output_format=output_format,
- instructions=instructions,
- )
+ if book_files is None or planned is None:
+ book_files, planned = AudiobookConverter.preflight_overwrites(
+ backend=backend, voice=voice, voice_mode=voice_mode,
+ voice_clone_ref_audio=clone, output_format=output_format,
+ instructions=instructions, confirm=confirm,
+ )
if not book_files:
print("[INFO] Nothing to convert. Add a .txt, .pdf, or .epub file "
"to the input folder and run again.")
@@ -108,6 +120,7 @@ def convert(backend: str = None, voice: str = None, clone: str = None,
language=language, backend=backend, voice=voice, debug=debug,
model_id=model_id, instructions=instructions,
request_options=request_options, api_url=api_url,
+ progress=progress, cancel=cancel,
)
converter._book_files = book_files
converter._planned = planned
@@ -118,6 +131,8 @@ def convert(backend: str = None, voice: str = None, clone: str = None,
except Exception as exc:
print(f"[FATAL] Fatal error: {exc}")
traceback.print_exc()
+ if progress is not None:
+ progress({"kind": "error", "message": str(exc)})
return 1
return 0 if ok else 1