@simplexai/localmodels-win32-x64 0.1.0-dev.102 → 0.1.0-dev.103

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/bootstrap.identity +1 -1
  2. package/bootstrap.sha256 +46 -27
  3. package/modules/localmodels/__init__.py +1 -1
  4. package/modules/localmodels/__main__.py +3 -1
  5. package/modules/localmodels/catalog.json +306 -1
  6. package/modules/localmodels/cli_parser.py +4 -0
  7. package/modules/localmodels/debug_stub_server.py +280 -7
  8. package/modules/localmodels/download-mirrors.json +76 -0
  9. package/modules/localmodels/engines-speechcpp-v0.11.3.json +84 -0
  10. package/modules/localmodels/library_serve.py +46 -26
  11. package/modules/localmodels/remote_ops_common.py +12 -2
  12. package/modules/localmodels/sidecar_downloads.py +426 -0
  13. package/modules/localmodels/sidecar_http.py +396 -0
  14. package/modules/localmodels/sidecar_state.py +466 -0
  15. package/modules/localmodels/speech_admission.py +13 -0
  16. package/modules/localmodels/speech_jobs.py +81 -370
  17. package/modules/localmodels/speech_server.py +17 -8
  18. package/modules/localmodels/speech_state.py +87 -454
  19. package/modules/localmodels/speech_workers.py +41 -163
  20. package/modules/localmodels/stack.py +18 -0
  21. package/modules/localmodels/stack_down.py +19 -14
  22. package/modules/localmodels/stack_ports.py +1 -0
  23. package/modules/localmodels/stack_up.py +51 -1
  24. package/modules/localmodels/strata_poly_server.py +140 -3
  25. package/modules/localmodels/tts-moss.txt +321 -0
  26. package/modules/localmodels/tts_admission.py +396 -0
  27. package/modules/localmodels/tts_backend_speechcpp.py +487 -0
  28. package/modules/localmodels/tts_catalog.py +251 -0
  29. package/modules/localmodels/tts_cli.py +333 -0
  30. package/modules/localmodels/tts_http.py +617 -0
  31. package/modules/localmodels/tts_jobs.py +496 -0
  32. package/modules/localmodels/tts_model.py +591 -0
  33. package/modules/localmodels/tts_moss_presets.json +1 -0
  34. package/modules/localmodels/tts_serve.py +451 -0
  35. package/modules/localmodels/tts_sidecar.py +750 -0
  36. package/modules/localmodels/tts_state.py +395 -0
  37. package/modules/localmodels/tts_worker_kokoro.py +463 -0
  38. package/modules/localmodels/tts_worker_moss.py +748 -0
  39. package/modules/localmodels/tts_workers.py +696 -0
  40. package/modules/{simplex_localmodels-0.1.0.dev102.dist-info → simplex_localmodels-0.1.0.dev103.dist-info}/METADATA +1 -1
  41. package/modules/{simplex_localmodels-0.1.0.dev102.dist-info → simplex_localmodels-0.1.0.dev103.dist-info}/RECORD +43 -24
  42. package/modules/{simplex_localmodels-0.1.0.dev102.dist-info → simplex_localmodels-0.1.0.dev103.dist-info}/licenses/NOTICE +29 -0
  43. package/package.json +1 -1
  44. package/tool.json +1 -1
  45. /package/modules/{simplex_localmodels-0.1.0.dev102.dist-info → simplex_localmodels-0.1.0.dev103.dist-info}/WHEEL +0 -0
  46. /package/modules/{simplex_localmodels-0.1.0.dev102.dist-info → simplex_localmodels-0.1.0.dev103.dist-info}/entry_points.txt +0 -0
  47. /package/modules/{simplex_localmodels-0.1.0.dev102.dist-info → simplex_localmodels-0.1.0.dev103.dist-info}/licenses/localmodels/HERMES-LICENSE +0 -0
