aboutsummaryrefslogtreecommitdiff
path: root/app/backends/faster.py
diff options
context:
space:
mode:
Diffstat (limited to 'app/backends/faster.py')
-rwxr-xr-xapp/backends/faster.py82
1 files changed, 15 insertions, 67 deletions
diff --git a/app/backends/faster.py b/app/backends/faster.py
index 60ddddf..6cfa53e 100755
--- a/app/backends/faster.py
+++ b/app/backends/faster.py
@@ -117,36 +117,16 @@ def load_voices(path: Path) -> dict:
return data
-def _decide_faster_transcription(wav_files: list, existing_voices: dict
- ) -> tuple:
- """Shape the transcription question for the setup form.
-
- Returns ``(choices, default_mode)``: CHOICES is a list of
- ``(label, mode)`` pairs where MODE is ``"missing"`` (only the new
- voices), ``"all"`` (re-transcribe everything) or ``"keep"``
- (reuse voices.json untouched). With new .wavs present transcribing
- only those is offered first (and is the default); otherwise — and
- always, per the modify design — re-transcribing everything stays
- available, but keeping the existing file is the default.
- """
- existing = dict(existing_voices)
- new_wavs = [wav for wav in wav_files if wav.stem not in existing]
- if new_wavs:
- return ([("Only transcribe new voices", "missing"),
- ("Re-transcribe all", "all")], "missing")
- return ([("Keep the existing voices.json", "keep"),
- ("Re-transcribe all", "all")], "keep")
-
-
def _write_voices_json(output_path: Path, wav_dir: Path, language: str,
- whisper_model: str, plan: Optional[dict]) -> Optional[dict]:
+ whisper_model: str,
+ plan: Optional[dict]) -> Optional[dict]:
"""Transcribe the wav dir and write voices.json; return the voices dict.
- PLAN (built by ``_decide_faster_transcription`` in the wizard, or an
- "all" plan for a fresh/flag run) decides whether every voice is
- re-transcribed ("all"), only the new ones ("missing" — merged into the
- existing entries), or nothing changes ("keep" — the existing file is
- left untouched and returned as-is). None (cancelled) writes nothing.
+ PLAN (from the wizard's transcription toggle, or an "all" plan for a
+ fresh/flag run) decides whether every voice is re-transcribed
+ ("all"), only the new ones ("missing" — merged into the existing
+ entries), or nothing changes ("keep" — the existing file is left
+ untouched and returned as-is). None (cancelled) writes nothing.
"""
if plan is None:
return None
@@ -242,49 +222,14 @@ def _wizard(stdscr, args: argparse.Namespace) -> Optional[dict]:
]
modifying = bool(existing_voices) and not args.force
if modifying:
- # Modify flow: offer keep/new-only/all when the picked directory
- # holds .wavs. Recomputed live so switching directories updates it.
-
- def current_dir(fields_list):
- value = next(f["value"] for f in fields_list
- if f.get("key") == "wav_dir")
- return Path(value) if value else wav_start
-
- choices_cache: dict = {}
-
- def transcription_field() -> dict:
- wav_files = find_wav_files(current_dir(fields))
- if choices_cache.get("dir") != wav_files:
- choices, default = _decide_faster_transcription(
- wav_files, existing_voices)
- choices_cache.clear()
- choices_cache.update({"dir": wav_files,
- "choices": choices,
- "default": default})
- return choices_cache
-
- def transcription_choices(_fields_list):
- return list(transcription_field()["choices"])
-
- def reset_transcription(fields_list) -> None:
- field = next(f for f in fields_list
- if f.get("key") == "transcription")
- modes = [mode for _label, mode
- in transcription_field()["choices"]]
- if field["value"] not in modes:
- field["value"] = transcription_field()["default"]
-
+ # Modify flow: a plain in-place toggle, always offered.
fields.append({
"key": "transcription", "label": "Transcription",
- "kind": "choice",
- "value": transcription_field()["default"],
- "choices": transcription_choices,
- "visible": lambda fs: bool(find_wav_files(current_dir(fs))),
+ "kind": "toggle", "value": "missing",
+ "choices": [("Transcribe new voices", "missing"),
+ ("Re-transcribe all voices", "all")],
"note": "An existing voices.json was found.",
})
- # Changing the directory refreshes the transcription offer;
- # tui.form calls the field's `on_change` with the field list.
- fields[0]["on_change"] = reset_transcription
result = tui.form(
stdscr, "Set up faster-qwen3-tts", fields,
@@ -299,7 +244,10 @@ def _wizard(stdscr, args: argparse.Namespace) -> Optional[dict]:
if not modifying:
plan = {"mode": "all", "missing": [], "existing": {}}
elif find_wav_files(wav_dir):
- plan = _plan_for(result["transcription"], wav_dir, existing_voices)
+ mode = result.get("transcription")
+ if mode not in ("missing", "all"):
+ mode = "missing"
+ plan = _plan_for(mode, wav_dir, existing_voices)
else:
# Directory without .wavs on a modify run: keep the existing file.
plan = {"mode": "keep", "missing": [],