openspeechapi 0.2.26__tar.gz → 0.3.1__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 (173) hide show
  1. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/PKG-INFO +9 -3
  2. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/core/base.py +86 -0
  3. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/core/model_hub.py +13 -3
  4. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/core/models.py +10 -0
  5. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/dispatch/aim_provision.py +59 -2
  6. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/dispatch/dispatcher.py +126 -10
  7. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/dispatch/executors/subprocess_exec.py +92 -25
  8. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/dispatch/lifecycle.py +49 -0
  9. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/engine_catalog.py +22 -0
  10. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/engine_registry.yaml +47 -4
  11. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/factory.py +15 -0
  12. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/local_engines/aim_resolver.py +12 -0
  13. openspeechapi-0.3.1/openspeechapi/local_engines/cosyvoice_venv.py +409 -0
  14. openspeechapi-0.3.1/openspeechapi/local_engines/fish_venv.py +192 -0
  15. openspeechapi-0.3.1/openspeechapi/local_engines/indextts_venv.py +271 -0
  16. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/local_engines/isolated_venv.py +40 -0
  17. openspeechapi-0.3.1/openspeechapi/providers/tts/cosyvoice.py +357 -0
  18. openspeechapi-0.3.1/openspeechapi/providers/tts/f5_tts.py +345 -0
  19. openspeechapi-0.3.1/openspeechapi/providers/tts/fish_speech.py +386 -0
  20. openspeechapi-0.3.1/openspeechapi/providers/tts/indextts.py +360 -0
  21. openspeechapi-0.3.1/openspeechapi/providers/tts/kokoro.py +294 -0
  22. openspeechapi-0.3.1/openspeechapi/providers/tts/piper.py +315 -0
  23. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/server/app.py +7 -1
  24. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/server/extras_installer.py +8 -0
  25. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/server/model_downloads.py +92 -19
  26. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/server/routes/management.py +195 -43
  27. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/server/routes/stt.py +25 -3
  28. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/server/routes/tts.py +110 -0
  29. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/server/webui/app.js +237 -8
  30. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/server/webui/index.html +13 -0
  31. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/server/ws/tts_stream.py +68 -0
  32. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/providers.example.yaml +4 -2
  33. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/pyproject.toml +7 -2
  34. openspeechapi-0.2.26/openspeechapi/providers/tts/cosyvoice.py +0 -113
  35. openspeechapi-0.2.26/openspeechapi/providers/tts/fish_speech.py +0 -158
  36. openspeechapi-0.2.26/openspeechapi/providers/tts/piper.py +0 -149
  37. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/.gitignore +0 -0
  38. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/README.md +0 -0
  39. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/__init__.py +0 -0
  40. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/__main__.py +0 -0
  41. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/cli.py +0 -0
  42. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/client/__init__.py +0 -0
  43. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/client/client.py +0 -0
  44. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/config.py +0 -0
  45. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/core/__init__.py +0 -0
  46. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/core/enums.py +0 -0
  47. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/core/registry.py +0 -0
  48. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/core/settings.py +0 -0
  49. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/demo.py +0 -0
  50. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/dispatch/__init__.py +0 -0
  51. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/dispatch/context.py +0 -0
  52. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/dispatch/executors/__init__.py +0 -0
  53. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/dispatch/executors/base.py +0 -0
  54. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/dispatch/executors/in_process.py +0 -0
  55. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/dispatch/executors/remote.py +0 -0
  56. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/dispatch/fanout.py +0 -0
  57. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/dispatch/filters.py +0 -0
  58. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/dispatch/watcher.py +0 -0
  59. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/exceptions.py +0 -0
  60. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/local_engines/__init__.py +0 -0
  61. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/local_engines/backends/__init__.py +0 -0
  62. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/local_engines/backends/docker_backend.py +0 -0
  63. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/local_engines/backends/native_backend.py +0 -0
  64. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/local_engines/base.py +0 -0
  65. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/local_engines/engines/__init__.py +0 -0
  66. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/local_engines/engines/faster_whisper.py +0 -0
  67. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/local_engines/engines/fish_speech.py +0 -0
  68. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/local_engines/engines/sherpa_onnx.py +0 -0
  69. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/local_engines/engines/whisper.py +0 -0
  70. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/local_engines/engines/whisperlivekit.py +0 -0
  71. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/local_engines/manager.py +0 -0
  72. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/local_engines/models.py +0 -0
  73. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/local_engines/progress.py +0 -0
  74. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/local_engines/registry.py +0 -0
  75. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/local_engines/task_store.py +0 -0
  76. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/local_engines/tasks.py +0 -0
  77. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/local_engines/vllm_gb10_patch.py +0 -0
  78. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/local_engines/vllm_venv.py +0 -0
  79. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/logging_config.py +0 -0
  80. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/observe/__init__.py +0 -0
  81. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/observe/base.py +0 -0
  82. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/observe/debug.py +0 -0
  83. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/observe/latency.py +0 -0
  84. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/observe/metrics.py +0 -0
  85. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/observe/tracing.py +0 -0
  86. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/observe/usage.py +0 -0
  87. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/providers/__init__.py +0 -0
  88. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/providers/_template.py +0 -0
  89. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/providers/stt/__init__.py +0 -0
  90. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/providers/stt/_local_audio.py +0 -0
  91. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/providers/stt/alibaba.py +0 -0
  92. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/providers/stt/assemblyai.py +0 -0
  93. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/providers/stt/azure_speech.py +0 -0
  94. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/providers/stt/baidu.py +0 -0
  95. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/providers/stt/canary_qwen_stt.py +0 -0
  96. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/providers/stt/deepgram.py +0 -0
  97. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/providers/stt/dolphin_stt.py +0 -0
  98. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/providers/stt/elevenlabs.py +0 -0
  99. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/providers/stt/faster_whisper.py +0 -0
  100. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/providers/stt/fireredasr_stt.py +0 -0
  101. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/providers/stt/funasr_stt.py +0 -0
  102. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/providers/stt/gemma4.py +0 -0
  103. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/providers/stt/google_cloud.py +0 -0
  104. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/providers/stt/iflytek.py +0 -0
  105. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/providers/stt/kimi_audio_stt.py +0 -0
  106. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/providers/stt/macos_speech.py +0 -0
  107. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/providers/stt/mlx_whisper_stt.py +0 -0
  108. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/providers/stt/mms_languages.json +0 -0
  109. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/providers/stt/mms_stt.py +0 -0
  110. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/providers/stt/moonshine_stt.py +0 -0
  111. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/providers/stt/openai.py +0 -0
  112. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/providers/stt/paraformer.py +0 -0
  113. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/providers/stt/parakeet_mlx_stt.py +0 -0
  114. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/providers/stt/phi4_multimodal_stt.py +0 -0
  115. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/providers/stt/qwen3_asr.py +0 -0
  116. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/providers/stt/qwen3_omni_stt.py +0 -0
  117. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/providers/stt/sensevoice.py +0 -0
  118. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/providers/stt/sherpa_onnx.py +0 -0
  119. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/providers/stt/tencent.py +0 -0
  120. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/providers/stt/volcengine.py +0 -0
  121. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/providers/stt/vosk_stt.py +0 -0
  122. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/providers/stt/voxtral_stt.py +0 -0
  123. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/providers/stt/wenet_stt.py +0 -0
  124. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/providers/stt/whisper.py +0 -0
  125. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/providers/stt/whisperlivekit.py +0 -0
  126. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/providers/stt/windows_speech.py +0 -0
  127. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/providers/tts/__init__.py +0 -0
  128. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/providers/tts/alibaba.py +0 -0
  129. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/providers/tts/azure_speech.py +0 -0
  130. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/providers/tts/baidu.py +0 -0
  131. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/providers/tts/coqui.py +0 -0
  132. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/providers/tts/deepgram.py +0 -0
  133. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/providers/tts/elevenlabs.py +0 -0
  134. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/providers/tts/google_cloud.py +0 -0
  135. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/providers/tts/iflytek.py +0 -0
  136. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/providers/tts/macos_say.py +0 -0
  137. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/providers/tts/minimax.py +0 -0
  138. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/providers/tts/openai.py +0 -0
  139. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/providers/tts/tencent.py +0 -0
  140. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/providers/tts/volcengine.py +0 -0
  141. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/providers/tts/windows_sapi.py +0 -0
  142. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/server/__init__.py +0 -0
  143. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/server/auth.py +0 -0
  144. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/server/middleware.py +0 -0
  145. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/server/native_installer.py +0 -0
  146. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/server/routes/__init__.py +0 -0
  147. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/server/routes/webui.py +0 -0
  148. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/server/system_metrics.py +0 -0
  149. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/server/webui/styles.css +0 -0
  150. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/server/ws/__init__.py +0 -0
  151. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/server/ws/stt_stream.py +0 -0
  152. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/telemetry/__init__.py +0 -0
  153. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/telemetry/perf.py +0 -0
  154. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/utils/__init__.py +0 -0
  155. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/utils/audio_converter.py +0 -0
  156. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/utils/audio_playback.py +0 -0
  157. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/openspeechapi/vendor_registry.yaml +0 -0
  158. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/scripts/aim_adopt.py +0 -0
  159. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/scripts/aim_consumers.py +0 -0
  160. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/scripts/engines/cloud/install.sh +0 -0
  161. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/scripts/engines/faster-whisper/native/install.sh +0 -0
  162. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/scripts/engines/fish-speech/native/install.sh +0 -0
  163. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/scripts/engines/macos-stt/_bundle.sh +0 -0
  164. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/scripts/engines/macos-stt/install.sh +0 -0
  165. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/scripts/engines/macos-stt/macos_stt.swift +0 -0
  166. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/scripts/engines/macos-stt/request_auth.swift +0 -0
  167. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/scripts/engines/sherpa-onnx/native/install.sh +0 -0
  168. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/scripts/engines/sherpa-onnx/native/run_streaming_server.py +0 -0
  169. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/scripts/engines/whisper/native/install.sh +0 -0
  170. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/scripts/engines/whisperlivekit/native/install.sh +0 -0
  171. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/scripts/gen_mms_languages.py +0 -0
  172. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/scripts/preload_stt_model.py +0 -0
  173. {openspeechapi-0.2.26 → openspeechapi-0.3.1}/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.1
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
@@ -60,6 +58,10 @@ Provides-Extra: elevenlabs-stt
60
58
  Requires-Dist: websockets; extra == 'elevenlabs-stt'
61
59
  Provides-Extra: elevenlabs-tts
62
60
  Requires-Dist: elevenlabs; extra == 'elevenlabs-tts'
61
+ Provides-Extra: f5-tts
62
+ Requires-Dist: f5-tts; extra == 'f5-tts'
63
+ Requires-Dist: mlx-whisper; (sys_platform == 'darwin') and extra == 'f5-tts'
64
+ Requires-Dist: soundfile; extra == 'f5-tts'
63
65
  Provides-Extra: faster-whisper-stt
64
66
  Requires-Dist: faster-whisper; extra == 'faster-whisper-stt'
65
67
  Provides-Extra: fireredasr-stt
@@ -88,6 +90,10 @@ Provides-Extra: iflytek-tts
88
90
  Requires-Dist: websockets; extra == 'iflytek-tts'
89
91
  Provides-Extra: kimi-audio-stt
90
92
  Requires-Dist: torch; extra == 'kimi-audio-stt'
93
+ Provides-Extra: kokoro
94
+ Requires-Dist: kokoro>=0.9.2; extra == 'kokoro'
95
+ Requires-Dist: misaki[zh]; extra == 'kokoro'
96
+ Requires-Dist: soundfile; extra == 'kokoro'
91
97
  Provides-Extra: macos-native
92
98
  Provides-Extra: minimax-tts
93
99
  Provides-Extra: mlx-whisper-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,65 @@ 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
+
138
+ @staticmethod
139
+ def pending_reference_asr(settings, opts) -> dict | None: # noqa: ANN001
140
+ """该请求是否需要先**追踪下载**一个「二级」模型(参考音频转写用的 ASR),默认 ``None``。
141
+
142
+ 克隆类 TTS(如 F5-TTS)在 ``reference_text`` 为空时要转写参考音频取文本,依赖一个 ASR
143
+ 模型。该模型未缓存时,合成前置 gate 据本钩子返回的 ``{source, repo, label}`` 起追踪下载
144
+ (上 Dashboard 面板)+ 返回 409 ``model_downloading``,而非在 worker 里静默现下 / 直接
145
+ 报错。返回 ``None`` = 无需二级下载(已给 ref_text、无参考音、模型已缓存,或引擎不涉及)。
146
+
147
+ 同 ``download_spec`` 纪律:server 进程内调用,纯字符串/缓存存在性逻辑,绝不加载模型/下载。
148
+ ``settings`` 可能是 dataclass 或 dict;``opts`` 为本次请求的 ``TTSOptions``。"""
149
+ return None
150
+
151
+ @staticmethod
152
+ def pending_aux_models(settings, opts) -> "list[dict] | None": # noqa: ANN001
153
+ """该引擎首次加载时要下的**辅助模型**里,尚未缓存的那些(默认 ``None``)。
154
+
155
+ 某些 SDK(如 IndexTTS2)在加载主模型时,会在 worker 里静默现下若干 GB 的辅助模型
156
+ (w2v-bert / codec / vocoder 等)——违反「前后台状态同步」+「绝不 worker 静默现下」。
157
+ 引擎 override 本钩子返回**缺失** aux 的列表 ``[{repo, allow_patterns, label}, ...]``,合成
158
+ 前置 gate 据此起**追踪下载**(上 Dashboard 面板)+ 返回 409 ``model_downloading`` + 前端
159
+ 自动重试;待全部就绪后 provider 把它们显式喂给 SDK(绕开其静默下载)。返回 ``None`` = 无
160
+ 待下 aux(已全缓存,或引擎无此需求)。
161
+
162
+ 同 ``download_spec`` 纪律:server 进程内调用,纯字符串/缓存存在性逻辑,绝不加载模型/下载。"""
163
+ return None
164
+
97
165
  @classmethod
98
166
  def expected_local_repo(cls, settings) -> str | None: # noqa: ANN001
99
167
  """该引擎在本机会从本地缓存加载的 HF repo id(用于「是否已下载」预检)。
@@ -249,3 +317,21 @@ class TTSProvider(SpeechProvider):
249
317
  async def list_voices(self) -> list[dict]:
250
318
  """Return available voices. Override in subclass to provide voice list."""
251
319
  return []
320
+
321
+ @classmethod
322
+ def static_voices(cls, model: str | None = None) -> list[dict] | None:
323
+ """Preset voices ({id, name}) for *model* WITHOUT loading it — the load-free fast path for
324
+ the Voice dropdown (CLAUDE.md 铁律: listing voices must NOT load a multi-GB model).
325
+
326
+ Return value is a SENTINEL the dispatcher uses to decide whether to load:
327
+ • ``None`` (default) — this provider can't answer statically; its speakers are only
328
+ knowable from the LOADED model (coqui/piper/fish). The dispatcher falls back to
329
+ load+invoke.
330
+ • a ``list`` (possibly EMPTY) — an AUTHORITATIVE answer: use it as-is, NEVER load. A
331
+ provider whose preset set is fully determined by the model id (e.g. cosyvoice: SFT/
332
+ Instruct → 7 presets; zero-shot 0.5B / base → ``[]``) returns this so switching models
333
+ is instant AND a genuinely preset-less model doesn't waste a load just to return ``[]``.
334
+
335
+ Override to return a list. Must stay import-light (no torch): it runs in the server process
336
+ off ``provider_cls`` with no instance/model."""
337
+ 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,14 @@ 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")
108
+ # Generic per-request setting overrides (JSON object) from the Lab Advanced Options panel. Keys
109
+ # matching the provider's settings dataclass fields are merged over the static config for THIS
110
+ # call only (via ``SpeechProvider._effective_settings``) — lets the panel expose any engine param
111
+ # (e.g. IndexTTS2 emotion) without per-field plumbing. Mirrors STTOptions.overrides.
112
+ overrides: dict | None = None
@@ -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,74 @@ class ServiceDispatcher:
488
499
  except Exception: # noqa: BLE001 - 预检取 repo 失败 → 当作无法判断,放行
489
500
  return None
490
501
 
502
+ def _settings_for(self, alias: str, model_override: str | None = None) -> 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
+
507
+ ``model_override`` 非空时(Lab 按请求 model 覆盖)叠加覆盖的 model,使这些钩子对照的是
508
+ 该请求**实际会加载**的模型,而非引擎静态配置(同 ``expected_repo_for``)。"""
509
+ handle = self._handles.get(alias)
510
+ if handle is None:
511
+ return None
512
+ settings = getattr(handle, "settings_dict", None)
513
+ if settings is None:
514
+ settings = getattr(handle, "settings", None) or {}
515
+ if model_override:
516
+ base = settings if isinstance(settings, dict) else (getattr(settings, "__dict__", {}) or {})
517
+ settings = {**base, "model": model_override}
518
+ return settings
519
+
520
+ def local_model_present(self, alias: str, model_override: str | None = None) -> bool | None:
521
+ """委托给 provider 类的 ``local_model_present`` —— 仅当引擎走**非标准**部分下载
522
+ (如 piper)才返回 True/False,否则 None(交标准 repo/aim 判断)。纯字符串/文件
523
+ 存在性逻辑、不加载模型;任何异常/找不到 → None(best-effort,绝不阻塞引擎列表)。
524
+ ``model_override`` 非空时按被覆盖的 model 判断(对照该请求实际加载的模型)。"""
525
+ handle = self._handles.get(alias)
526
+ if handle is None:
527
+ return None
528
+ try:
529
+ return handle.provider_cls.local_model_present(self._settings_for(alias, model_override) or {})
530
+ except Exception: # noqa: BLE001 - best-effort 预检,失败当作「无法判断」
531
+ return None
532
+
533
+ def download_spec(self, alias: str, model_override: str | None = None) -> dict | None:
534
+ """委托给 provider 类的 ``download_spec`` —— 返回 ``{repo, allow_patterns, label}``
535
+ 的部分 snapshot 下载描述(piper 等无法 aim 纳管、需从大仓只取若干文件的引擎),
536
+ 否则 None。纯字符串逻辑、不加载模型;任何异常/找不到 → None(best-effort)。
537
+ ``model_override`` 非空时按被覆盖的 model 取(下载目标对准该请求实际加载的模型)。"""
538
+ handle = self._handles.get(alias)
539
+ if handle is None:
540
+ return None
541
+ try:
542
+ return handle.provider_cls.download_spec(self._settings_for(alias, model_override) or {})
543
+ except Exception: # noqa: BLE001 - best-effort,失败当作「无部分下载」
544
+ return None
545
+
546
+ def pending_reference_asr(self, alias: str, opts) -> dict | None: # noqa: ANN001
547
+ """委托给 provider 类的 ``pending_reference_asr`` —— 该请求(``opts``)是否需要先追踪
548
+ 下载一个参考转写用的 ASR 模型(克隆类 TTS 在 ref_text 为空时);返回 ``{source, repo,
549
+ label}`` 或 None。纯字符串/缓存逻辑、不加载模型;任何异常/找不到 → None(best-effort)。"""
550
+ handle = self._handles.get(alias)
551
+ if handle is None:
552
+ return None
553
+ try:
554
+ return handle.provider_cls.pending_reference_asr(self._settings_for(alias) or {}, opts)
555
+ except Exception: # noqa: BLE001 - best-effort 预检,失败当作「无需二级下载」
556
+ return None
557
+
558
+ def pending_aux_models(self, alias: str, opts) -> "list[dict] | None": # noqa: ANN001
559
+ """委托给 provider 类的 ``pending_aux_models`` —— 该引擎首次加载要下的辅助模型里尚未缓存的
560
+ 那些(``[{repo, allow_patterns, label}]`` 或 None);合成前置 gate 据此追踪下载(上 Dashboard)。
561
+ 纯字符串/缓存逻辑、不加载模型;任何异常/找不到 → None(best-effort)。"""
562
+ handle = self._handles.get(alias)
563
+ if handle is None:
564
+ return None
565
+ try:
566
+ return handle.provider_cls.pending_aux_models(self._settings_for(alias) or {}, opts)
567
+ except Exception: # noqa: BLE001 - best-effort 预检,失败当作「无待下 aux」
568
+ return None
569
+
491
570
  async def _negotiate_audio_format(
492
571
  self, handle: "_ProviderHandle", audio: AudioData
493
572
  ) -> AudioData:
@@ -620,16 +699,42 @@ class ServiceDispatcher:
620
699
  # ------------------------------------------------------------------
621
700
 
622
701
  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)."""
702
+ """Built-in voices of a provider's model, fetched via the executor's invoke path so it works
703
+ for ALL exec modes — SUBPROCESS included (lifecycle.get_instance() returns None there, so a
704
+ direct instance.list_voices() always yielded [] for e.g. coqui).
705
+
706
+ CLAUDE.md 铁律: listing voices must NOT load a multi-GB model. So when the engine is NOT
707
+ already loaded, first try the provider's load-free ``static_voices()``: an AUTHORITATIVE
708
+ answer (a list — possibly EMPTY — e.g. cosyvoice SFT/Instruct → presets, zero-shot → [])
709
+ is returned in-process without starting the worker, so switching models in the Lab is
710
+ instant (and a preset-less model doesn't waste a load just to return []). Only ``None``
711
+ (coqui/piper/fish, whose speakers need the loaded model) falls back to loading + invoke.
712
+ When the engine IS loaded, always invoke so ``list_available_spks()`` wins."""
627
713
  handle = self._get_handle(provider)
714
+ if self._lifecycle.get_state(provider) != ProviderState.READY:
715
+ try:
716
+ eff_model = model or (getattr(handle, "settings_dict", {}) or {}).get("model")
717
+ static = handle.provider_cls.static_voices(eff_model)
718
+ except Exception: # noqa: BLE001 - static hint is best-effort; fall back to load+invoke
719
+ static = None
720
+ if static is not None: # authoritative (even []) → never load to list voices
721
+ return list(static)
628
722
  await self._lifecycle.ensure_ready(provider)
629
723
  result = await handle.executor.invoke("list_voices", **({"model": model} if model else {}))
630
724
  self._lifecycle.touch(provider)
631
725
  return list(result or [])
632
726
 
727
+ async def add_reference(self, provider: str, voice_id: str, audio, text: str) -> dict:
728
+ """Register a named reference voice on a provider (e.g. fish-speech ``/v1/references/add``)
729
+ via the executor invoke path. Lets the Lab register a cloned voice once and reuse it by
730
+ ``reference_id`` thereafter."""
731
+ handle = self._get_handle(provider)
732
+ await self._lifecycle.ensure_ready(provider)
733
+ result = await handle.executor.invoke(
734
+ "add_reference", voice_id=voice_id, audio=audio, text=text)
735
+ self._lifecycle.touch(provider)
736
+ return dict(result or {})
737
+
633
738
  async def _synthesize(
634
739
  self,
635
740
  provider: str,
@@ -752,9 +857,20 @@ class ServiceDispatcher:
752
857
  # ------------------------------------------------------------------
753
858
 
754
859
  async def health(self) -> dict[str, bool]:
755
- """Return health status for all configured providers."""
860
+ """Return health status for all configured providers.
861
+
862
+ Each check is BOUNDED (2s): a busy/slow worker (an invoke in flight — e.g. a long model
863
+ load/download holds the executor's _io_lock) must not hang the whole endpoint. /v1/health
864
+ AND /v1/engines both call this, so an unbounded check froze the entire WebUI when a worker
865
+ was mid-download. A timeout here is safe — the check is blocked *waiting to acquire* the
866
+ lock (nothing sent on the wire yet), so cancelling it can't desync the IPC protocol."""
867
+ async def _bounded(h: Any) -> bool:
868
+ try:
869
+ return bool(await asyncio.wait_for(h.executor.health_check(), timeout=2.0))
870
+ except Exception: # noqa: BLE001 - timeout / transport error → treat as not-healthy-now
871
+ return False
756
872
  results = await asyncio.gather(
757
- *[h.executor.health_check() for h in self._handles.values()],
873
+ *[_bounded(h) for h in self._handles.values()],
758
874
  return_exceptions=True,
759
875
  )
760
876
  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,
@@ -50,6 +69,13 @@ _PROXY_ENV_KEYS = (
50
69
  # Override via env; <= 0 disables the bound entirely.
51
70
  _DEFAULT_START_TIMEOUT_S = 600.0 # max silence during model load / weight download
52
71
  _DEFAULT_INVOKE_TIMEOUT_S = 300.0 # max silence during a single transcribe/synthesize
72
+ # Max wall-clock to wait for a freshly-spawned worker to BIND its UDS. This is a
73
+ # hard deadline (not inactivity-based) — a fresh interpreter + `import openspeechapi`
74
+ # is ~0.2s idle, but under heavy CPU contention or a large parent process (torch
75
+ # loaded → slow fork/COW) the spawn can take seconds, so keep it generous. A dead
76
+ # worker (import error / unpicklable provider) is detected immediately regardless,
77
+ # so a wide window never means a long hang on a real failure. Override via env.
78
+ _DEFAULT_SOCKET_TIMEOUT_S = 30.0
53
79
 
54
80
 
55
81
  def _env_timeout(name: str, default: float) -> float:
@@ -526,6 +552,7 @@ class SubprocessExecutor(Executor):
526
552
  *,
527
553
  start_timeout_s: float | None = None,
528
554
  invoke_timeout_s: float | None = None,
555
+ socket_timeout_s: float | None = None,
529
556
  worker_python: str | None = None,
530
557
  ) -> None:
531
558
  self._provider_cls: type[SpeechProvider] | None = None
@@ -552,6 +579,12 @@ class SubprocessExecutor(Executor):
552
579
  _env_timeout("OSA_WORKER_INVOKE_TIMEOUT_S", _DEFAULT_INVOKE_TIMEOUT_S)
553
580
  if invoke_timeout_s is None else invoke_timeout_s
554
581
  )
582
+ # Hard deadline for the freshly-spawned worker to bind its UDS (see
583
+ # _DEFAULT_SOCKET_TIMEOUT_S). Env-overridable so a slow/loaded host can widen it.
584
+ self._socket_timeout_s = (
585
+ _env_timeout("OSA_WORKER_SOCKET_TIMEOUT_S", _DEFAULT_SOCKET_TIMEOUT_S)
586
+ if socket_timeout_s is None else socket_timeout_s
587
+ )
555
588
  # Rolling capture of the worker's stderr (download progress, tracebacks,
556
589
  # native crash output) — surfaced in logs live and appended to errors.
557
590
  self._stderr_tail: deque[str] = deque(maxlen=50)
@@ -609,6 +642,7 @@ class SubprocessExecutor(Executor):
609
642
  )
