diff options
| author | historia <historiavg@proton.me> | 2026-08-26 19:58:45 -0400 |
|---|---|---|
| committer | historia <historiavg@proton.me> | 2026-08-26 19:58:45 -0400 |
| commit | 975bd960fd07e75799b8e3adc4c0033046b34792 (patch) | |
| tree | 6d5a13c0ad6eb3a6afeb5659bd9e9e21e8c215bc /app/backends | |
| parent | 5af37bbd575eec89c6ac2fecf2d8c2eda4c1728d (diff) | |
| download | tts-audiobook-generator-975bd960fd07e75799b8e3adc4c0033046b34792.tar.gz | |
feat: language and option fields in tui, context-sensitive voice label
Diffstat (limited to 'app/backends')
| -rw-r--r-- | app/backends/common.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/app/backends/common.py b/app/backends/common.py index 25d4f31..b9448e0 100644 --- a/app/backends/common.py +++ b/app/backends/common.py @@ -230,6 +230,28 @@ def normalize_remote_url(value: str) -> str: (parts.scheme or "http", parts.netloc, parts.path, "", "")) +def parse_request_options(text: str) -> Dict[str, str]: + """Parse a user-supplied ``KEY=VALUE`` option string into a dict. + + Items are separated by commas or whitespace; each must contain an + ``=`` with a non-empty key. Values are kept verbatim (only the key is + stripped), so e.g. ``speed=1.1`` yields ``{"speed": "1.1"}`` — the + audio.cpp server coerces per-model option values itself. A blank + string yields {}. Raises ValueError with a user-facing message when + an item lacks ``=`` or has an empty key; later duplicates of a key + override earlier ones. + """ + options: Dict[str, str] = {} + for item in text.replace(",", " ").split(): + key, sep, value = item.partition("=") + if not sep or not key.strip(): + raise ValueError( + f"Request options expect KEY=VALUE items " + f"(e.g. emotion=neutral); got {item!r}") + options[key.strip()] = value + return options + + def server_running(url: str, timeout: float = 0.3) -> bool: """True when something accepts TCP connections at URL's host:port. |
