aboutsummaryrefslogtreecommitdiff
path: root/app/backends/faster.py
diff options
context:
space:
mode:
authorhistoria <historiavg@proton.me>2026-08-24 23:49:34 -0400
committerhistoria <historiavg@proton.me>2026-08-24 23:49:34 -0400
commitfe4b2b9eb7fb8aac81f65630720c9079d0a3121a (patch)
tree9c5e5f56d0b931d25e6580f10d09453505eddc2f /app/backends/faster.py
parentf4b1de303704e13818259d5057d176cd841b6ed8 (diff)
downloadtts-audiobook-generator-fe4b2b9eb7fb8aac81f65630720c9079d0a3121a.tar.gz
feat: user-friendly menu gating, clearer install/configure path for backends
Diffstat (limited to 'app/backends/faster.py')
-rwxr-xr-xapp/backends/faster.py119
1 files changed, 75 insertions, 44 deletions
diff --git a/app/backends/faster.py b/app/backends/faster.py
index 36121ff..585e480 100755
--- a/app/backends/faster.py
+++ b/app/backends/faster.py
@@ -52,7 +52,7 @@ from converter.tts import (
transcribe_reference_audio,
whisper_backend_available,
)
-from ui import tui
+from ui import taskview, tui
FASTER_DIR_NAME = "faster-qwen3-tts"
FASTER_GIT_URL = "https://github.com/andimarafioti/faster-qwen3-tts"
@@ -353,49 +353,78 @@ def _try_language(value: str) -> bool:
return False
-def _execute(settings: dict) -> int:
- """Console tail: install, clone, write voices.json, sync, advise."""
+def _execute_steps(settings: dict) -> List[taskview.TaskStep]:
+ """Build the ordered setup steps for the in-TUI task view.
+
+ The same work ``_execute`` runs on the console, split into named steps so
+ the view can show per-step state and progress. Subprocess steps (pip
+ install, git clone) stream through EMIT and abort on CANCEL; print()-based
+ steps are captured by the view's stdout redirect.
+ """
+ steps: List[taskview.TaskStep] = []
+
if settings["do_install"]:
- rc = common.pip_install([FASTER_PIP_PKG])
- if rc != 0:
- print(f"[WARNING] pip install failed (exit {rc}); install "
- f"{FASTER_PIP_PKG} manually")
- else:
- print("[OK] faster-qwen3-tts installed")
+ def install(emit, cancel):
+ rc = common.pip_install([FASTER_PIP_PKG], emit=emit, cancel=cancel)
+ if rc != 0:
+ print(f"[WARNING] pip install failed (exit {rc}); install "
+ f"{FASTER_PIP_PKG} manually")
+ else:
+ print("[OK] faster-qwen3-tts installed")
+ return rc
+ steps.append(taskview.TaskStep(
+ f"Install {FASTER_PIP_PKG}", install))
if settings["do_clone"]:
- rc = common.git_clone(FASTER_GIT_URL, _checkout())
- if rc != 0:
- print(f"[WARNING] git clone failed (exit {rc}); clone manually: "
- f"git clone {FASTER_GIT_URL} {_checkout()}")
- else:
- print(f"[OK] cloned into {_checkout()}")
+ def clone(emit, cancel):
+ rc = common.git_clone(FASTER_GIT_URL, _checkout(),
+ emit=emit, cancel=cancel)
+ if rc != 0:
+ print(f"[WARNING] git clone failed (exit {rc}); clone "
+ f"manually: git clone {FASTER_GIT_URL} {_checkout()}")
+ else:
+ print(f"[OK] cloned into {_checkout()}")
+ return rc
+ steps.append(taskview.TaskStep(
+ "Clone faster-qwen3-tts", clone))
+
+ def write(emit, cancel):
+ voices = _write_voices_json(settings["output_path"],
+ settings["wav_dir"],
+ settings["language"],
+ settings["whisper_model"],
+ settings["plan"])
+ if voices is None:
+ return 1
+
+ # Sync app/converter/config.py port + default voice.
+ port = settings["port"]
+ new_url = common.url_with_port(config.FASTER_API_URL, port)
+ if new_url != config.FASTER_API_URL:
+ if common.update_config_value("FASTER_API_URL", new_url):
+ print(f"[OK] Updated FASTER_API_URL to {new_url}")
+ else:
+ print("[WARNING] Could not update FASTER_API_URL; edit "
+ "app/converter/config.py by hand")
+ default_voice = next(iter(voices))
+ if default_voice != config.FASTER_VOICE:
+ if common.update_config_value("FASTER_VOICE", default_voice):
+ print(f"[OK] Updated FASTER_VOICE to {default_voice}")
+ else:
+ print("[WARNING] Could not update FASTER_VOICE; edit "
+ "app/converter/config.py by hand")
+
+ _print_launch_hint(settings["output_path"], port)
+ return 0
+ steps.append(taskview.TaskStep(
+ "Write voices.json & sync config", write))
+
+ return steps
- voices = _write_voices_json(settings["output_path"], settings["wav_dir"],
- settings["language"], settings["whisper_model"],
- settings["plan"])
- if voices is None:
- return 1
-
- # Sync app/converter/config.py port + default voice.
- port = settings["port"]
- new_url = common.url_with_port(config.FASTER_API_URL, port)
- if new_url != config.FASTER_API_URL:
- if common.update_config_value("FASTER_API_URL", new_url):
- print(f"[OK] Updated FASTER_API_URL to {new_url}")
- else:
- print("[WARNING] Could not update FASTER_API_URL; edit "
- "app/converter/config.py by hand")
- default_voice = next(iter(voices))
- if default_voice != config.FASTER_VOICE:
- if common.update_config_value("FASTER_VOICE", default_voice):
- print(f"[OK] Updated FASTER_VOICE to {default_voice}")
- else:
- print("[WARNING] Could not update FASTER_VOICE; edit "
- "app/converter/config.py by hand")
- _print_launch_hint(settings["output_path"], port)
- return 0
+def _execute(settings: dict) -> int:
+ """Console tail: install, clone, write voices.json, sync, advise."""
+ return taskview.run_steps_inline(_execute_steps(settings))
def _print_launch_hint(voices_path: Path, port: int) -> None:
@@ -415,16 +444,18 @@ def setup_screen(stdscr) -> int:
The hub drives this as one screen of its own ``tui.Wizard`` stack, so
Esc on the wizard's first screen simply returns here and the hub pops
- back to the menu that launched it. The console tail (install/clone/
- transcribe/write) runs under ``tui.suspend`` so the hub's curses
- session stays intact. Returns 0 on completion, 1 when the user aborted.
+ back to the menu that launched it. The setup tail (install/clone/
+ transcribe/write) runs inside the TUI task view on this same screen, so
+ the hub's curses session stays intact and the user sees per-step status
+ instead of being dropped to the console. Returns 0 on completion, 1 when
+ the user aborted.
"""
args = build_parser().parse_args([])
settings = _wizard(stdscr, args)
if settings is None:
return 1
- with tui.suspend(stdscr):
- return _execute(settings)
+ return taskview.run_steps(stdscr, "Setting up faster-qwen3-tts",
+ _execute_steps(settings))
def run_tui(args: Optional[argparse.Namespace] = None) -> int: