openspeechapi 0.2.18__tar.gz → 0.2.20__tar.gz

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 (161) hide show
  1. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/PKG-INFO +1 -1
  2. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/cli.py +114 -0
  3. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/config.py +17 -0
  4. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/dispatch/dispatcher.py +3 -0
  5. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/dispatch/executors/subprocess_exec.py +25 -0
  6. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/dispatch/lifecycle.py +13 -0
  7. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/pyproject.toml +1 -1
  8. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/.gitignore +0 -0
  9. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/README.md +0 -0
  10. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/__init__.py +0 -0
  11. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/__main__.py +0 -0
  12. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/client/__init__.py +0 -0
  13. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/client/client.py +0 -0
  14. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/core/__init__.py +0 -0
  15. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/core/base.py +0 -0
  16. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/core/enums.py +0 -0
  17. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/core/model_hub.py +0 -0
  18. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/core/models.py +0 -0
  19. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/core/registry.py +0 -0
  20. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/core/settings.py +0 -0
  21. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/demo.py +0 -0
  22. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/dispatch/__init__.py +0 -0
  23. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/dispatch/aim_provision.py +0 -0
  24. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/dispatch/context.py +0 -0
  25. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/dispatch/executors/__init__.py +0 -0
  26. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/dispatch/executors/base.py +0 -0
  27. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/dispatch/executors/in_process.py +0 -0
  28. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/dispatch/executors/remote.py +0 -0
  29. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/dispatch/fanout.py +0 -0
  30. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/dispatch/filters.py +0 -0
  31. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/dispatch/watcher.py +0 -0
  32. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/engine_catalog.py +0 -0
  33. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/engine_registry.yaml +0 -0
  34. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/exceptions.py +0 -0
  35. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/factory.py +0 -0
  36. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/local_engines/__init__.py +0 -0
  37. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/local_engines/aim_resolver.py +0 -0
  38. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/local_engines/backends/__init__.py +0 -0
  39. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/local_engines/backends/docker_backend.py +0 -0
  40. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/local_engines/backends/native_backend.py +0 -0
  41. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/local_engines/base.py +0 -0
  42. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/local_engines/engines/__init__.py +0 -0
  43. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/local_engines/engines/faster_whisper.py +0 -0
  44. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/local_engines/engines/fish_speech.py +0 -0
  45. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/local_engines/engines/sherpa_onnx.py +0 -0
  46. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/local_engines/engines/whisper.py +0 -0
  47. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/local_engines/engines/whisperlivekit.py +0 -0
  48. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/local_engines/isolated_venv.py +0 -0
  49. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/local_engines/manager.py +0 -0
  50. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/local_engines/models.py +0 -0
  51. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/local_engines/progress.py +0 -0
  52. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/local_engines/registry.py +0 -0
  53. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/local_engines/task_store.py +0 -0
  54. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/local_engines/tasks.py +0 -0
  55. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/logging_config.py +0 -0
  56. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/observe/__init__.py +0 -0
  57. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/observe/base.py +0 -0
  58. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/observe/debug.py +0 -0
  59. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/observe/latency.py +0 -0
  60. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/observe/metrics.py +0 -0
  61. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/observe/tracing.py +0 -0
  62. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/observe/usage.py +0 -0
  63. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/providers/__init__.py +0 -0
  64. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/providers/_template.py +0 -0
  65. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/providers/stt/__init__.py +0 -0
  66. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/providers/stt/_local_audio.py +0 -0
  67. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/providers/stt/alibaba.py +0 -0
  68. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/providers/stt/assemblyai.py +0 -0
  69. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/providers/stt/azure_speech.py +0 -0
  70. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/providers/stt/baidu.py +0 -0
  71. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/providers/stt/canary_qwen_stt.py +0 -0
  72. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/providers/stt/deepgram.py +0 -0
  73. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/providers/stt/dolphin_stt.py +0 -0
  74. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/providers/stt/elevenlabs.py +0 -0
  75. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/providers/stt/faster_whisper.py +0 -0
  76. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/providers/stt/fireredasr_stt.py +0 -0
  77. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/providers/stt/funasr_stt.py +0 -0
  78. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/providers/stt/gemma4.py +0 -0
  79. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/providers/stt/google_cloud.py +0 -0
  80. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/providers/stt/iflytek.py +0 -0
  81. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/providers/stt/kimi_audio_stt.py +0 -0
  82. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/providers/stt/macos_speech.py +0 -0
  83. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/providers/stt/mlx_whisper_stt.py +0 -0
  84. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/providers/stt/mms_languages.json +0 -0
  85. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/providers/stt/mms_stt.py +0 -0
  86. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/providers/stt/moonshine_stt.py +0 -0
  87. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/providers/stt/openai.py +0 -0
  88. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/providers/stt/paraformer.py +0 -0
  89. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/providers/stt/parakeet_mlx_stt.py +0 -0
  90. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/providers/stt/phi4_multimodal_stt.py +0 -0
  91. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/providers/stt/qwen3_asr.py +0 -0
  92. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/providers/stt/qwen3_omni_stt.py +0 -0
  93. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/providers/stt/sensevoice.py +0 -0
  94. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/providers/stt/sherpa_onnx.py +0 -0
  95. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/providers/stt/tencent.py +0 -0
  96. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/providers/stt/volcengine.py +0 -0
  97. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/providers/stt/vosk_stt.py +0 -0
  98. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/providers/stt/voxtral_stt.py +0 -0
  99. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/providers/stt/wenet_stt.py +0 -0
  100. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/providers/stt/whisper.py +0 -0
  101. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/providers/stt/whisperlivekit.py +0 -0
  102. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/providers/stt/windows_speech.py +0 -0
  103. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/providers/tts/__init__.py +0 -0
  104. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/providers/tts/alibaba.py +0 -0
  105. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/providers/tts/azure_speech.py +0 -0
  106. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/providers/tts/baidu.py +0 -0
  107. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/providers/tts/coqui.py +0 -0
  108. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/providers/tts/cosyvoice.py +0 -0
  109. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/providers/tts/deepgram.py +0 -0
  110. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/providers/tts/elevenlabs.py +0 -0
  111. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/providers/tts/fish_speech.py +0 -0
  112. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/providers/tts/google_cloud.py +0 -0
  113. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/providers/tts/iflytek.py +0 -0
  114. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/providers/tts/macos_say.py +0 -0
  115. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/providers/tts/minimax.py +0 -0
  116. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/providers/tts/openai.py +0 -0
  117. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/providers/tts/piper.py +0 -0
  118. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/providers/tts/tencent.py +0 -0
  119. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/providers/tts/volcengine.py +0 -0
  120. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/providers/tts/windows_sapi.py +0 -0
  121. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/server/__init__.py +0 -0
  122. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/server/app.py +0 -0
  123. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/server/auth.py +0 -0
  124. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/server/extras_installer.py +0 -0
  125. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/server/middleware.py +0 -0
  126. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/server/native_installer.py +0 -0
  127. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/server/routes/__init__.py +0 -0
  128. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/server/routes/management.py +0 -0
  129. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/server/routes/stt.py +0 -0
  130. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/server/routes/tts.py +0 -0
  131. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/server/routes/webui.py +0 -0
  132. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/server/system_metrics.py +0 -0
  133. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/server/webui/app.js +0 -0
  134. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/server/webui/index.html +0 -0
  135. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/server/webui/styles.css +0 -0
  136. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/server/ws/__init__.py +0 -0
  137. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/server/ws/stt_stream.py +0 -0
  138. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/server/ws/tts_stream.py +0 -0
  139. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/telemetry/__init__.py +0 -0
  140. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/telemetry/perf.py +0 -0
  141. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/utils/__init__.py +0 -0
  142. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/utils/audio_converter.py +0 -0
  143. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/utils/audio_playback.py +0 -0
  144. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/openspeechapi/vendor_registry.yaml +0 -0
  145. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/providers.example.yaml +0 -0
  146. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/scripts/aim_adopt.py +0 -0
  147. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/scripts/aim_consumers.py +0 -0
  148. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/scripts/engines/cloud/install.sh +0 -0
  149. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/scripts/engines/faster-whisper/native/install.sh +0 -0
  150. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/scripts/engines/fish-speech/native/install.sh +0 -0
  151. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/scripts/engines/macos-stt/_bundle.sh +0 -0
  152. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/scripts/engines/macos-stt/install.sh +0 -0
  153. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/scripts/engines/macos-stt/macos_stt.swift +0 -0
  154. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/scripts/engines/macos-stt/request_auth.swift +0 -0
  155. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/scripts/engines/sherpa-onnx/native/install.sh +0 -0
  156. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/scripts/engines/sherpa-onnx/native/run_streaming_server.py +0 -0
  157. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/scripts/engines/whisper/native/install.sh +0 -0
  158. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/scripts/engines/whisperlivekit/native/install.sh +0 -0
  159. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/scripts/gen_mms_languages.py +0 -0
  160. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/scripts/preload_stt_model.py +0 -0
  161. {openspeechapi-0.2.18 → openspeechapi-0.2.20}/scripts/release.sh +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: openspeechapi