610
643
 
611
644
  env = dict(os.environ)
645
+ _augment_worker_path(env) # so workers find system tools (e.g. espeak-ng) under nohup/setsid
612
646
  for key in _PROXY_ENV_KEYS:
613
647
  env.pop(key, None)
614
648
 
@@ -623,38 +657,64 @@ class SubprocessExecutor(Executor):
623
657
  # native crash output) to the server log instead of discarding it.
624
658
  self._start_stderr_drain()
625
659
 
626
- # Wait for socket to appear (worker needs a moment to bind)
627
- await self._wait_for_socket(self._socket_path, timeout=10.0)
628
-
629
- self._reader, self._writer = await asyncio.open_unix_connection(self._socket_path)
630
-
631
- # Tell the worker to start the provider. Bound the wait: provider.start()
632
- # may download model weights, which can stall indefinitely on a blocked
633
- # network — turn that into a clear error rather than an infinite hang.
634
- await _write_msg(self._writer, {"cmd": "start"})
635
660
  try:
636
- resp = await self._read_resp(self._start_timeout_s)
637
- except asyncio.TimeoutError:
638
- to = self._start_timeout_s
661
+ # Wait for the worker to bind its socket. Fails fast if the worker dies
662
+ # during startup; the window is generous (OSA_WORKER_SOCKET_TIMEOUT_S,
663
+ # default 30s) so a slow spawn on a CPU-bound host / heavy parent (torch
664
+ # loaded → slow fork/COW) isn't killed prematurely.
665
+ await self._wait_for_socket(self._socket_path)
666
+
667
+ self._reader, self._writer = await asyncio.open_unix_connection(self._socket_path)
668
+
669
+ # Tell the worker to start the provider. Bound the wait: provider.start()
670
+ # may download model weights, which can stall indefinitely on a blocked
671
+ # network — turn that into a clear error rather than an infinite hang.
672
+ await _write_msg(self._writer, {"cmd": "start"})
673
+ try:
674
+ resp = await self._read_resp(self._start_timeout_s)
675
+ except asyncio.TimeoutError:
676
+ to = self._start_timeout_s
677
+ raise RuntimeError(
678
+ f"Worker '{self._label}' did not finish startup — no progress for "
679
+ f"{to:.0f}s (model load/download stalled; a progressing download "
680
+ f"would keep emitting output). Pre-download the model, use the "
681
+ f"ModelScope mirror (hub=ms) on China networks, or raise "
682
+ f"OSA_WORKER_START_TIMEOUT_S. Recent worker output:\n{self._recent_stderr()}"
683
+ ) from None
684
+ if not resp.get("ok"):
685
+ raise RuntimeError(f"Worker start failed: {resp.get('error')}")
686
+ except BaseException:
687
+ # Any startup failure (socket never bound, worker died, start error/timeout)
688
+ # → tear down the worker so we never leak a process or a half-open connection.
639
689
  await self._kill_process()
