openspeechapi 0.2.26__tar.gz → 0.3.0__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 (169) hide show
  1. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/PKG-INFO +1 -3
  2. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/core/base.py +59 -0
  3. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/core/model_hub.py +13 -3
  4. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/core/models.py +5 -0
  5. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/dispatch/aim_provision.py +59 -2
  6. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/dispatch/dispatcher.py +94 -10
  7. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/dispatch/executors/subprocess_exec.py +27 -0
  8. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/dispatch/lifecycle.py +49 -0
  9. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/engine_catalog.py +4 -0
  10. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/engine_registry.yaml +9 -4
  11. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/local_engines/aim_resolver.py +12 -0
  12. openspeechapi-0.3.0/openspeechapi/local_engines/cosyvoice_venv.py +409 -0
  13. openspeechapi-0.3.0/openspeechapi/local_engines/fish_venv.py +192 -0
  14. openspeechapi-0.3.0/openspeechapi/providers/tts/cosyvoice.py +357 -0
  15. openspeechapi-0.3.0/openspeechapi/providers/tts/fish_speech.py +386 -0
  16. openspeechapi-0.3.0/openspeechapi/providers/tts/piper.py +315 -0
  17. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/server/app.py +7 -1
  18. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/server/model_downloads.py +77 -16
  19. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/server/routes/management.py +154 -41
  20. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/server/routes/stt.py +5 -2
  21. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/server/routes/tts.py +53 -0
  22. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/server/webui/app.js +122 -5
  23. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/server/webui/index.html +11 -0
  24. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/server/ws/tts_stream.py +34 -0
  25. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/providers.example.yaml +4 -2
  26. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/pyproject.toml +5 -2
  27. openspeechapi-0.2.26/openspeechapi/providers/tts/cosyvoice.py +0 -113
  28. openspeechapi-0.2.26/openspeechapi/providers/tts/fish_speech.py +0 -158
  29. openspeechapi-0.2.26/openspeechapi/providers/tts/piper.py +0 -149
  30. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/.gitignore +0 -0
  31. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/README.md +0 -0
  32. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/__init__.py +0 -0
  33. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/__main__.py +0 -0
  34. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/cli.py +0 -0
  35. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/client/__init__.py +0 -0
  36. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/client/client.py +0 -0
  37. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/config.py +0 -0
  38. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/core/__init__.py +0 -0
  39. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/core/enums.py +0 -0
  40. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/core/registry.py +0 -0
  41. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/core/settings.py +0 -0
  42. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/demo.py +0 -0
  43. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/dispatch/__init__.py +0 -0
  44. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/dispatch/context.py +0 -0
  45. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/dispatch/executors/__init__.py +0 -0
  46. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/dispatch/executors/base.py +0 -0
  47. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/dispatch/executors/in_process.py +0 -0
  48. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/dispatch/executors/remote.py +0 -0
  49. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/dispatch/fanout.py +0 -0
  50. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/dispatch/filters.py +0 -0
  51. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/dispatch/watcher.py +0 -0
  52. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/exceptions.py +0 -0
  53. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/factory.py +0 -0
  54. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/local_engines/__init__.py +0 -0
  55. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/local_engines/backends/__init__.py +0 -0
  56. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/local_engines/backends/docker_backend.py +0 -0
  57. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/local_engines/backends/native_backend.py +0 -0
  58. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/local_engines/base.py +0 -0
  59. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/local_engines/engines/__init__.py +0 -0
  60. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/local_engines/engines/faster_whisper.py +0 -0
  61. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/local_engines/engines/fish_speech.py +0 -0
  62. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/local_engines/engines/sherpa_onnx.py +0 -0
  63. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/local_engines/engines/whisper.py +0 -0
  64. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/local_engines/engines/whisperlivekit.py +0 -0
  65. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/local_engines/isolated_venv.py +0 -0
  66. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/local_engines/manager.py +0 -0
  67. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/local_engines/models.py +0 -0
  68. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/local_engines/progress.py +0 -0
  69. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/local_engines/registry.py +0 -0
  70. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/local_engines/task_store.py +0 -0
  71. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/local_engines/tasks.py +0 -0
  72. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/local_engines/vllm_gb10_patch.py +0 -0
  73. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/local_engines/vllm_venv.py +0 -0
  74. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/logging_config.py +0 -0
  75. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/observe/__init__.py +0 -0
  76. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/observe/base.py +0 -0
  77. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/observe/debug.py +0 -0
  78. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/observe/latency.py +0 -0
  79. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/observe/metrics.py +0 -0
  80. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/observe/tracing.py +0 -0
  81. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/observe/usage.py +0 -0
  82. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/providers/__init__.py +0 -0
  83. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/providers/_template.py +0 -0
  84. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/providers/stt/__init__.py +0 -0
  85. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/providers/stt/_local_audio.py +0 -0
  86. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/providers/stt/alibaba.py +0 -0
  87. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/providers/stt/assemblyai.py +0 -0
  88. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/providers/stt/azure_speech.py +0 -0
  89. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/providers/stt/baidu.py +0 -0
  90. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/providers/stt/canary_qwen_stt.py +0 -0
  91. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/providers/stt/deepgram.py +0 -0
  92. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/providers/stt/dolphin_stt.py +0 -0
  93. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/providers/stt/elevenlabs.py +0 -0
  94. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/providers/stt/faster_whisper.py +0 -0
  95. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/providers/stt/fireredasr_stt.py +0 -0
  96. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/providers/stt/funasr_stt.py +0 -0
  97. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/providers/stt/gemma4.py +0 -0
  98. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/providers/stt/google_cloud.py +0 -0
  99. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/providers/stt/iflytek.py +0 -0
  100. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/providers/stt/kimi_audio_stt.py +0 -0
  101. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/providers/stt/macos_speech.py +0 -0
  102. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/providers/stt/mlx_whisper_stt.py +0 -0
  103. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/providers/stt/mms_languages.json +0 -0
  104. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/providers/stt/mms_stt.py +0 -0
  105. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/providers/stt/moonshine_stt.py +0 -0
  106. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/providers/stt/openai.py +0 -0
  107. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/providers/stt/paraformer.py +0 -0
  108. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/providers/stt/parakeet_mlx_stt.py +0 -0
  109. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/providers/stt/phi4_multimodal_stt.py +0 -0
  110. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/providers/stt/qwen3_asr.py +0 -0
  111. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/providers/stt/qwen3_omni_stt.py +0 -0
  112. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/providers/stt/sensevoice.py +0 -0
  113. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/providers/stt/sherpa_onnx.py +0 -0
  114. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/providers/stt/tencent.py +0 -0
  115. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/providers/stt/volcengine.py +0 -0
  116. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/providers/stt/vosk_stt.py +0 -0
  117. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/providers/stt/voxtral_stt.py +0 -0
  118. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/providers/stt/wenet_stt.py +0 -0
  119. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/providers/stt/whisper.py +0 -0
  120. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/providers/stt/whisperlivekit.py +0 -0
  121. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/providers/stt/windows_speech.py +0 -0
  122. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/providers/tts/__init__.py +0 -0
  123. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/providers/tts/alibaba.py +0 -0
  124. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/providers/tts/azure_speech.py +0 -0
  125. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/providers/tts/baidu.py +0 -0
  126. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/providers/tts/coqui.py +0 -0
  127. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/providers/tts/deepgram.py +0 -0
  128. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/providers/tts/elevenlabs.py +0 -0
  129. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/providers/tts/google_cloud.py +0 -0
  130. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/providers/tts/iflytek.py +0 -0
  131. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/providers/tts/macos_say.py +0 -0
  132. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/providers/tts/minimax.py +0 -0
  133. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/providers/tts/openai.py +0 -0
  134. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/providers/tts/tencent.py +0 -0
  135. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/providers/tts/volcengine.py +0 -0
  136. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/providers/tts/windows_sapi.py +0 -0
  137. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/server/__init__.py +0 -0
  138. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/server/auth.py +0 -0
  139. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/server/extras_installer.py +0 -0
  140. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/server/middleware.py +0 -0
  141. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/server/native_installer.py +0 -0
  142. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/server/routes/__init__.py +0 -0
  143. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/server/routes/webui.py +0 -0
  144. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/server/system_metrics.py +0 -0
  145. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/server/webui/styles.css +0 -0
  146. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/server/ws/__init__.py +0 -0
  147. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/server/ws/stt_stream.py +0 -0
  148. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/telemetry/__init__.py +0 -0
  149. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/telemetry/perf.py +0 -0
  150. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/utils/__init__.py +0 -0
  151. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/utils/audio_converter.py +0 -0
  152. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/utils/audio_playback.py +0 -0
  153. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/openspeechapi/vendor_registry.yaml +0 -0
  154. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/scripts/aim_adopt.py +0 -0
  155. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/scripts/aim_consumers.py +0 -0
  156. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/scripts/engines/cloud/install.sh +0 -0
  157. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/scripts/engines/faster-whisper/native/install.sh +0 -0
  158. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/scripts/engines/fish-speech/native/install.sh +0 -0
  159. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/scripts/engines/macos-stt/_bundle.sh +0 -0
  160. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/scripts/engines/macos-stt/install.sh +0 -0
  161. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/scripts/engines/macos-stt/macos_stt.swift +0 -0
  162. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/scripts/engines/macos-stt/request_auth.swift +0 -0
  163. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/scripts/engines/sherpa-onnx/native/install.sh +0 -0
  164. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/scripts/engines/sherpa-onnx/native/run_streaming_server.py +0 -0
  165. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/scripts/engines/whisper/native/install.sh +0 -0
  166. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/scripts/engines/whisperlivekit/native/install.sh +0 -0
  167. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/scripts/gen_mms_languages.py +0 -0
  168. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/scripts/preload_stt_model.py +0 -0
  169. {openspeechapi-0.2.26 → openspeechapi-0.3.0}/scripts/release.sh +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: openspeechapi