@@ -0,0 +1,496 @@
1
+ """TTS catalog status, list, resumable downloads, cancel, remove, and configuration commands.
2
+
3
+ Delegates byte-range downloads, mirror reuse, disk-space checks, Windows cancel watch, and
4
+ directory pruning to ``localmodels.sidecar_downloads``.
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ import contextlib
10
+ import io
11
+ import os
12
+ import shutil
13
+ from pathlib import Path
14
+ from typing import cast
15
+
16
+ from localmodels import (
17
+ __version__,
18
+ debug_mode,
19
+ hosts,
20
+ library_jobs,
21
+ plan_envelope,
22
+ remote_ops_download,
23
+ sidecar_downloads,
24
+ tts_catalog,
25
+ tts_state,
26
+ tts_workers,
27
+ )
28
+ from localmodels.probe import HostFacts
29
+ from localmodels.records import ReleaseEngine, ReusableFile
30
+ from localmodels.sidecar_downloads import KEEP_FAILED_CODES
31
+ from localmodels.transport import Executor
32
+ from localmodels.tts_catalog import TtsModelSpec
33
+ from localmodels.tts_model import (
34
+ CONFIG_SCHEMA,
35
+ LIST_SCHEMA,
36
+ STATUS_SCHEMA,
37
+ DownloadStep,
38
+ TtsConfig,
39
+ TtsConfigDocument,
40
+ TtsDownloadProgress,
41
+ TtsError,
42
+ TtsListDocument,
43
+ TtsModelError,
44
+ TtsModelRow,
45
+ TtsModelState,
46
+ TtsRuntime,
47
+ TtsStatusDocument,
48
+ emit_progress,
49
+ )
50
+ from localmodels.tts_state import TtsJob, TtsJobHandle, TtsModelRecord
51
+
52
+ _NAMESPACE = "tts"
53
+
54
+
55
+ def model_dir(base_dir: str, model_id: str) -> Path:
56
+ """Directory holding one TTS model's weight, lexicon, and FST files."""
57
+ return sidecar_downloads.model_dir(base_dir, _NAMESPACE, model_id)
58
+
59
+
60
+ def model_file_dest(base_dir: str, model_id: str, file_path: str) -> Path:
61
+ """Destination path for one pinned file of ``model_id``, preserving relative subdirs."""
62
+ return sidecar_downloads.model_file_dest(base_dir, _NAMESPACE, model_id, file_path)
63
+
64
+
65
+ def model_file_specs(
66
+ spec: TtsModelSpec,
67
+ base_dir: str,
68
+ *,
69
+ hf_endpoint: str | None = None,
70
+ ) -> list[ReusableFile]:
71
+ """Pinned file specs with ModelScope mirrors for one TTS model."""
72
+ return sidecar_downloads.model_file_specs(spec, base_dir, _NAMESPACE, hf_endpoint=hf_endpoint)
73
+
74
+
75
+ def weights_installed(spec: TtsModelSpec, base_dir: str) -> bool:
76
+ """True when every pinned file of ``spec`` is verified on disk."""
77
+ return sidecar_downloads.weights_installed(spec, base_dir, _NAMESPACE)
78
+
79
+
80
+ def _lookup_model(model_id: str) -> TtsModelSpec:
81
+ try:
82
+ return tts_catalog.tts_model(model_id)
83
+ except KeyError:
84
+ raise TtsError("MODEL_UNKNOWN", f"unknown tts model: {model_id}") from None
85
+
86
+
87
+ def _row_state(
88
+ spec: TtsModelSpec,
89
+ base_dir: str,
90
+ runtime: TtsRuntime,
91
+ record: TtsModelRecord | None,
92
+ job_info: tuple[TtsJob, bool] | None,
93
+ ) -> tuple[TtsModelState, bool, TtsDownloadProgress | None, TtsModelError | None]:
94
+ active = runtime["running"] and runtime["active_model"] == spec.id
95
+ if active:
96
+ rt_state = runtime["state"]
97
+ if rt_state == "loading":
98
+ return "loading", True, None, None
99
+ if rt_state == "loaded":
100
+ return "loaded", True, None, None
101
+ if rt_state == "error":
102
+ return (
103
+ "failed",
104
+ True,
105
+ None,
106
+ {
107
+ "code": "RUNTIME_ERROR",
108
+ "message": "tts runtime reported an error",
109
+ },
110
+ )
111
+ return "idle", True, None, None
112
+ if job_info is not None and job_info[1]:
113
+ job = job_info[0]
114
+ step: DownloadStep = "verify" if job["step"] == "verify" else "download"
115
+ dl: TtsDownloadProgress = {
116
+ "step": step,
117
+ "done_bytes": job["done_bytes"],
118
+ "total_bytes": job["total_bytes"],
119
+ "bytes_per_second": job["bytes_per_second"],
120
+ "source": job["source"],
121
+ "connections": job["connections"],
122
+ }
123
+ return "downloading", False, dl, None
124
+ if weights_installed(spec, base_dir):
125
+ if record is not None and record.get("state") == "failed" and record.get("error"):
126
+ return "failed", False, None, record["error"]
127
+ return "idle", False, None, None
128
+ if job_info is not None and job_info[0].get("error"):
129
+ return "failed", False, None, job_info[0]["error"]
130
+ return "absent", False, None, None
131
+
132
+
133
+ def _resolve_backend_engine(
134
+ spec: TtsModelSpec,
135
+ base_dir: str,
136
+ *,
137
+ include_gpu: bool,
138
+ facts: HostFacts | None,
139
+ ) -> ReleaseEngine | None:
140
+ backend = tts_workers.BACKENDS.get(spec.engine)
141
+ if backend is None:
142
+ return None
143
+ return backend.resolve_engine(spec, base_dir, include_gpu=include_gpu, facts=facts)
144
+
145
+
146
+ def _engine_bytes(
147
+ spec: TtsModelSpec, base_dir: str, *, use_gpu: bool, facts: HostFacts | None
148
+ ) -> int:
149
+ if facts is None or spec.engine_tag is None:
150
+ return 0
151
+ with contextlib.redirect_stderr(io.StringIO()):
152
+ engine = _resolve_backend_engine(spec, base_dir, include_gpu=use_gpu, facts=facts)
153
+ if engine is None:
154
+ return 0
155
+ return sum(int(asset["size_bytes"]) for asset in engine.get("assets") or ())
156
+
157
+
158
+ def _build_row(
159
+ spec: TtsModelSpec,
160
+ base_dir: str,
161
+ runtime: TtsRuntime,
162
+ record: TtsModelRecord | None,
163
+ job_info: tuple[TtsJob, bool] | None,
164
+ engine_bytes: int = 0,
165
+ ) -> TtsModelRow:
166
+ state, active, dl_info, err_info = _row_state(spec, base_dir, runtime, record, job_info)
167
+ static = spec.status_fields()
168
+ return {
169
+ "id": str(static["id"]),
170
+ "name": str(static["name"]),
171
+ "engine": str(static["engine"]),
172
+ "languages": list(static["languages"]),
173
+ "language_count": int(static["language_count"]),
174
+ "quality_rating": str(static["quality_rating"]),
175
+ "default_voice": str(static["default_voice"]),
176
+ "voice_count": int(static["voice_count"]),
177
+ "sample_rate": int(static["sample_rate"]),
178
+ "supports_streaming": bool(static["supports_streaming"]),
179
+ "supports_instructions": bool(static["supports_instructions"]),
180
+ "license": str(static["license"]),
181
+ "license_url": str(static["license_url"]),
182
+ "commercial_notice": static["commercial_notice"],
183
+ "opt_in_only": bool(static["opt_in_only"]),
184
+ "disk_size_bytes": int(static["disk_size_bytes"]) + engine_bytes,
185
+ "vram_estimate_bytes": int(static["vram_estimate_bytes"]),
186
+ "ram_estimate_bytes": int(static["ram_estimate_bytes"]),
187
+ "gpu_supported": bool(static["gpu_supported"]),
188
+ "state": state,
189
+ "active": active,
190
+ "download": dl_info,
191
+ "error": err_info,
192
+ }
193
+
194
+
195
+ def status(base_dir: str, *, state_dir: Path | None = None) -> TtsStatusDocument:
196
+ """Read-only ``localmodels.tts-status/v1`` snapshot."""
197
+ cfg = tts_state.load_config(state_dir)
198
+ runtime = tts_state.probe_live_runtime(cfg, state_dir)
199
+ by_record = {rec["id"]: rec for rec in tts_state.records(state_dir)}
200
+ by_job = tts_state.jobs(state_dir)
201
+ dbg = debug_mode.current()
202
+ cached_facts = (
203
+ cast(HostFacts, debug_mode.simulated_facts(dbg))
204
+ if dbg.mode == "simulate"
205
+ else hosts.load_facts(hosts.LOCAL_ID)
206
+ )
207
+ rows = [
208
+ _build_row(
209
+ spec,
210
+ base_dir,
211
+ runtime,
212
+ by_record.get(spec.id),
213
+ by_job.get(spec.id),
214
+ _engine_bytes(spec, base_dir, use_gpu=bool(cfg.get("use_gpu")), facts=cached_facts),
215
+ )
216
+ for spec in tts_catalog.tts_models()
217
+ ]
218
+ return {
219
+ "schema": STATUS_SCHEMA,
220
+ "tool_version": __version__,
221
+ "observed_at": plan_envelope.utc_now(),
222
+ "config": cfg,
223
+ "runtime": runtime,
224
+ "models": rows,
225
+ }
226
+
227
+
228
+ def list_models(base_dir: str, *, state_dir: Path | None = None) -> TtsListDocument:
229
+ """Read-only ``localmodels.tts-list/v1`` catalog and install-state summary."""
230
+ snap = status(base_dir, state_dir=state_dir)
231
+ return {
232
+ "schema": LIST_SCHEMA,
233
+ "tool_version": snap["tool_version"],
234
+ "models": snap["models"],
235
+ }
236
+
237
+
238
+ def model_row(model_id: str, base_dir: str, *, state_dir: Path | None = None) -> TtsModelRow:
239
+ """Return the current ``TtsModelRow`` for ``model_id``."""
240
+ for row in status(base_dir, state_dir=state_dir)["models"]:
241
+ if row["id"] == model_id:
242
+ return row
243
+ raise TtsError("MODEL_UNKNOWN", f"unknown tts model: {model_id}")
244
+
245
+
246
+ def _check_disk_space(
247
+ base_dir: str, files: list[ReusableFile], engine: ReleaseEngine | None
248
+ ) -> None:
249
+ needed = sidecar_downloads.needed_disk_bytes(files, engine)
250
+ free = sidecar_downloads.disk_free_bytes(base_dir)
251
+ if free is not None and needed > free:
252
+ raise TtsError(
253
+ "DISK_INSUFFICIENT",
254
+ f"not enough disk space under {base_dir}: needs {needed} bytes, {free} free",
255
+ need_bytes=needed,
256
+ have_bytes=free,
257
+ )
258
+
259
+
260
+ def _emit_tts_progress(
261
+ model_id: str,
262
+ step: str,
263
+ done_bytes: int,
264
+ total_bytes: int,
265
+ rate: int,
266
+ source: str,
267
+ connections: int,
268
+ ) -> None:
269
+ typed: DownloadStep = "verify" if step == "verify" else "download"
270
+ emit_progress(
271
+ model_id, typed, done_bytes, total_bytes, rate, source=source, connections=connections
272
+ )
273
+
274
+
275
+ def _unload_if_active(model_id: str, state_dir: Path | None) -> None:
276
+ rec_rt = tts_state.load_runtime_record(state_dir)
277
+ if rec_rt is None or rec_rt.get("active_model") != model_id:
278
+ return
279
+ rt_url = rec_rt.get("base_url")
280
+ if isinstance(rt_url, str) and rt_url:
281
+ key_file = rec_rt.get("key_file")
282
+ tts_state.sidecar_request(
283
+ rt_url,
284
+ "/v1/tts/unload",
285
+ method="POST",
286
+ key_file=key_file if isinstance(key_file, str) else None,
287
+ payload={"model_id": model_id},
288
+ timeout=3.0,
289
+ )
290
+
291
+
292
+ def _abort_cancelled(
293
+ spec: TtsModelSpec, base_dir: str, dests: list[str], job: TtsJob, state_dir: Path | None
294
+ ) -> None:
295
+ with tts_state.locked(state_dir):
296
+ if not weights_installed(spec, base_dir):
297
+ sidecar_downloads.delete_partials(dests)
298
+ if tts_state.current_job(job, state_dir):
299
+ tts_state.clear_job(spec.id, state_dir)
300
+
301
+
302
+ def download(
303
+ model_id: str,
304
+ base_dir: str,
305
+ *,
306
+ include_gpu_engine: bool = False,
307
+ state_dir: Path | None = None,
308
+ executor: Executor | None = None,
309
+ facts: HostFacts | None = None,
310
+ hf_endpoint: str | None = None,
311
+ ) -> TtsModelRow:
312
+ """Download and SHA-256 verify a TTS model into ``<base_dir>/tts/<model_id>/``."""
313
+ spec = _lookup_model(model_id)
314
+ cfg = debug_mode.current()
315
+ is_sim = cfg.mode == "simulate"
316
+ effective_facts = (
317
+ facts
318
+ if facts is not None
319
+ else (cast(HostFacts, debug_mode.simulated_facts(cfg)) if is_sim else None)
320
+ )
321
+ files = model_file_specs(spec, base_dir, hf_endpoint=hf_endpoint)
322
+ engine = _resolve_backend_engine(
323
+ spec, base_dir, include_gpu=include_gpu_engine, facts=effective_facts
324
+ )
325
+ _check_disk_space(base_dir, files, engine)
326
+ dests = [item["dest"] for item in files]
327
+ if executor is not None:
328
+ runner = executor
329
+ elif is_sim:
330
+ runner = cast(Executor, debug_mode.SimulatedExecutor(cfg))
331
+ else:
332
+ runner = hosts.executor(hosts.get_device(hosts.LOCAL_ID))
333
+
334
+ library_jobs.cancel_on_sigterm()
335
+ with tts_state.locked(state_dir):
336
+ job = tts_state.acquire_job(
337
+ spec.id, base_dir, dests, spec.disk_size_bytes, state_dir=state_dir
338
+ )
339
+ claims = [job]
340
+ with tts_state.held_job(claims, state_dir):
341
+ handle = TtsJobHandle(job, state_dir)
342
+ try:
343
+ if not weights_installed(spec, base_dir):
344
+ _unload_if_active(spec.id, state_dir)
345
+ with sidecar_downloads.watch_cancel(tts_state.STORE, job, state_dir):
346
+ sidecar_downloads.run_fetch(
347
+ spec.id,
348
+ files,
349
+ engine,
350
+ handle,
351
+ runner,
352
+ _emit_tts_progress,
353
+ lambda code, msg: TtsError(code, msg, failed=True),
354
+ )
355
+ except KeyboardInterrupt:
356
+ _abort_cancelled(spec, base_dir, dests, job, state_dir)
357
+ raise TtsError("CANCELLED", "the tts download was cancelled") from None
358
+ except TtsError as exc:
359
+ try:
360
+ sidecar_downloads.check_windows_cancelled(tts_state.STORE, job, state_dir)
361
+ except KeyboardInterrupt:
362
+ _abort_cancelled(spec, base_dir, dests, job, state_dir)
363
+ raise TtsError("CANCELLED", "the tts download was cancelled") from None
364
+ with tts_state.locked(state_dir):
365
+ if tts_state.current_job(job, state_dir):
366
+ if tts_state.is_cancelled(job, state_dir):
367
+ sidecar_downloads.delete_partials(dests)
368
+ tts_state.clear_job(spec.id, state_dir)
369
+ raise TtsError("CANCELLED", "the tts download was cancelled") from None
370
+ if exc.code not in KEEP_FAILED_CODES:
371
+ sidecar_downloads.delete_partials(dests)
372
+ tts_state.fail_job(
373
+ handle.job, {"code": exc.code, "message": exc.message}, state_dir
374
+ )
375
+ claims.clear()
376
+ raise
377
+
378
+ record: TtsModelRecord = {
379
+ "schema": tts_state.MODEL_RECORD_SCHEMA,
380
+ "id": spec.id,
381
+ "base_dir": base_dir,
382
+ "model_dir": str(model_dir(base_dir, spec.id)),
383
+ "files": dests,
384
+ "engine_dir": engine["dir"] if engine is not None else None,
385
+ "engine_backend": engine.get("backend") if engine is not None else None,
386
+ "state": "idle",
387
+ "updated_at": plan_envelope.utc_now(),
388
+ }
389
+ with tts_state.locked(state_dir):
390
+ found = tts_state.read_job(spec.id, state_dir)
391
+ if found is None or found["id"] != job["id"] or tts_state.is_cancelled(job, state_dir):
392
+ sidecar_downloads.delete_partials(dests)
393
+ if tts_state.current_job(job, state_dir):
394
+ tts_state.clear_job(spec.id, state_dir)
395
+ raise TtsError("CANCELLED", "the tts download was cancelled")
396
+ tts_state.save_record(record, state_dir)
397
+ tts_state.clear_job(spec.id, state_dir)
398
+
399
+ return model_row(spec.id, base_dir, state_dir=state_dir)
400
+
401
+
402
+ def cancel(model_id: str, base_dir: str, *, state_dir: Path | None = None) -> TtsModelRow:
403
+ """Cancel an active TTS download cross-platform and discard partial files."""
404
+ spec = _lookup_model(model_id)
405
+ with tts_state.locked(state_dir):
406
+ job = tts_state.read_job(spec.id, state_dir)
407
+ if job is None or job["kind"] != "download":
408
+ raise TtsError("INVALID_STATE", f"{spec.id} has no running download")
409
+ identity = tts_state.receipt(spec.id, state_dir)
410
+ tts_state.mark_cancelled(job, state_dir)
411
+ if identity is not None:
412
+ try:
413
+ tts_state.stop_job_process(identity)
414
+ except (OSError, RuntimeError) as exc:
415
+ raise TtsError("INVALID_STATE", f"cannot stop the download: {exc}") from None
416
+ with tts_state.locked(state_dir):
417
+ if tts_state.current_job(job, state_dir) and not tts_state.job_alive(spec.id, state_dir):
418
+ if not weights_installed(spec, base_dir):
419
+ sidecar_downloads.delete_partials(job["files"])
420
+ tts_state.clear_job(spec.id, state_dir)
421
+ return model_row(spec.id, base_dir, state_dir=state_dir)
422
+
423
+
424
+ def remove(model_id: str, base_dir: str, *, state_dir: Path | None = None) -> TtsModelRow:
425
+ """Unload if active, remove weight files idempotently, and preserve shared venvs."""
426
+ spec = _lookup_model(model_id)
427
+ with tts_state.locked(state_dir):
428
+ if tts_state.job_alive(spec.id, state_dir):
429
+ raise TtsError("INVALID_STATE", f"{spec.id} is downloading; cancel it first")
430
+ _unload_if_active(spec.id, state_dir)
431
+ with tts_state.locked(state_dir):
432
+ record = tts_state.load_record(spec.id, state_dir)
433
+ paths = [f["dest"] for f in model_file_specs(spec, base_dir)]
434
+ if record is not None:
435
+ paths = list(dict.fromkeys([*paths, *record["files"]]))
436
+ for file_path in paths:
437
+ expanded = os.path.expanduser(file_path)
438
+ remote_ops_download.discard(expanded + ".part")
439
+ for target in (expanded, expanded + ".sha256"):
440
+ try:
441
+ os.remove(target)
442
+ except FileNotFoundError:
443
+ pass
444
+ sidecar_downloads.prune_empty_model_dirs(model_dir(base_dir, spec.id), paths)
445
+ eng_dir = record.get("engine_dir") if record is not None else None
446
+ if eng_dir and not sidecar_downloads.engine_in_use_elsewhere(
447
+ tts_state.STORE, eng_dir, spec.id, state_dir
448
+ ):
449
+ eng_path = Path(os.path.expanduser(eng_dir))
450
+ engines_root = Path(os.path.expanduser(base_dir)).resolve() / "engines"
451
+ if eng_path.is_dir() and eng_path.resolve().is_relative_to(engines_root):
452
+ shutil.rmtree(eng_path, ignore_errors=True)
453
+ tts_state.clear_job(spec.id, state_dir)
454
+ tts_state.forget_record(spec.id, state_dir)
455
+ return model_row(spec.id, base_dir, state_dir=state_dir)
456
+
457
+
458
+ def configure(
459
+ base_dir: str,
460
+ *,
461
+ model_id: str | None = None,
462
+ voice: str | None = None,
463
+ speed: float | None = None,
464
+ response_format: str | None = None,
465
+ use_gpu: bool | None = None,
466
+ keep_loaded_seconds: int | None = None,
467
+ language: str | None = None,
468
+ state_dir: Path | None = None,
469
+ ) -> TtsConfigDocument:
470
+ """Validate and atomically persist TTS configuration, pushing live updates best-effort."""
471
+ _ = base_dir
472
+ updates: dict[str, object] = {
473
+ key: val
474
+ for key, val in (
475
+ ("model_id", model_id),
476
+ ("voice", voice),
477
+ ("speed", speed),
478
+ ("response_format", response_format),
479
+ ("use_gpu", use_gpu),
480
+ ("keep_loaded_seconds", keep_loaded_seconds),
481
+ ("language", language),
482
+ )
483
+ if val is not None
484
+ }
485
+ with tts_state.locked(state_dir):
486
+ current = tts_state.load_config(state_dir)
487
+ validated: TtsConfig = tts_state.merge_config_update(current, updates)
488
+ tts_state.save_config(validated, state_dir)
489
+
490
+ runtime_updated = tts_state.STORE.push_config_update("/v1/tts/config", validated, state_dir)
491
+ return {
492
+ "schema": CONFIG_SCHEMA,
493
+ "ok": True,
494
+ "config": validated,
495
+ "runtime_updated": runtime_updated,
496
+ }