640
- raise RuntimeError(
641
- f"Worker '{self._label}' did not finish startup — no progress for "
642
- f"{to:.0f}s (model load/download stalled; a progressing download "
643
- f"would keep emitting output). Pre-download the model, use the "
644
- f"ModelScope mirror (hub=ms) on China networks, or raise "
645
- f"OSA_WORKER_START_TIMEOUT_S. Recent worker output:\n{self._recent_stderr()}"
646
- ) from None
647
- if not resp.get("ok"):
648
- raise RuntimeError(f"Worker start failed: {resp.get('error')}")
649
-
650
- @staticmethod
651
- async def _wait_for_socket(path: str, timeout: float = 10.0) -> None:
690
+ raise
691
+
692
+ async def _wait_for_socket(self, path: str, timeout: float | None = None) -> None:
693
+ """Wait for the worker to bind ``path``, up to ``timeout`` seconds (default
694
+ ``self._socket_timeout_s``). Fails FAST if the worker process exits first —
695
+ an import error / unpicklable provider / bad interpreter dies before binding,
696
+ and there's no point waiting out the full window (and the generic 'socket did
697
+ not appear' hid the real cause). Surfaces the worker's stderr either way."""
698
+ if timeout is None:
699
+ timeout = self._socket_timeout_s
652
700
  deadline = time.monotonic() + timeout