3
- Version: 0.2.18
3
+ Version: 0.2.20
4
4
  Summary: Unified speech interface for STT/TTS providers
5
5
  Requires-Python: >=3.11
6
6
  Requires-Dist: httpx>=0.27
@@ -54,6 +54,98 @@ def _cmd_check(args: argparse.Namespace) -> None:
54
54
  sys.exit(1)
55
55
 
56
56
 
57
+ # ── management CLI: talk to a running `serve` over HTTP (free GPU on demand) ──
58
+
59
+ def _server_base_url(args: argparse.Namespace) -> str:
60
+ """Base URL of a running server: ``--url`` if given, else ``http://127.0.0.1:<config port>``."""
61
+ url = getattr(args, "url", None)
62
+ if url:
63
+ return url.rstrip("/")
64
+ port = 8600
65
+ try:
66
+ cfg = load_config(resolve_config_path(getattr(args, "config", None)))
67
+ port = cfg.server.port
68
+ except Exception: # noqa: BLE001 - config unreadable → fall back to the default port
69
+ pass
70
+ return f"http://127.0.0.1:{port}"
71
+
72
+
73
+ def _http_json(method: str, url: str, timeout: float = 15.0) -> dict:
74
+ """Minimal stdlib HTTP JSON call — keeps the client CLI path dependency-free."""
75
+ import json
76
+ import urllib.error
77
+ import urllib.request
78
+ req = urllib.request.Request(url, method=method)
79
+ try:
80
+ with urllib.request.urlopen(req, timeout=timeout) as resp:
81
+ body = resp.read().decode("utf-8")
82
+ return json.loads(body) if body else {}
83
+ except urllib.error.HTTPError as e:
84
+ detail = e.read().decode("utf-8", "replace")[:500]
85
+ raise RuntimeError(f"HTTP {e.code} from {url}: {detail}") from e
86
+ except urllib.error.URLError as e:
87
+ raise RuntimeError(
88
+ f"cannot reach server at {url} ({e.reason}); is `openspeechapi serve` running?"
89
+ ) from e
90
+
91
+
92
+ def _cmd_ps(args: argparse.Namespace) -> None:
93
+ """List engine workers in a running server (state / idle / keepalive)."""
94
+ base = _server_base_url(args)
95
+ try:
96
+ data = _http_json("GET", f"{base}/v1/engines")
97
+ except RuntimeError as e:
98
+ print(str(e), file=sys.stderr)
99
+ sys.exit(1)
100
+ engines = data.get("engines", [])
101
+ if getattr(args, "type", None):
102
+ engines = [e for e in engines if e.get("type") == args.type]
103
+ if getattr(args, "running", False):
104
+ engines = [e for e in engines if str(e.get("state", "")).lower() == "ready"]
105
+ if not engines:
106
+ print("(no engines)")
107
+ return
108
+ rows = [("NAME", "TYPE", "STATE", "IDLE", "KEEPALIVE", "HEALTHY")]
109
+ for e in sorted(engines, key=lambda x: str(x.get("name", ""))):
110
+ idle = e.get("idle_seconds")
111
+ ka = e.get("keepalive") or 0
112
+ rows.append((
113
+ str(e.get("name", "")),
114
+ str(e.get("type", "")),
115
+ str(e.get("state", "")),
116
+ "-" if idle is None else f"{float(idle):.0f}s",
117
+ "off" if not ka else f"{ka}s",
118
+ "yes" if e.get("healthy") else "no",
119
+ ))
120
+ widths = [max(len(r[i]) for r in rows) for i in range(len(rows[0]))]
121
+ for r in rows:
122
+ print(" ".join(c.ljust(widths[i]) for i, c in enumerate(r)))
123
+
124
+
125
+ def _cmd_load(args: argparse.Namespace) -> None:
126
+ """Pre-warm (start) an engine worker in a running server."""
127
+ base = _server_base_url(args)
128
+ try:
129
+ # /start blocks until the worker has loaded the model — can be minutes for big
130
+ # local models (e.g. gemma4 CUDA ~65s), so allow a generous timeout.
131
+ r = _http_json("POST", f"{base}/v1/providers/{args.engine}/start", timeout=600.0)
132
+ except RuntimeError as e:
133
+ print(str(e), file=sys.stderr)
134
+ sys.exit(1)
135
+ print(f"{r.get('engine', args.engine)}: state={r.get('state', '?')} healthy={r.get('healthy')}")
136
+
137
+
138
+ def _cmd_unload(args: argparse.Namespace) -> None:
139
+ """Stop an engine worker (free its GPU/RAM) in a running server."""
140
+ base = _server_base_url(args)
141
+ try:
142
+ r = _http_json("POST", f"{base}/v1/providers/{args.engine}/stop", timeout=60.0)
143
+ except RuntimeError as e:
144
+ print(str(e), file=sys.stderr)
145
+ sys.exit(1)
146
+ print(f"{r.get('engine', args.engine)}: state={r.get('state', '?')} (unloaded)")
147
+
148
+
57
149
  def _runtime_cfg_from_args(args: argparse.Namespace) -> RuntimeConfig:
58
150
  options = {}
59
151
  if getattr(args, "image", None):
@@ -315,6 +407,25 @@ def main(argv: list[str] | None = None) -> None:
315
407
  serve_p.add_argument("--host", default="0.0.0.0", help="Bind host")
316
408
  serve_p.add_argument("--port", type=int, default=8600, help="Bind port")
317
409
 
410
+ # Management CLI — talk to a running `serve` to inspect / unload engine workers.
411
+ ps_p = sub.add_parser(
412
+ "ps", parents=[_cfg_parent],
413
+ help="List engine workers in a running server (state/idle/keepalive)")
414
+ ps_p.add_argument("--url", default=None, help="Server base URL (default http://127.0.0.1:<port>)")
415
+ ps_p.add_argument("--type", choices=["stt", "tts"], default=None, help="Filter by engine type")
416
+ ps_p.add_argument("--running", action="store_true", help="Only show loaded (READY) engines")
417
+
418
+ load_p = sub.add_parser(
419
+ "load", parents=[_cfg_parent], help="Pre-warm an engine worker in a running server")
420
+ load_p.add_argument("engine", help="Engine alias to load")
421
+ load_p.add_argument("--url", default=None, help="Server base URL")
422
+
423
+ unload_p = sub.add_parser(
424
+ "unload", parents=[_cfg_parent],
425
+ help="Stop an engine worker (free its GPU/RAM) in a running server")
426
+ unload_p.add_argument("engine", help="Engine alias to unload")
427
+ unload_p.add_argument("--url", default=None, help="Server base URL")
428
+
318
429
  engine_p = sub.add_parser("engine", help="Manage local engine runtime")
319
430
  engine_sub = engine_p.add_subparsers(dest="engine_cmd", required=True)
320
431
 
@@ -412,6 +523,9 @@ def main(argv: list[str] | None = None) -> None:
412
523
  "list": _cmd_list,
413
524
  "check": _cmd_check,
414
525
  "serve": _cmd_serve,
526
+ "ps": _cmd_ps,
527
+ "load": _cmd_load,
528
+ "unload": _cmd_unload,
415
529
  "engine": _cmd_engine,
416
530
  }
417
531
  commands[args.command](args)
@@ -115,6 +115,11 @@ class ServerConfig:
115
115
  temp_warn_c: float = 80.0
116
116
  temp_critical_c: float = 90.0
117
117
  thermal_guard: bool = True
118
+ # Default idle-unload TTL (seconds) for engine workers that don't set their own
119
+ # ``keepalive``. 0 = stay warm indefinitely (backward-compatible default). Set e.g. 600 on
120
+ # multi-engine / memory-constrained boxes so idle engines free their GPU/RAM after N seconds
121
+ # of inactivity (auto-reloaded on next request). A per-engine ``keepalive > 0`` overrides this.
122
+ default_keepalive: int = 0
118
123
 
119
124
 
120
125
  @dataclass
@@ -262,11 +267,23 @@ def load_config(path: Path) -> OpenSpeechConfig:
262
267
  except (TypeError, ValueError):
263
268
  pass
264
269
  server_cfg.thermal_guard = bool(srv.get("thermal_guard", server_cfg.thermal_guard))
270
+ try:
271
+ server_cfg.default_keepalive = max(
272
+ 0, int(srv.get("default_keepalive", server_cfg.default_keepalive)))
273
+ except (TypeError, ValueError):
274
+ pass
265
275
  auth = srv.get("auth", {})
266
276
  if auth:
267
277
  server_cfg.auth_enabled = bool(auth.get("enabled", False))
268
278
  server_cfg.api_keys = list(auth.get("api_keys", []))
269
279
 
