aboutsummaryrefslogtreecommitdiff
path: root/app/backends
diff options
context:
space:
mode:
authorhistoria <historiavg@proton.me>2026-08-25 13:28:42 -0400
committerhistoria <historiavg@proton.me>2026-08-25 13:28:42 -0400
commitd4dbc1a158d1dd6babcba7333a4ed7d719b65d3e (patch)
treeccba2efaef9a265f7cbc754cf70d8071d09e9612 /app/backends
parent0cc01d1da0a629e104202053feb0bb0db91d578d (diff)
downloadtts-audiobook-generator-d4dbc1a158d1dd6babcba7333a4ed7d719b65d3e.tar.gz
feat: automatically name audio.cpp model ids with long name
Diffstat (limited to 'app/backends')
-rwxr-xr-xapp/backends/audiocpp.py73
1 files changed, 20 insertions, 53 deletions
diff --git a/app/backends/audiocpp.py b/app/backends/audiocpp.py
index f95216e..0b82a4e 100755
--- a/app/backends/audiocpp.py
+++ b/app/backends/audiocpp.py
@@ -123,16 +123,6 @@ class _GoBack(Exception):
# Package names that mark a voice-design model (hosted with task "vdes").
DESIGN_PACKAGE_RE = re.compile(r"voice[\s_\-]?design", re.IGNORECASE)
-# Short, friendly default entry ids for selected families. Other families
-# derive an id from their family name (see default_model_id). All families
-# are listed equally, in alphabetical order.
-PREFERRED_IDS = {
- "qwen3_tts": "qwen",
- "higgs_audio_tts": "higgs",
- "voxcpm2": "voxcpm2",
- "index_tts2": "indextts2",
-}
-
class _TuiError(Exception):
"""A fatal error raised from inside the TUI wizard.
@@ -305,16 +295,6 @@ def update_config_model_ids(model_id: str,
return True
-def default_model_id(family: str) -> str:
- """Derive a default server entry id from a family name."""
- if family in PREFERRED_IDS:
- return PREFERRED_IDS[family]
- name = family
- if name.endswith("_tts"):
- name = name[:-4]
- return name.replace("_", "") or family
-
-
def detect_audiocpp_dir() -> Optional[Path]:
"""Best-effort location of a local audio.cpp checkout with model_specs.
@@ -411,9 +391,9 @@ def load_model_catalog(audiocpp_dir: Path) -> List[dict]:
Each returned entry has: family, display_name, description, languages,
clone_capable, packages (the full list from the spec), install_id
- (recommended package id), default_path (``models/<target_directory>``),
- and preferred_id. All families are treated equally and listed in
- alphabetical order by display name.
+ (recommended package id), and default_path (``models/<target_directory>``).
+ All families are treated equally and listed in alphabetical order by
+ display name.
"""
specs_dir = audiocpp_dir / "model_specs"
if not specs_dir.is_dir():
@@ -449,7 +429,6 @@ def load_model_catalog(audiocpp_dir: Path) -> List[dict]:
"packages": packages,
"install_id": package.get("id") or family,
"default_path": f"models/{target_directory}",
- "preferred_id": default_model_id(family),
})
# All families are treated equally: alphabetical by display name.
@@ -716,17 +695,18 @@ def _offer_config_model_id_sync(model_id: str, accepted: Optional[bool]) -> None
def _build_entries(family_keys: List[str], chosen: Dict[str, List[dict]],
catalog_by_family: Dict[str, dict],
task_picker: Callable[[str], str],
- id_picker: Callable[[str, str, str], str],
known_tasks: Optional[Dict[Tuple[str, str], str]] = None
) -> Tuple[List[dict], List[str], List[Tuple[str, str]],
List[str], bool]:
"""Build server.json model entries from the selected families/packages.
- TASK_PICKER is called for each design package to choose vdes/tts;
- ID_PICKER resolves a duplicate server entry id. KNOWN_TASKS maps
- ``(family, target_directory)`` to a previously-stored task ("tts" or
- "vdes") so a modify run preserves how a design package was hosted
- instead of re-asking. Returns (model_entries, entry_ids,
+ TASK_PICKER is called for each design package to choose vdes/tts.
+ KNOWN_TASKS maps ``(family, target_directory)`` to a previously-stored
+ task ("tts" or "vdes") so a modify run preserves how a design package
+ was hosted instead of re-asking. Each entry's server id is its package
+ ``target_directory`` (flattened to a token), so packages from the same
+ family never collide; an id that does collide (across families) is
+ auto-suffixed without prompting. Returns (model_entries, entry_ids,
install_guidance, design_entry_ids, include_clone).
"""
model_entries: List[dict] = []
@@ -745,12 +725,13 @@ def _build_entries(family_keys: List[str], chosen: Dict[str, List[dict]],
task = task_picker(opt["install_id"])
else:
task = TASK_TTS
- base_id = (f"{entry['preferred_id']}-design"
- if task == TASK_VDES else entry["preferred_id"])
+ base_id = opt["target_directory"].replace("/", "-")
model_id = base_id
if model_id in entry_ids:
- model_id = id_picker(entry["display_name"], opt["install_id"],
- f"{base_id}-2")
+ n = 2
+ while f"{base_id}-{n}" in entry_ids:
+ n += 1
+ model_id = f"{base_id}-{n}"
entry_ids.append(model_id)
model_entries.append(build_model_entry(
family, model_id, f"models/{opt['target_directory']}",
@@ -1014,9 +995,8 @@ def _wizard(stdscr, args: argparse.Namespace, parser: argparse.ArgumentParser
s["family_keys"] = family_keys
def _compute_entries() -> None:
- # Design task menus and duplicate-id renames. Esc on any of them
- # raises _GoBack, which the caller turns into Wizard.BACK (the
- # design/duplicate-id prompts are grouped: Esc returns to the
+ # Design task menu. Esc raises _GoBack, which the caller turns into
+ # Wizard.BACK (the design prompts are grouped: Esc returns to the
# families tree).
def task_picker(install_id: str) -> str:
result = tui.menu(
@@ -1031,20 +1011,10 @@ def _wizard(stdscr, args: argparse.Namespace, parser: argparse.ArgumentParser
raise _GoBack()
return result
- def id_picker(display_name: str, install_id: str,
- default: str) -> str:
- result = tui.line_edit(
- stdscr,
- f"Server model id for {display_name} package "
- f"'{install_id}'", default, back_value=_GO_BACK)
- if result is _GO_BACK:
- raise _GoBack()
- return result
-
model_entries, entry_ids, install_guidance, \
design_entry_ids, include_clone = _build_entries(
s["family_keys"], s["chosen"], s["catalog_by_family"],
- task_picker, id_picker, known_tasks=s["existing_tasks"])
+ task_picker, known_tasks=s["existing_tasks"])
s.update({
"model_entries": model_entries,
"entry_ids": entry_ids,
@@ -2373,16 +2343,13 @@ def _collect_from_flags(args: argparse.Namespace,
else:
chosen[family] = [opt for opt in opts if opt["recommended"]]
- # Non-interactive pickers: design packages default to vdes, dup ids get -2.
+ # Non-interactive picker: design packages default to vdes.
def task_picker(install_id: str) -> str:
return TASK_VDES
- def id_picker(display_name: str, install_id: str, default: str) -> str:
- return default
-
model_entries, entry_ids, install_guidance, design_entry_ids, include_clone = \
_build_entries(family_keys, chosen, catalog_by_family,
- task_picker, id_picker)
+ task_picker)
# Server settings.
host = args.host or DEFAULT_HOST