653
701
  while time.monotonic() < deadline:
654
702
  if os.path.exists(path):
655
703
  return
704
+ proc = self._process
705
+ if proc is not None and proc.returncode is not None:
706
+ raise RuntimeError(
707
+ f"Worker '{self._label}' exited (code {proc.returncode}) during "
708
+ f"startup before binding its socket. Recent worker output:\n"
709
+ f"{self._recent_stderr()}"
710
+ )
656
711
  await asyncio.sleep(0.05)
657
- raise RuntimeError(f"Worker socket did not appear at {path!r} within {timeout}s")
712
+ raise RuntimeError(
713
+ f"Worker '{self._label}' socket did not appear at {path!r} within {timeout:.0f}s "
714
+ f"(worker startup stalled — a heavy import under CPU contention, a slow fork "
715
+ f"of a large parent, or a wedged interpreter; raise OSA_WORKER_SOCKET_TIMEOUT_S "
716
+ f"on a slow/loaded host). Recent worker output:\n{self._recent_stderr()}"
717
+ )
658
718
 
659
719
  async def _read_resp(self, idle_timeout: float) -> Any:
660
720
  """Read one worker response with a progress-aware (inactivity) bound.
@@ -921,6 +981,13 @@ class SubprocessExecutor(Executor):
921
981
  return False
922
982
  if not await self._check_alive():
923
983
  return False
984
+ # A busy worker (an invoke in flight — e.g. a long model load/download) holds _io_lock.
985
+ # The process is alive (checked above) and working, so report healthy WITHOUT queueing the
986
+ # health ping behind that invoke: queueing hangs /v1/health + /v1/engines for the WHOLE
987
+ # operation (an ~11-min inline download once froze the entire WebUI). Only ping a free
988
+ # connection; the dispatcher also bounds this call as a belt-and-suspenders (health()).
989
+ if self._io_lock.locked():
990
+ return True
924
991
  try:
925
992
  async with self._io_lock:
926
993
  await _write_msg(self._writer, {"cmd": "health"})