3
- Version: 0.2.26
3
+ Version: 0.3.0
4
4
  Summary: Unified speech interface for STT/TTS providers
5
5
  Requires-Python: >=3.11
6
6
  Requires-Dist: httpx>=0.27
@@ -36,8 +36,6 @@ Provides-Extra: cloud
36
36
  Requires-Dist: websockets; extra == 'cloud'
37
37
  Provides-Extra: coqui-tts
38
38
  Requires-Dist: coqui-tts[codec,cpu]; extra == 'coqui-tts'
39
- Provides-Extra: cosyvoice-tts
40
- Requires-Dist: torchaudio; extra == 'cosyvoice-tts'
41
39
  Provides-Extra: deepgram
42
40
  Requires-Dist: websockets; extra == 'deepgram'
43
41
  Provides-Extra: deepgram-stt
@@ -81,6 +81,15 @@ class SpeechProvider(ABC):
81
81
  # _effective_settings). When True the Lab "Advanced Options" panel renders a
82
82
  # dynamic control for each overridable setting. Default False (legacy).
83
83
  supports_param_overrides: bool = False
84
+ # Optional fail-fast guard for subprocess/local engines whose SDK is NOT pip-
85
+ # installable from a pyproject extra (e.g. a git-clone-only SDK). Set to the
86
+ # importable top-level module name that MUST be present for this provider to
87
+ # run (e.g. "cosyvoice"). When set, the lifecycle does a lightweight
88
+ # ``importlib.util.find_spec`` name-presence check (NO import / no heavy load)
89
+ # in the server process BEFORE spawning the worker — a missing module fails
90
+ # fast with a clear error instead of spawning a worker that blocks until the
91
+ # (long, model-load-appropriate) start timeout. None (default) = no pre-check.
92
+ required_import: str | None = None
84
93
 