280
+ # Engines that didn't set their own keepalive inherit the global default (so operators can
281
+ # set one idle-unload policy via server.default_keepalive instead of per-engine).
282
+ if server_cfg.default_keepalive > 0:
283
+ for eng in engines.values():
284
+ if eng.keepalive == 0:
285
+ eng.keepalive = server_cfg.default_keepalive
286
+
270
287
  return OpenSpeechConfig(
271
288
  engines=engines,
272
289
  providers=cred_providers,
@@ -365,6 +365,8 @@ class ServiceDispatcher:
365
365
  "exec_mode": str, # "remote" | "local" | "in_process" | ...
366
366
  "exec_mode_desc": str, # human-readable exec_mode
367
367
  "display_info": dict, # key settings (model, voice, ...)
368
+ "idle_seconds": float, # since last use (None unless loaded/READY)
369
+ "keepalive": int, # idle-unload TTL in seconds (0 = stays warm)
368
370
  }
369
371
  """
370
372
  from openspeechapi.engine_catalog import derive_category, get_catalog_entry
@@ -440,6 +442,7 @@ class ServiceDispatcher:
440
442
  "exec_mode": exec_mode_value,
441
443
  "exec_mode_desc": _exec_mode_desc(exec_mode_value),
442
444
  "display_info": display_info,
445
+ **self._lifecycle.runtime_info(name), # idle_seconds + keepalive (for `ps`)
443
446
  })
444
447
 
445
448
  return result
@@ -7,6 +7,7 @@ import enum
7
7
  import importlib
8
8
  import os
9
9
  import pickle
10
+ import signal
10
11
  import struct
11
12
  import sys
12
13
  import tempfile
@@ -341,8 +342,32 @@ async def _with_download_progress(coro, provider: Any = None):
341
342
  # Worker process entry point
342
343
  # ---------------------------------------------------------------------------
343
344
 
345
+ def _set_parent_death_signal() -> None:
346
+ """Linux: ask the kernel to SIGKILL this worker the moment its parent (the server) dies,
347
+ so a hard-killed (``kill -9``) or crashed server never leaks orphaned worker processes
348
+ still pinning GPU/RAM. No-op off Linux — macOS/Windows have no equivalent; there the
349
+ server's graceful shutdown reaps workers via ``executor.stop`` (terminate/kill).
350
+
351
+ Race-safe: PDEATHSIG fires only on *future* parent death, so if the parent already exited
352
+ during the spawn window we'd miss it — we detect that via reparenting (``getppid()`` no
353
+ longer the original parent) and exit immediately."""
354
+ if sys.platform != "linux":
355
+ return
356
+ parent_pid = os.getppid()
357
+ try:
358
+ import ctypes
359
+ PR_SET_PDEATHSIG = 1
360
+ if ctypes.CDLL("libc.so.6", use_errno=True).prctl(PR_SET_PDEATHSIG, signal.SIGKILL) != 0:
361
+ return
362
+ if os.getppid() != parent_pid: # parent died before prctl took effect → don't orphan
363
+ os._exit(0)
364
+ except Exception: # best-effort; never block worker startup on this
365
+ pass
366
+
367
+
344
368
  def _worker_main(provider_pickle: bytes, socket_path: str) -> None:
345
369
  """Entry point for the worker subprocess. Runs the provider and serves IPC requests."""
370
+ _set_parent_death_signal() # auto-die if the server dies (no orphaned GPU/RAM); Linux-only
346
371
  asyncio.run(_worker_serve(provider_pickle, socket_path))
347
372
 
348
373
 
@@ -57,6 +57,19 @@ class ProviderLifecycleManager:
57
57
  entry = self._entries.get(name)
58
58
  return entry.state if entry else None
59
59
 
60
+ def runtime_info(self, name: str) -> dict:
61
+ """Idle time + effective keepalive for a provider (for `ps`-style listings).
62
+
63
+ ``idle_seconds`` is None unless the provider is currently READY (loaded); ``keepalive``
64
+ is the resolved idle-unload TTL (0 = stays warm)."""
65
+ entry = self._entries.get(name)
66
+ if entry is None:
67
+ return {"idle_seconds": None, "keepalive": 0}
68
+ idle = None
69
+ if entry.state == ProviderState.READY and entry.last_used > 0:
70
+ idle = round(time.monotonic() - entry.last_used, 1)
71
+ return {"idle_seconds": idle, "keepalive": entry.keepalive}
72
+
60
73
  def list_states(self) -> dict[str, str]:
61
74
  return {name: entry.state.value for name, entry in self._entries.items()}
62
75
 
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "openspeechapi"
7
- version = "0.2.18"
7
+ version = "0.2.20"
8
8
  description = "Unified speech interface for STT/TTS providers"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.11"
File without changes