85
94
  def aim_model_spec(self) -> "AimModelSpec | None":
86
95
  """Override to let ``aim`` (ai-model-manager) download + manage this model.
@@ -94,6 +103,38 @@ class SpeechProvider(ABC):
94
103
  """
95
104
  return None
96
105
 
106
+ @staticmethod
107
+ def local_model_present(settings) -> bool | None: # noqa: ANN001
108
+ """该 config 的模型权重是否已在本机(用于「是否已下载」预检的**非标准**判定)。
109
+
110
+ 默认返回 ``None`` —— 表示「按标准 repo/aim 流程判断」(交回 ``expected_local_repo`` +
111
+ ``model_is_cached`` / aim store 检测)。**仅当**引擎走非标准的部分下载(典型:piper 从
112
+ 10.9GB 单仓只取某 voice 的 2 个文件,``expected_local_repo`` 给不出可整仓校验的 id)
113
+ 才 override,直接报告**本 config** 的权重是否齐备。
114
+
115
+ 与 ``expected_local_repo`` 同纪律:在 **server 进程** 调用 → 纯字符串/文件存在性逻辑,
116
+ 绝不 import torch/transformers/mlx、绝不加载模型、绝不触发下载。``settings`` 可能是
117
+ dataclass 实例或 dict。任何不确定 → 返回 ``None``(放行,交标准流程)。返回 ``True``/
118
+ ``False`` 时,预检以此为准、不再走 repo/aim 判断。"""
119
+ return None
120
+
121
+ @staticmethod
122
+ def download_spec(settings) -> dict | None: # noqa: ANN001
123
+ """该引擎「下载模型」按钮触发的**部分 snapshot 下载**描述,默认 ``None``。
124
+
125
+ 走 aim 纳管的引擎用 ``aim_model_spec()``;无法 aim 纳管、又需从一个大仓只取若干文件
126
+ 的引擎(典型:piper —— aim 无「部分仓/多文件」下载能力,``AimModelSpec`` 是单源)
127
+ override 本方法,返回::
128
+
129
+ {"repo": "<hf repo>", "allow_patterns": ["<glob>", ...], "label": "<str>"}
130
+
131
+ ``repo`` 为 HF 仓库 id;``allow_patterns`` 为只下这几个文件的 glob;``label`` 用于区分
132
+ 同仓不同目标(如不同 voice)的下载任务。被「下载模型」按钮 + 进度面板使用。
133
+
134
+ 同 ``expected_local_repo`` 纪律:server 进程内调用,纯字符串逻辑、不加载模型、不下载。
135
+ ``settings`` 可能是 dataclass 实例或 dict。无可下载目标 → ``None``。"""
136
+ return None
137
+
97
138
  @classmethod
98
139
  def expected_local_repo(cls, settings) -> str | None: # noqa: ANN001
99
140
  """该引擎在本机会从本地缓存加载的 HF repo id(用于「是否已下载」预检)。
@@ -249,3 +290,21 @@ class TTSProvider(SpeechProvider):
249
290
  async def list_voices(self) -> list[dict]:
250
291
  """Return available voices. Override in subclass to provide voice list."""
251
292
  return []
293
+
294
+ @classmethod
295
+ def static_voices(cls, model: str | None = None) -> list[dict] | None:
296
+ """Preset voices ({id, name}) for *model* WITHOUT loading it — the load-free fast path for
297
+ the Voice dropdown (CLAUDE.md 铁律: listing voices must NOT load a multi-GB model).
298
+
299
+ Return value is a SENTINEL the dispatcher uses to decide whether to load:
300
+ • ``None`` (default) — this provider can't answer statically; its speakers are only
301
+ knowable from the LOADED model (coqui/piper/fish). The dispatcher falls back to
302
+ load+invoke.
303
+ • a ``list`` (possibly EMPTY) — an AUTHORITATIVE answer: use it as-is, NEVER load. A
304
+ provider whose preset set is fully determined by the model id (e.g. cosyvoice: SFT/
305
+ Instruct → 7 presets; zero-shot 0.5B / base → ``[]``) returns this so switching models
306
+ is instant AND a genuinely preset-less model doesn't waste a load just to return ``[]``.
307
+
308
+ Override to return a list. Must stay import-light (no torch): it runs in the server process
309
+ off ``provider_cls`` with no instance/model."""
310
+ return None
@@ -364,12 +364,22 @@ def _hf_local(repo: str) -> str | None:
364
364
 
365
365
 
366
366
  def _ms_local(repo: str) -> str | None:
367
- """Path to an already-downloaded ModelScope snapshot of ``repo`` (no network), or None.
368
- Checks our storage root and the default modelscope cache."""
367
+ """Path to an already-downloaded **complete** ModelScope snapshot of ``repo`` (no network),
368
+ or None. Checks our storage root and the default modelscope cache.
369
+
370
+ Requires ModelScope's completion marker ``.mv`` (``MODEL_VERSION_FILE_NAME``), which
371
+ ``snapshot_download`` writes via ``save_model_version()`` ONLY after every file has finished
372
+ (modelscope/hub/snapshot_download.py — the call is AFTER ``_download_file_lists``). So an
373
+ interrupted/partial snapshot (files present but no ``.mv``) is treated as absent — the
374
+ ModelScope analogue of ``_hf_snapshot_complete``'s ``*.incomplete`` check. Without this a
375
+ half-finished ms download (e.g. cosyvoice with llm/flow/hift .pt but the .onnx tokenizer
376
+ missing) masqueraded as cached → the download gate 放行'd it → the worker loaded a broken model
377
+ (ONNX NO_SUCHFILE) or silently re-downloaded inline (which froze the WebUI). NOTE: the per-file
378
+ ``.msc`` index is written incrementally and is NOT a completeness signal; only ``.mv`` is."""
369
379
  for base in (os.path.join(default_storage_root(), "modelscope"),
370
380
  os.path.expanduser("~/.cache/modelscope/hub")):
371
381
  d = os.path.join(base, *repo.split("/"))
372
- if os.path.isdir(d) and os.listdir(d):
382
+ if os.path.isdir(d) and os.path.exists(os.path.join(d, ".mv")):
373
383
  return d
374
384
  return None
375
385
 
@@ -99,4 +99,9 @@ class TTSOptions:
99
99
  # voice cloning (XTTS / F5 / GPT-SoVITS / CosyVoice2 …): the speaker to clone — raw audio
100
100
  # bytes, base64, OR a local path/URL. Ignored by preset-voice engines.
101
101
  reference_audio: bytes | str | None = None
102
+ # Transcript of reference_audio (what the clip SAYS), PAIRED with this request's clip. Set →
103
+ # zero-shot cloning aligns to it (most accurate); absent → transcript-free cross-lingual clone.
104
+ # Per-request ONLY — must NOT be filled from a static engine setting: a stale/mismatched config
105
+ # transcript garbles the clone output (the cosyvoice '合成的语音不是输入的文本' bug).
106
+ reference_text: str | None = None
102
107
  language: str | None = None # cloning engines need an explicit lang code (e.g. "zh", "en")
@@ -11,13 +11,19 @@ See the "模型下载与管理(aim 集成)" rule in CLAUDE.md.
11
11
  from __future__ import annotations
12
12
 
13
13
  import dataclasses
14
+ import time
14
15
  from pathlib import Path
15
16
  from typing import Any
16
17
 
17
18
  import yaml
18
19
 
19
20
  from openspeechapi.core.settings import BaseSettings
20
- from openspeechapi.local_engines.aim_resolver import aim_available, aim_ensure_model
21
+ from openspeechapi.local_engines.aim_resolver import (
22
+ aim_available,
23
+ aim_ensure_model,
24
+ aim_has_model,
25
+ )
26
+ from openspeechapi.local_engines.models import TaskStatus
21
27
  from openspeechapi.logging_config import logger
22
28
 
23
29
 
@@ -60,11 +66,45 @@ def _persist_model_path(config_path: Path, engine_name: str, path: str) -> None:
60
66
  logger.warning("aim: failed to persist model_path for {}: {}", engine_name, exc)
61
67
 
62
68
 
69
+ def _tracked_aim_ensure(spec: Any, downloads: Any) -> str | None:
70
+ """Ensure ``spec``'s model via the server's ModelDownloadManager (so the download is a
71
+ TRACKED task visible in the WebUI progress panel), blocking until it finishes.
72
+
73
+ Mirrors :func:`aim_ensure_model` but routes the actual ``aim download`` through the
74
+ manager instead of calling the aim CLI directly: resolve first (already there → no
75
+ download); if missing, ``manager.start_aim`` (de-duped — reuses an in-flight task, e.g.
76
+ one the user kicked off from the panel) and poll until the task is terminal, then
77
+ re-resolve to the loadable path. Returns None (caller falls back) if the download fails
78
+ or aim can't provide a usable path."""
79
+ from openspeechapi.local_engines.aim_resolver import _aim_resolve, _loadable_path
80
+ if aim_has_model(spec.model_id):
81
+ return _loadable_path(_aim_resolve(spec.model_id))
82
+ task = downloads.start_aim(
83
+ source=spec.source, model_id=spec.model_id, category=spec.category,
84
+ )
85
+ # Block until the tracked download finishes — the provider needs the weights present
86
+ # before its service starts. The manager bounds the download by its own wall-clock
87
+ # timeout, so this poll terminates even if aim hangs.
88
+ terminal = (TaskStatus.SUCCEEDED, TaskStatus.FAILED, TaskStatus.CANCELLED)
89
+ while True:
90
+ cur = downloads.get(task.task_id)
91
+ if cur is None or cur.status in terminal:
92
+ break
93
+ time.sleep(1.0)
94
+ if cur is None or cur.status != TaskStatus.SUCCEEDED:
95
+ logger.warning(
96
+ "aim: tracked download for model '{}' did not succeed (status={}) — falling back",
97
+ spec.model_id, getattr(cur, "status", None))
98
+ return None
99
+ return _loadable_path(_aim_resolve(spec.model_id))
100
+
101
+
63
102
  def provision_aim_model(
64
103
  engine_name: str,
65
104
  provider_cls: Any,
66
105
  settings_dict: dict,
67
106
  config_path: Path | None,
107
+ downloads: Any | None = None,
68
108
  ) -> dict:
69
109
  """Return ``settings_dict`` with ``model_path`` set to the aim-resolved path.
70
110
 
@@ -72,6 +112,12 @@ def provision_aim_model(
72
112
  already provisioned and still on disk, the provider declares no aim spec, or
73
113
  aim fails to provide a path. On success the path is also persisted to
74
114
  ``providers.yaml`` so it survives restarts and aim uninstallation.
115
+
116
+ ``downloads`` (the server's ModelDownloadManager, duck-typed) is optional: when
117
+ supplied AND the model is missing, the download runs as a TRACKED task through it so
118
+ it appears in the WebUI progress panel (the lazy / synth-triggered path); it still
119
+ blocks until the weights are present. When None (library API, tests) the download
120
+ goes directly via the aim CLI as before.
75
121
  """
76
122
  if not aim_available():
77
123
  return settings_dict
@@ -82,7 +128,18 @@ def provision_aim_model(
82
128
  spec = _provider_aim_spec(provider_cls, settings_dict)
83
129
  if spec is None:
84
130
  return settings_dict
85
- path = aim_ensure_model(spec)
131
+ # With an injected manager, download as a tracked task (visible in the panel); without
132
+ # one, fall back to the direct aim CLI. A tracked-path failure also falls back, so the
133
+ # provider still gets a shot at its own download.
134
+ path = None
135
+ if downloads is not None:
136
+ try:
137
+ path = _tracked_aim_ensure(spec, downloads)
138
+ except Exception as exc: # noqa: BLE001 - tracked path is best-effort; fall back to CLI
139
+ logger.warning("aim: tracked provision failed for '{}': {} — falling back to aim CLI",
140
+ engine_name, exc)
141
+ if not path:
142
+ path = aim_ensure_model(spec)
86
143
  if not path:
87
144
  return settings_dict
88
145
  logger.info("aim: provisioned model for engine '{}' → {}", engine_name, path)
@@ -20,7 +20,7 @@ from openspeechapi.dispatch.executors.remote import RemoteExecutor
20
20
  from openspeechapi.dispatch.executors.subprocess_exec import SubprocessExecutor
21
21
  from openspeechapi.utils.audio_converter import AudioConverter
22
22
  from openspeechapi.dispatch.fanout import FirstCompleted, MergeStrategy, fan_out
23
- from openspeechapi.dispatch.lifecycle import ProviderLifecycleManager
23
+ from openspeechapi.dispatch.lifecycle import ProviderLifecycleManager, ProviderState
24
24
  from openspeechapi.exceptions import ProviderNotFoundError
25
25
  from openspeechapi.logging_config import bind_context
26
26
  from openspeechapi.observe.base import DispatchObserver, ObserverManager
@@ -169,9 +169,19 @@ class ServiceDispatcher:
169
169
  self._observer_mgr = ObserverManager()
170
170
  self._lifecycle = ProviderLifecycleManager()
171
171
  self._config_path: Any = None # set by from_config/reload_config for aim provisioning
172
+ self._model_downloads: Any = None # injected by the server so lazy aim provisioning is tracked
172
173
  self.stt = _STTNamespace(self)
173
174
  self.tts = _TTSNamespace(self)
174
175
 
176
+ def set_model_downloads(self, manager: Any) -> None:
177
+ """Inject the server's ModelDownloadManager (duck-typed) so a synth-triggered (lazy)
178
+ aim provision registers its download with it → the WebUI progress panel shows it.
179
+
180
+ Optional: when unset (library API, tests), aim provisioning downloads directly via the
181
+ aim CLI as before. Forwarded to the lifecycle manager, which runs the provisioning."""
182
+ self._model_downloads = manager
183
+ self._lifecycle.set_model_downloads(manager)
184
+
175
185
  # ------------------------------------------------------------------
176
186
  # Factory
177
187
  # ------------------------------------------------------------------
@@ -237,6 +247,7 @@ class ServiceDispatcher:
237
247
  self._shared_http_client = httpx.AsyncClient(timeout=60.0)
238
248
  self._lifecycle.set_shared_http_client(self._shared_http_client)
239
249
  self._lifecycle.set_config_path(self._config_path)
250
+ self._lifecycle.set_model_downloads(self._model_downloads)
240
251
 
241
252
  for handle in self._handles.values():
242
253
  self._lifecycle.register(handle.name, handle, handle.keepalive)
@@ -335,9 +346,9 @@ class ServiceDispatcher:
335
346
 
336
347
  # Display-friendly settings keys extracted for UI display_info
337
348
  _DISPLAY_INFO_KEYS = (
338
- "model", "model_size", "model_name", "voice", "voice_id", "voice_type",
339
- "voice_name", "language", "engine_type", "dev_pid", "base_url", "region",
340
- "api_url", "cluster",
349
+ "model", "model_size", "model_name", "weights_repo", "voice", "voice_id",
350
+ "voice_type", "voice_name", "language", "engine_type", "dev_pid", "base_url",
351
+ "region", "api_url", "cluster",
341
352
  )
342
353
 
343
354
  def list_engines_info(self, *, engine_type: str | None = None) -> list[dict]:
@@ -488,6 +499,42 @@ class ServiceDispatcher:
488
499
  except Exception: # noqa: BLE001 - 预检取 repo 失败 → 当作无法判断,放行
489
500
  return None
490
501
 
502
+ def _settings_for(self, alias: str) -> dict | None:
503
+ """The configured settings dict for *alias* (the dict the provider class's
504
+ string-only hooks read), or None if the engine is unknown. Used by the
505
+ ``local_model_present`` / ``download_spec`` delegators below."""
506
+ handle = self._handles.get(alias)
507
+ if handle is None:
508
+ return None
509
+ settings = getattr(handle, "settings_dict", None)
510
+ if settings is None:
511
+ settings = getattr(handle, "settings", None) or {}
512
+ return settings
513
+
514
+ def local_model_present(self, alias: str) -> bool | None:
515
+ """委托给 provider 类的 ``local_model_present`` —— 仅当引擎走**非标准**部分下载
516
+ (如 piper)才返回 True/False,否则 None(交标准 repo/aim 判断)。纯字符串/文件
517
+ 存在性逻辑、不加载模型;任何异常/找不到 → None(best-effort,绝不阻塞引擎列表)。"""
518
+ handle = self._handles.get(alias)
519
+ if handle is None:
520
+ return None
521
+ try:
522
+ return handle.provider_cls.local_model_present(self._settings_for(alias) or {})
523
+ except Exception: # noqa: BLE001 - best-effort 预检,失败当作「无法判断」
524
+ return None
525
+
526
+ def download_spec(self, alias: str) -> dict | None:
527
+ """委托给 provider 类的 ``download_spec`` —— 返回 ``{repo, allow_patterns, label}``
528
+ 的部分 snapshot 下载描述(piper 等无法 aim 纳管、需从大仓只取若干文件的引擎),
529
+ 否则 None。纯字符串逻辑、不加载模型;任何异常/找不到 → None(best-effort)。"""
530
+ handle = self._handles.get(alias)
531
+ if handle is None:
532
+ return None
533
+ try:
534
+ return handle.provider_cls.download_spec(self._settings_for(alias) or {})
535
+ except Exception: # noqa: BLE001 - best-effort,失败当作「无部分下载」
536
+ return None
537
+
491
538
  async def _negotiate_audio_format(
492
539
  self, handle: "_ProviderHandle", audio: AudioData
493
540
  ) -> AudioData:
@@ -620,16 +667,42 @@ class ServiceDispatcher:
620
667
  # ------------------------------------------------------------------
621
668
 
622
669
  async def list_voices(self, provider: str, model: str | None = None) -> list[dict]:
623
- """Built-in voices of a provider's loaded model, fetched via the executor's invoke path so
624
- it works for ALL exec modes — SUBPROCESS included (lifecycle.get_instance() returns None
625
- there, so a direct instance.list_voices() always yielded [] for e.g. coqui). The model is
626
- lazily loaded first (its speakers can only be enumerated once the model is loaded)."""
670
+ """Built-in voices of a provider's model, fetched via the executor's invoke path so it works
671
+ for ALL exec modes — SUBPROCESS included (lifecycle.get_instance() returns None there, so a
672
+ direct instance.list_voices() always yielded [] for e.g. coqui).
673
+
674
+ CLAUDE.md 铁律: listing voices must NOT load a multi-GB model. So when the engine is NOT
675
+ already loaded, first try the provider's load-free ``static_voices()``: an AUTHORITATIVE
676
+ answer (a list — possibly EMPTY — e.g. cosyvoice SFT/Instruct → presets, zero-shot → [])
677
+ is returned in-process without starting the worker, so switching models in the Lab is
678
+ instant (and a preset-less model doesn't waste a load just to return []). Only ``None``
679
+ (coqui/piper/fish, whose speakers need the loaded model) falls back to loading + invoke.
680
+ When the engine IS loaded, always invoke so ``list_available_spks()`` wins."""
627
681
  handle = self._get_handle(provider)
682
+ if self._lifecycle.get_state(provider) != ProviderState.READY:
683
+ try:
684
+ eff_model = model or (getattr(handle, "settings_dict", {}) or {}).get("model")
685
+ static = handle.provider_cls.static_voices(eff_model)
686
+ except Exception: # noqa: BLE001 - static hint is best-effort; fall back to load+invoke
687
+ static = None
688
+ if static is not None: # authoritative (even []) → never load to list voices
689
+ return list(static)
628
690
  await self._lifecycle.ensure_ready(provider)
629
691
  result = await handle.executor.invoke("list_voices", **({"model": model} if model else {}))
630
692
  self._lifecycle.touch(provider)
631
693
  return list(result or [])
632
694
 
695
+ async def add_reference(self, provider: str, voice_id: str, audio, text: str) -> dict:
696
+ """Register a named reference voice on a provider (e.g. fish-speech ``/v1/references/add``)
697
+ via the executor invoke path. Lets the Lab register a cloned voice once and reuse it by
698
+ ``reference_id`` thereafter."""
699
+ handle = self._get_handle(provider)
700
+ await self._lifecycle.ensure_ready(provider)
701
+ result = await handle.executor.invoke(
702
+ "add_reference", voice_id=voice_id, audio=audio, text=text)
703
+ self._lifecycle.touch(provider)
704
+ return dict(result or {})
705
+
633
706
  async def _synthesize(
634
707
  self,
635
708
  provider: str,
@@ -752,9 +825,20 @@ class ServiceDispatcher:
752
825
  # ------------------------------------------------------------------
753
826
 
754
827
  async def health(self) -> dict[str, bool]:
755
- """Return health status for all configured providers."""
828
+ """Return health status for all configured providers.
829
+
830
+ Each check is BOUNDED (2s): a busy/slow worker (an invoke in flight — e.g. a long model
831
+ load/download holds the executor's _io_lock) must not hang the whole endpoint. /v1/health
832
+ AND /v1/engines both call this, so an unbounded check froze the entire WebUI when a worker
833
+ was mid-download. A timeout here is safe — the check is blocked *waiting to acquire* the
834
+ lock (nothing sent on the wire yet), so cancelling it can't desync the IPC protocol."""
835
+ async def _bounded(h: Any) -> bool:
836
+ try:
837
+ return bool(await asyncio.wait_for(h.executor.health_check(), timeout=2.0))
838
+ except Exception: # noqa: BLE001 - timeout / transport error → treat as not-healthy-now
839
+ return False
756
840
  results = await asyncio.gather(
757
- *[h.executor.health_check() for h in self._handles.values()],
841
+ *[_bounded(h) for h in self._handles.values()],
758
842
  return_exceptions=True,
759
843
  )
760
844
  return {
@@ -41,6 +41,25 @@ _PROXY_ENV_KEYS = (
41
41
  "all_proxy",
42
42
  )
43
43
 
44
+ # System bin dirs a login/GUI shell has but a `nohup`/`setsid`/launchd-launched server may
45
+ # NOT inherit — so a worker subprocess (which copies the server's PATH) can't find system
46
+ # tools an engine needs (e.g. coqui needs `espeak-ng`, typically in Homebrew's bin). We
47
+ # prepend the ones that exist and aren't already present, so workers find system binaries
48
+ # regardless of how the server was launched. Cross-platform & idempotent: only existing,
49
+ # not-already-present dirs are added (Homebrew arm64 / Homebrew x86+Linux / the base dirs).
50
+ _SYSTEM_BIN_DIRS = ("/opt/homebrew/bin", "/usr/local/bin", "/usr/bin", "/bin")
51
+
52
+
53
+ def _augment_worker_path(env: dict) -> None:
54
+ """Prepend standard system bin dirs (existing + not already on PATH) to ``env['PATH']``
55
+ in place, so worker subprocesses find system binaries even when the server was launched
56
+ with a stripped PATH. Fixes coqui's '[!] No espeak backend found' under nohup/setsid."""
57
+ parts = env.get("PATH", "").split(os.pathsep) if env.get("PATH") else []
58
+ have = set(parts)
59
+ add = [d for d in _SYSTEM_BIN_DIRS if d not in have and os.path.isdir(d)]
60
+ if add:
61
+ env["PATH"] = os.pathsep.join(add + parts)
62
+
44
63
  # Default IPC read timeouts — interpreted as INACTIVITY (no-progress) windows,
45
64
  # in seconds. A worker that is still emitting output (e.g. a HuggingFace/
46
65
  # ModelScope download progress bar) is making progress and is NEVER timed out,
@@ -609,6 +628,7 @@ class SubprocessExecutor(Executor):
609
628
  )
610
629
 
611
630
  env = dict(os.environ)
631
+ _augment_worker_path(env) # so workers find system tools (e.g. espeak-ng) under nohup/setsid
612
632
  for key in _PROXY_ENV_KEYS:
613
633
  env.pop(key, None)
614
634
 
@@ -921,6 +941,13 @@ class SubprocessExecutor(Executor):
921
941
  return False
922
942
  if not await self._check_alive():
923
943
  return False
944
+ # A busy worker (an invoke in flight — e.g. a long model load/download) holds _io_lock.
945
+ # The process is alive (checked above) and working, so report healthy WITHOUT queueing the
946
+ # health ping behind that invoke: queueing hangs /v1/health + /v1/engines for the WHOLE
947
+ # operation (an ~11-min inline download once froze the entire WebUI). Only ping a free
948
+ # connection; the dispatcher also bounds this call as a belt-and-suspenders (health()).
949
+ if self._io_lock.locked():
950
+ return True
924
951
  try:
925
952
  async with self._io_lock:
926
953
  await _write_msg(self._writer, {"cmd": "health"})
@@ -2,6 +2,7 @@
2
2
  from __future__ import annotations
3
3
 
4
4
  import asyncio
5
+ import importlib.util
5
6
  import time
6
7
  from enum import Enum
7
8
  from typing import Any
@@ -12,6 +13,38 @@ from openspeechapi.logging_config import bind_context
12
13
  from openspeechapi.telemetry.perf import Event, PerfTimer, milestone
13
14
 
14
15
 
16
+ def _require_import_present(name: str, provider_cls: Any) -> None:
17
+ """Fail fast when a provider declares ``required_import`` but that module is absent.
18
+
19
+ Generic pre-spawn guard for subprocess/local engines whose SDK is NOT installable
20
+ from a pyproject extra (e.g. a git-clone-only SDK). Uses ``importlib.util.find_spec``
21
+ — a lightweight name-presence check that does NOT import or run the heavy SDK — in the
22
+ server process, so a worker is never spawned only to block until the (long) start
23
+ timeout when the SDK simply isn't there.
24
+
25
+ Safety: only acts when ``required_import`` is set (None default → no-op, the normal
26
+ path is untouched). ``find_spec`` returning None — or raising ``ModuleNotFoundError``
27
+ (a missing PARENT package of a dotted name) — means the module is absent → raise a
28
+ clear ImportError. Any OTHER exception (a broken/exotic importer) is swallowed so a
29
+ false positive can never block the healthy start path; the worker spawn proceeds.
30
+ """
31
+ req = getattr(provider_cls, "required_import", None)
32
+ if not req or not isinstance(req, str):
33
+ return
34
+ try:
35
+ spec = importlib.util.find_spec(req)
36
+ except ModuleNotFoundError:
37
+ spec = None # a parent package of the dotted name is missing → absent
38
+ except Exception: # noqa: BLE001 — exotic importer error: don't block, let spawn proceed
39
+ return
40
+ if spec is None:
41
+ raise ImportError(
42
+ f"{name}: required module '{req}' is not installed. This engine needs a "
43
+ f"dedicated SDK installer that is not yet available (e.g. a git-clone SDK, "
44
+ f"not a pip extra). Install it manually, then retry."
45
+ )
46
+
47
+
15
48
  class ProviderState(str, Enum):
16
49
  REGISTERED = "registered"
17
50
  STARTING = "starting"
@@ -38,6 +71,7 @@ class ProviderLifecycleManager:
38
71
  self._check_interval: float = 30.0
39
72
  self._shared_http_client: Any = None
40
73
  self._config_path: Any = None
74
+ self._model_downloads: Any = None
41
75
 
42
76
  def set_shared_http_client(self, client: Any) -> None:
43
77
  """Store a shared httpx.AsyncClient for injection into providers."""
@@ -47,6 +81,11 @@ class ProviderLifecycleManager:
47
81
  """providers.yaml path, so aim provisioning can persist resolved model paths."""
48
82
  self._config_path = path
49
83
 
84
+ def set_model_downloads(self, manager: Any) -> None:
85
+ """The server's ModelDownloadManager (duck-typed, may be None), so a lazy aim
86
+ provision runs its download as a tracked task visible in the WebUI panel."""
87
+ self._model_downloads = manager
88
+
50
89
  def register(self, name: str, handle: Any, keepalive: int = 0) -> None:
51
90
  self._entries[name] = _ProviderEntry(name, handle, keepalive)
52
91
 
@@ -97,6 +136,15 @@ class ProviderLifecycleManager:
97
136
  import dataclasses
98
137
  from openspeechapi.core.settings import BaseSettings
99
138
  handle = entry.handle
139
+ # Fail-fast on a missing SDK (no worker spawn → no long start-timeout
140
+ # hang). A provider may declare ``required_import`` = the top-level
141
+ # module that MUST be importable for it to run (e.g. a git-clone-only
142
+ # SDK not on PyPI). ``find_spec`` is a lightweight name-presence check
143
+ # (does NOT import / load the heavy SDK) run in the server process.
144
+ # Only checked when the attr is set; any error other than "absent"
145
+ # (ModuleNotFoundError) is swallowed so a quirky import system never
146
+ # blocks the normal/healthy start path.
147
+ _require_import_present(name, handle.provider_cls)
100
148
  # aim provisioning (main process): if `aim` manages this engine's
101
149
  # model, ensure it via aim, set settings.model_path, persist to
102
150
  # providers.yaml. No-op when aim is absent / provider opts out, so
@@ -108,6 +156,7 @@ class ProviderLifecycleManager:
108
156
  handle.settings_dict = await asyncio.to_thread(
109
157
  provision_aim_model,
110
158
  name, handle.provider_cls, handle.settings_dict, self._config_path,
159
+ self._model_downloads,
111
160
  )
112
161
  settings_cls = getattr(handle.provider_cls, "settings_cls", BaseSettings)
113
162
  # Filter settings to only include fields the class accepts
@@ -40,6 +40,8 @@ class CatalogEntry:
40
40
  isolated_venv: bool = False # run this engine's worker from a dedicated per-engine venv
41
41
  pip_constraints: list[str] = field(default_factory=list) # version pins applied when building the isolated venv
42
42
  vllm_venv: bool = False # build a clean vLLM-Omni serving venv (no openspeechapi) for a service-client engine
43
+ fish_venv: bool = False # build a fish-speech serving venv + git src checkout (service-client engine)
44
+ cosyvoice_venv: bool = False # dedicated git-clone SDK installer (CosyVoice SDK isn't on PyPI): Install builds ~/AI/venvs/cosyvoice via create_cosyvoice_venv (git clone --recursive + uv venv + wetext, no pynini) + worker runs from it (also set isolated_venv)
43
45
  cuda_torch: bool = False # isolated_venv: on a CUDA host, pre-install torch+torchaudio from the CUDA wheel index (default PyPI ships CPU torch on aarch64)
44
46
 
45
47
  @property
@@ -199,6 +201,8 @@ def build_catalog(registry_path: Path | None = None) -> list[CatalogEntry]:
199
201
  isolated_venv=bool(raw.get("isolated_venv", False)),
200
202
  pip_constraints=list(raw.get("pip_constraints", []) or []),
201
203
  vllm_venv=bool(raw.get("vllm_venv", False)),
204
+ fish_venv=bool(raw.get("fish_venv", False)),
205
+ cosyvoice_venv=bool(raw.get("cosyvoice_venv", False)),
202
206
  cuda_torch=bool(raw.get("cuda_torch", False)),
203
207
  )
204
208
  # Try to enrich with provider code metadata
@@ -477,10 +477,12 @@ engines:
477
477
  type: tts
478
478
  category: local
479
479
  display_name: "Fish Speech"
480
- description: "Fish Speech — high quality local TTS"
480
+ description: "Fish Speech (OpenAudio S1) — high-quality local TTS + voice cloning. OSA-managed serving venv (git clone + uv venv, no openspeechapi) + msgpack client. macOS(MPS)/CUDA."
481
481
  default_alias: fish_speech
482
482
  default_exec_mode: local
483
- pip_extras: [fish-speech]
483
+ fish_venv: true
484
+ cuda_torch: true # CUDA host: reinstall torch from the CUDA wheel index (lock pins CPU torch on aarch64)
485
+ pip_extras: []
484
486
 
485
487
  - name: piper
486
488
  provider: piper
@@ -497,10 +499,13 @@ engines:
497
499
  type: tts
498
500
  category: local
499
501
  display_name: "CosyVoice"
500
- description: "CosyVoice — local Chinese TTS (GPU)。⚠️ 权重商用条款有争议(上游 issue 未决),研究/内部使用 OK"
502
+ description: "CosyVoice — local Chinese TTS (GPU,含 CosyVoice2)。OSA 托管 git-clone venv(从 FunAudioLLM/CosyVoice 钉版 clone --recursive + Matcha-TTS 子模块 + uv venv;依赖用 wetext,无 pynini)。macOS/CUDA 均可一键 Install。⚠️ 权重商用条款有争议(上游 issue 未决),研究/内部使用 OK"
501
503
  default_alias: cosyvoice_tts
502
504
  default_exec_mode: subprocess
503
- pip_extras: [cosyvoice-tts]
505
+ cosyvoice_venv: true # 专用 git-clone SDK 安装器:clone --recursive(SDK 非 PyPI,需 Matcha-TTS 子模块)+ uv venv + editable openspeechapi + requirements + .pth(cosyvoice/matcha)
506
+ isolated_venv: true # worker 从专用 venv(~/AI/venvs/cosyvoice)跑,resolve_worker_python 据此寻 venv;cosyvoice_venv 安装器负责构建它
507
+ cuda_torch: true # CUDA 主机(有 nvidia-smi)装 requirements 前先从 cu130 index 装 torch+torchaudio(requirements 钉的 torch==2.3.1 在 aarch64 默认是 CPU 版)
508
+ pip_extras: []
504
509
 
505
510
  - name: coqui
506
511
  provider: coqui
@@ -135,6 +135,18 @@ def aim_has_model(model_id: str) -> bool:
135
135
  return aim_available() and _aim_resolve(model_id) is not None
136
136
 
137
137
 
138
+ def aim_local_path(model_id: str) -> str | None:
139
+ """aim's directly-loadable local path for *model_id* if already in aim's store, else None.
140
+
141
+ RESOLVE-ONLY — never downloads. For load-time use where the caller ensured the download out
142
+ of band (e.g. the TTS synth pre-flight gate warms aim's store, then the worker loads from it,
143
+ avoiding a second silent SDK download). Native-CAS (HF/Ollama) → None (load by repo id from
144
+ the aim-managed cache instead); only non-CAS store dirs (ModelScope ~/AI/store) are returned."""
145
+ if not aim_available():
146
+ return None
147
+ return _loadable_path(_aim_resolve(model_id))
148
+
149
+
138
150
  def _loadable_path(meta: dict | None) -> str | None:
139
151
  """A directly-loadable local model path from aim resolve metadata, or None.
140
152