openspeechapi 0.2.25__tar.gz → 0.2.26__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 (165) hide show
  1. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/PKG-INFO +2 -2
  2. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/core/models.py +4 -0
  3. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/dispatch/dispatcher.py +11 -0
  4. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/engine_catalog.py +2 -0
  5. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/engine_registry.yaml +7 -4
  6. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/local_engines/isolated_venv.py +29 -2
  7. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/providers/stt/qwen3_omni_stt.py +24 -4
  8. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/providers/tts/alibaba.py +1 -0
  9. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/providers/tts/baidu.py +1 -0
  10. openspeechapi-0.2.26/openspeechapi/providers/tts/coqui.py +412 -0
  11. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/providers/tts/cosyvoice.py +1 -0
  12. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/providers/tts/deepgram.py +1 -0
  13. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/providers/tts/iflytek.py +1 -0
  14. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/providers/tts/macos_say.py +1 -0
  15. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/providers/tts/openai.py +1 -0
  16. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/providers/tts/piper.py +6 -0
  17. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/providers/tts/tencent.py +1 -0
  18. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/providers/tts/volcengine.py +1 -0
  19. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/providers/tts/windows_sapi.py +1 -0
  20. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/server/routes/management.py +20 -1
  21. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/server/routes/tts.py +15 -8
  22. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/server/webui/app.js +93 -4
  23. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/server/webui/index.html +4 -0
  24. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/server/webui/styles.css +10 -1
  25. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/server/ws/tts_stream.py +28 -24
  26. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/pyproject.toml +2 -2
  27. openspeechapi-0.2.25/openspeechapi/providers/tts/coqui.py +0 -63
  28. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/.gitignore +0 -0
  29. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/README.md +0 -0
  30. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/__init__.py +0 -0
  31. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/__main__.py +0 -0
  32. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/cli.py +0 -0
  33. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/client/__init__.py +0 -0
  34. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/client/client.py +0 -0
  35. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/config.py +0 -0
  36. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/core/__init__.py +0 -0
  37. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/core/base.py +0 -0
  38. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/core/enums.py +0 -0
  39. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/core/model_hub.py +0 -0
  40. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/core/registry.py +0 -0
  41. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/core/settings.py +0 -0
  42. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/demo.py +0 -0
  43. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/dispatch/__init__.py +0 -0
  44. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/dispatch/aim_provision.py +0 -0
  45. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/dispatch/context.py +0 -0
  46. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/dispatch/executors/__init__.py +0 -0
  47. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/dispatch/executors/base.py +0 -0
  48. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/dispatch/executors/in_process.py +0 -0
  49. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/dispatch/executors/remote.py +0 -0
  50. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/dispatch/executors/subprocess_exec.py +0 -0
  51. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/dispatch/fanout.py +0 -0
  52. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/dispatch/filters.py +0 -0
  53. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/dispatch/lifecycle.py +0 -0
  54. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/dispatch/watcher.py +0 -0
  55. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/exceptions.py +0 -0
  56. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/factory.py +0 -0
  57. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/local_engines/__init__.py +0 -0
  58. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/local_engines/aim_resolver.py +0 -0
  59. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/local_engines/backends/__init__.py +0 -0
  60. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/local_engines/backends/docker_backend.py +0 -0
  61. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/local_engines/backends/native_backend.py +0 -0
  62. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/local_engines/base.py +0 -0
  63. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/local_engines/engines/__init__.py +0 -0
  64. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/local_engines/engines/faster_whisper.py +0 -0
  65. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/local_engines/engines/fish_speech.py +0 -0
  66. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/local_engines/engines/sherpa_onnx.py +0 -0
  67. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/local_engines/engines/whisper.py +0 -0
  68. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/local_engines/engines/whisperlivekit.py +0 -0
  69. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/local_engines/manager.py +0 -0
  70. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/local_engines/models.py +0 -0
  71. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/local_engines/progress.py +0 -0
  72. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/local_engines/registry.py +0 -0
  73. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/local_engines/task_store.py +0 -0
  74. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/local_engines/tasks.py +0 -0
  75. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/local_engines/vllm_gb10_patch.py +0 -0
  76. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/local_engines/vllm_venv.py +0 -0
  77. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/logging_config.py +0 -0
  78. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/observe/__init__.py +0 -0
  79. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/observe/base.py +0 -0
  80. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/observe/debug.py +0 -0
  81. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/observe/latency.py +0 -0
  82. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/observe/metrics.py +0 -0
  83. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/observe/tracing.py +0 -0
  84. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/observe/usage.py +0 -0
  85. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/providers/__init__.py +0 -0
  86. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/providers/_template.py +0 -0
  87. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/providers/stt/__init__.py +0 -0
  88. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/providers/stt/_local_audio.py +0 -0
  89. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/providers/stt/alibaba.py +0 -0
  90. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/providers/stt/assemblyai.py +0 -0
  91. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/providers/stt/azure_speech.py +0 -0
  92. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/providers/stt/baidu.py +0 -0
  93. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/providers/stt/canary_qwen_stt.py +0 -0
  94. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/providers/stt/deepgram.py +0 -0
  95. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/providers/stt/dolphin_stt.py +0 -0
  96. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/providers/stt/elevenlabs.py +0 -0
  97. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/providers/stt/faster_whisper.py +0 -0
  98. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/providers/stt/fireredasr_stt.py +0 -0
  99. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/providers/stt/funasr_stt.py +0 -0
  100. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/providers/stt/gemma4.py +0 -0
  101. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/providers/stt/google_cloud.py +0 -0
  102. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/providers/stt/iflytek.py +0 -0
  103. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/providers/stt/kimi_audio_stt.py +0 -0
  104. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/providers/stt/macos_speech.py +0 -0
  105. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/providers/stt/mlx_whisper_stt.py +0 -0
  106. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/providers/stt/mms_languages.json +0 -0
  107. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/providers/stt/mms_stt.py +0 -0
  108. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/providers/stt/moonshine_stt.py +0 -0
  109. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/providers/stt/openai.py +0 -0
  110. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/providers/stt/paraformer.py +0 -0
  111. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/providers/stt/parakeet_mlx_stt.py +0 -0
  112. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/providers/stt/phi4_multimodal_stt.py +0 -0
  113. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/providers/stt/qwen3_asr.py +0 -0
  114. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/providers/stt/sensevoice.py +0 -0
  115. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/providers/stt/sherpa_onnx.py +0 -0
  116. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/providers/stt/tencent.py +0 -0
  117. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/providers/stt/volcengine.py +0 -0
  118. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/providers/stt/vosk_stt.py +0 -0
  119. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/providers/stt/voxtral_stt.py +0 -0
  120. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/providers/stt/wenet_stt.py +0 -0
  121. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/providers/stt/whisper.py +0 -0
  122. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/providers/stt/whisperlivekit.py +0 -0
  123. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/providers/stt/windows_speech.py +0 -0
  124. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/providers/tts/__init__.py +0 -0
  125. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/providers/tts/azure_speech.py +0 -0
  126. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/providers/tts/elevenlabs.py +0 -0
  127. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/providers/tts/fish_speech.py +0 -0
  128. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/providers/tts/google_cloud.py +0 -0
  129. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/providers/tts/minimax.py +0 -0
  130. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/server/__init__.py +0 -0
  131. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/server/app.py +0 -0
  132. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/server/auth.py +0 -0
  133. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/server/extras_installer.py +0 -0
  134. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/server/middleware.py +0 -0
  135. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/server/model_downloads.py +0 -0
  136. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/server/native_installer.py +0 -0
  137. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/server/routes/__init__.py +0 -0
  138. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/server/routes/stt.py +0 -0
  139. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/server/routes/webui.py +0 -0
  140. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/server/system_metrics.py +0 -0
  141. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/server/ws/__init__.py +0 -0
  142. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/server/ws/stt_stream.py +0 -0
  143. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/telemetry/__init__.py +0 -0
  144. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/telemetry/perf.py +0 -0
  145. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/utils/__init__.py +0 -0
  146. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/utils/audio_converter.py +0 -0
  147. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/utils/audio_playback.py +0 -0
  148. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/openspeechapi/vendor_registry.yaml +0 -0
  149. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/providers.example.yaml +0 -0
  150. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/scripts/aim_adopt.py +0 -0
  151. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/scripts/aim_consumers.py +0 -0
  152. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/scripts/engines/cloud/install.sh +0 -0
  153. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/scripts/engines/faster-whisper/native/install.sh +0 -0
  154. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/scripts/engines/fish-speech/native/install.sh +0 -0
  155. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/scripts/engines/macos-stt/_bundle.sh +0 -0
  156. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/scripts/engines/macos-stt/install.sh +0 -0
  157. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/scripts/engines/macos-stt/macos_stt.swift +0 -0
  158. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/scripts/engines/macos-stt/request_auth.swift +0 -0
  159. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/scripts/engines/sherpa-onnx/native/install.sh +0 -0
  160. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/scripts/engines/sherpa-onnx/native/run_streaming_server.py +0 -0
  161. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/scripts/engines/whisper/native/install.sh +0 -0
  162. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/scripts/engines/whisperlivekit/native/install.sh +0 -0
  163. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/scripts/gen_mms_languages.py +0 -0
  164. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/scripts/preload_stt_model.py +0 -0
  165. {openspeechapi-0.2.25 → openspeechapi-0.2.26}/scripts/release.sh +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: openspeechapi
3
- Version: 0.2.25
3
+ Version: 0.2.26
4
4
  Summary: Unified speech interface for STT/TTS providers
5
5
  Requires-Python: >=3.11
6
6
  Requires-Dist: httpx>=0.27
@@ -35,7 +35,7 @@ Provides-Extra: canary-qwen-stt
35
35
  Provides-Extra: cloud
36
36
  Requires-Dist: websockets; extra == 'cloud'
37
37
  Provides-Extra: coqui-tts
38
- Requires-Dist: tts; extra == 'coqui-tts'
38
+ Requires-Dist: coqui-tts[codec,cpu]; extra == 'coqui-tts'
39
39
  Provides-Extra: cosyvoice-tts
40
40
  Requires-Dist: torchaudio; extra == 'cosyvoice-tts'
41
41
  Provides-Extra: deepgram
@@ -96,3 +96,7 @@ class TTSOptions:
96
96
  output_format: AudioFormat = AudioFormat.PCM_16K
97
97
  model: str | None = None
98
98
  stream_transport: str | None = None
99
+ # voice cloning (XTTS / F5 / GPT-SoVITS / CosyVoice2 …): the speaker to clone — raw audio
100
+ # bytes, base64, OR a local path/URL. Ignored by preset-voice engines.
101
+ reference_audio: bytes | str | None = None
102
+ language: str | None = None # cloning engines need an explicit lang code (e.g. "zh", "en")
@@ -619,6 +619,17 @@ class ServiceDispatcher:
619
619
  # TTS
620
620
  # ------------------------------------------------------------------
621
621
 
622
+ 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)."""
627
+ handle = self._get_handle(provider)
628
+ await self._lifecycle.ensure_ready(provider)
629
+ result = await handle.executor.invoke("list_voices", **({"model": model} if model else {}))
630
+ self._lifecycle.touch(provider)
631
+ return list(result or [])
632
+
622
633
  async def _synthesize(
623
634
  self,
624
635
  provider: str,
@@ -40,6 +40,7 @@ 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
+ 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)
43
44
 
44
45
  @property
45
46
  def compatible(self) -> bool:
@@ -198,6 +199,7 @@ def build_catalog(registry_path: Path | None = None) -> list[CatalogEntry]:
198
199
  isolated_venv=bool(raw.get("isolated_venv", False)),
199
200
  pip_constraints=list(raw.get("pip_constraints", []) or []),
200
201
  vllm_venv=bool(raw.get("vllm_venv", False)),
202
+ cuda_torch=bool(raw.get("cuda_torch", False)),
201
203
  )
202
204
  # Try to enrich with provider code metadata
203
205
  entry = _enrich_from_provider(entry)
@@ -497,7 +497,7 @@ engines:
497
497
  type: tts
498
498
  category: local
499
499
  display_name: "CosyVoice"
500
- description: "CosyVoice — local Chinese TTS (GPU)"
500
+ description: "CosyVoice — local Chinese TTS (GPU)。⚠️ 权重商用条款有争议(上游 issue 未决),研究/内部使用 OK"
501
501
  default_alias: cosyvoice_tts
502
502
  default_exec_mode: subprocess
503
503
  pip_extras: [cosyvoice-tts]
@@ -506,11 +506,14 @@ engines:
506
506
  provider: coqui
507
507
  type: tts
508
508
  category: local
509
- display_name: "Coqui TTS"
510
- description: "Coqui TTS — local neural TTS (experimental)"
509
+ display_name: "Coqui XTTS-v2"
510
+ description: "Coqui TTS 工具箱 — 71 模型:零样本克隆(XTTS-v2/your_tts,需 reference_audio)+ 多说话人音库(VCTK ~109,选 speaker)+ 单说话人。⚠️ XTTS 权重 CPML 非商用(研究/内部);经典模型(VCTK/LJSpeech 用 espeak phonemizer)需系统装 espeak-ng(brew/apt)并在服务 PATH 上"
511
511
  default_alias: coqui_tts
512
- default_exec_mode: in_process
512
+ default_exec_mode: subprocess # 重 + isolated venv(coqui-tts 钉 torch)
513
+ isolated_venv: true
514
+ cuda_torch: true # CUDA 主机(有 nvidia-smi)装 extras 前先从 cu130 index 预装 torch+torchaudio(aarch64 默认 PyPI 是 CPU 版)
513
515
  pip_extras: [coqui-tts]
516
+ pip_constraints: ["transformers>=4.57,<5"] # coqui-tts 0.27.5 声明 >=4.57 但其 tortoise 代码用 isin_mps_friendly(transformers 5.x 已删)→ 封顶 <5 取 4.57.x
514
517
 
515
518
  # ---- macOS Native ----
516
519
  - name: macos-stt
@@ -133,16 +133,43 @@ def create_isolated_venv(repo_root: Path | str, entry, *, timeout: int = 1800) -
133
133
  else:
134
134
  method = "exists"
135
135
 
136
- # 2. Editable-install openspeechapi (base deps incl. msgpack) → IPC compat.
136
+ # 2. Install openspeechapi into the venv (base deps incl. msgpack) → IPC compat. From a
137
+ # source/editable checkout (repo_root has pyproject.toml) use ``-e <repo_root>``; from a
138
+ # PyPI/wheel install (no source — repo_root resolves to site-packages) install the SAME
139
+ # version from the index instead, so pickled providers + msgpack dataclass/enum
140
+ # reconstruction resolve to identical classes. This lets a pip-installed OSA build
141
+ # isolated engine venvs too (no source checkout required).
137
142
  argv, _ = _installer_argv(str(vpy))
138
143
  if argv is None:
139
144
  return IsolatedVenvResult(ok=False, method=method,
140
145
  log="no pip/uv available to install into the venv")
141
- r = _run(argv + ["-e", str(repo_root)], timeout=timeout)
146
+ if (Path(repo_root) / "pyproject.toml").exists():
147
+ osa_target = ["-e", str(repo_root)]
148
+ else:
149
+ from importlib.metadata import PackageNotFoundError
150
+ from importlib.metadata import version as _pkg_version
151
+ try:
152
+ osa_target = [f"openspeechapi=={_pkg_version('openspeechapi')}"]
153
+ except PackageNotFoundError: # pragma: no cover - openspeechapi is always importable at runtime
154
+ osa_target = ["openspeechapi"]
155
+ r = _run(argv + osa_target, timeout=timeout)
142
156
  logs.append((r.stdout or "") + (r.stderr or ""))
143
157
  if r.returncode != 0:
144
158
  return IsolatedVenvResult(ok=False, method=method, log="\n".join(logs)[-4000:])
145
159
 
160
+ # 2.5 CUDA torch pre-install: engines flagged ``cuda_torch`` on a CUDA host get torch+
161
+ # torchaudio from the CUDA wheel index FIRST, so the extras' ``torch>=X`` is satisfied by
162
+ # the GPU build (default PyPI ships CPU-only torch on aarch64 — e.g. the GB10/DGX). Off
163
+ # CUDA hosts (no nvidia-smi, e.g. macOS) this is skipped → extras pull the normal wheel.
164
+ if getattr(entry, "cuda_torch", False) and shutil.which("nvidia-smi"):
165
+ index = os.environ.get(
166
+ "OSA_TORCH_CUDA_INDEX", "https://download.pytorch.org/whl/cu130").strip()
167
+ logs.append(f"[cuda_torch] pre-installing torch+torchaudio+torchcodec from {index}")
168
+ r = _run(argv + ["torch", "torchaudio", "torchcodec", "--index-url", index], timeout=timeout)
169
+ logs.append((r.stdout or "") + (r.stderr or ""))
170
+ if r.returncode != 0:
171
+ return IsolatedVenvResult(ok=False, method=method, log="\n".join(logs)[-4000:])
172
+
146
173
  # 3. Engine extras + version pins, installed into the venv.
147
174
  res = install_extras(
148
175
  repo_root, list(entry.pip_extras or []),
@@ -22,8 +22,10 @@ from __future__ import annotations
22
22
  import asyncio
23
23
  import base64
24
24
  import json
25
+ import os
25
26
  import shlex
26
27
  import shutil
28
+ import signal
27
29
  import subprocess
28
30
  import time
29
31
  from collections.abc import AsyncIterator
@@ -365,7 +367,8 @@ class Qwen3OmniSTT(STTProvider):
365
367
  self._service_log_fh = log_path.open("ab")
366
368
  logger.info("{}: launching vllm-omni (venv) → {}", self.name, " ".join(cmd))
367
369
  self._service_proc = subprocess.Popen(
368
- cmd, stdout=self._service_log_fh, stderr=subprocess.STDOUT, env=env)
370
+ cmd, stdout=self._service_log_fh, stderr=subprocess.STDOUT, env=env,
371
+ start_new_session=True) # own process group → _stop_service reaps vLLM's EngineCore children
369
372
  self._owns_service = True
370
373
  await self._poll_until_healthy(
371
374
  alive=lambda: self._service_proc.poll() is None,
@@ -452,12 +455,29 @@ class Qwen3OmniSTT(STTProvider):
452
455
  # venv-spawned process
453
456
  proc, self._service_proc = self._service_proc, None
454
457
  if proc is not None and self._owns_service and proc.poll() is None:
455
- proc.terminate()
458
+ # vLLM forks an EngineCore (+ workers) child that holds the GPU; killing only the
459
+ # parent orphans it (VRAM leak — the classic "Stop didn't free memory"). Started with
460
+ # start_new_session → signal the whole process GROUP so children are reaped too.
461
+ try:
462
+ pgid = os.getpgid(proc.pid)
463
+ except Exception: # noqa: BLE001 - no pgid (already gone / not a real proc) → single-proc fallback
464
+ pgid = None
465
+
466
+ def _sig(s):
467
+ try:
468
+ if pgid is not None:
469
+ os.killpg(pgid, s)
470
+ else:
471
+ proc.send_signal(s)
472
+ except Exception: # noqa: BLE001
473
+ pass
474
+
475
+ _sig(signal.SIGTERM)
456
476
  try:
457
477
  proc.wait(timeout=15)
458
478
  except subprocess.TimeoutExpired:
459
- proc.kill()
460
- logger.info("{}: stopped managed vllm-omni (venv)", self.name)
479
+ _sig(signal.SIGKILL)
480
+ logger.info("{}: stopped managed vllm-omni (venv) + worker group", self.name)
461
481
  # docker container WE started (--rm → removed on stop)
462
482
  name, self._docker_container = self._docker_container, None
463
483
  if name and self._owns_service:
@@ -24,6 +24,7 @@ class AlibabaTTSSettings(BaseSettings):
24
24
  class AlibabaTTS(TTSProvider):
25
25
  name = "alibaba-tts"
26
26
  provider_type = ProviderType.TTS
27
+ supported_languages = ['zh', 'en', 'yue', 'ja', 'ko', 'de', 'fr', 'es', 'ru', 'pt', 'it', 'ar', 'th', 'id'] # tags/filter only (researched)
27
28
  execution_mode = ExecMode.IN_PROCESS
28
29
  settings_cls = AlibabaTTSSettings
29
30
  capabilities = {Capability.BATCH, Capability.MULTILINGUAL}
@@ -26,6 +26,7 @@ class BaiduTTSSettings(BaseSettings):
26
26
  class BaiduTTS(TTSProvider):
27
27
  name = "baidu-tts"
28
28
  provider_type = ProviderType.TTS
29
+ supported_languages = ['zh', 'en', 'yue'] # tags/filter only (researched)
29
30
  execution_mode = ExecMode.IN_PROCESS
30
31
  settings_cls = BaiduTTSSettings
31
32
  capabilities = {Capability.BATCH, Capability.MULTILINGUAL}
@@ -0,0 +1,412 @@
1
+ """Coqui TTS provider (coqui-tts toolkit) — cloning + built-in voice libraries (subprocess, isolated venv).
2
+
3
+ coqui-tts ships many models; pick one via the ``model`` setting (see field_options):
4
+ • zero-shot cloning — XTTS-v2 (default, 17 langs) / YourTTS: clone from a reference clip
5
+ (``TTSOptions.reference_audio`` raw bytes / base64 / path, or ``settings.speaker_wav``).
6
+ • multi-speaker libraries — e.g. VCTK (~109 built-in voices): pick a speaker via ``TTSOptions.voice``
7
+ or ``settings.speaker`` (no reference needed); ``list_voices()`` exposes the library.
8
+ • single-speaker — e.g. LJSpeech: one fixed voice, needs neither reference nor speaker.
9
+ The loaded model's ``is_multi_lingual`` / ``is_multi_speaker`` decide which tts_to_file kwargs are sent.
10
+
11
+ ⚠️ XTTS-v2 weights are **CPML (NON-COMMERCIAL)** — research/internal use only (per the project's stance).
12
+ Heavy: torch + model → runs in an isolated venv (deps pin torch). XTTS is fetched via aim
13
+ (``hf:coqui/XTTS-v2`` / ``ms:AI-ModelScope/XTTS-v2``); other models download via coqui's own registry.
14
+ """
15
+ from __future__ import annotations
16
+
17
+ import asyncio
18
+ import base64
19
+ import contextlib
20
+ import io
21
+ import json
22
+ import os
23
+ import shutil
24
+ import subprocess
25
+ import tempfile
26
+ import time
27
+ import wave
28
+ from collections.abc import AsyncIterator
29
+ from dataclasses import dataclass
30
+ from typing import Any
31
+
32
+ from openspeechapi.core.base import AimModelSpec, TTSProvider, aim_local_path_or
33
+ from openspeechapi.core.enums import AudioFormat, Capability, ExecMode, ProviderType
34
+ from openspeechapi.core.model_hub import build_aim_spec
35
+ from openspeechapi.core.models import AudioChunk, AudioData, TTSOptions
36
+ from openspeechapi.core.settings import BaseSettings
37
+ from openspeechapi.logging_config import logger
38
+
39
+ _XTTS_HF = "coqui/XTTS-v2"
40
+ _MS_REPOS = {"coqui/XTTS-v2": "AI-ModelScope/XTTS-v2"} # ModelScope mirror (HF-blocked boxes)
41
+
42
+
43
+ def _resolve_gpu(device: str) -> bool:
44
+ """Map the `device` setting to coqui's ``gpu=`` bool. "auto" picks cuda when a GPU is
45
+ visible (DGX/CUDA hosts), else cpu (macOS/CPU — coqui's high-level API has no MPS path)."""
46
+ d = (device or "auto").strip().lower()
47
+ if d == "cuda":
48
+ return True
49
+ if d == "cpu":
50
+ return False
51
+ try:
52
+ import torch
53
+ return bool(torch.cuda.is_available())
54
+ except Exception:
55
+ return False
56
+
57
+
58
+ _CLONING_KEYS = ("xtts", "your_tts", "bark", "tortoise")
59
+
60
+
61
+ def _is_cloning(model: str) -> bool:
62
+ """coqui models that clone a voice from a reference clip (use speaker_wav)."""
63
+ return any(k in (model or "").lower() for k in _CLONING_KEYS)
64
+
65
+
66
+ @contextlib.contextmanager
67
+ def _torch_weights_only_false():
68
+ """Make torch load coqui's registry checkpoints under torch 2.6+. 2.6 flipped torch.load's
69
+ default to ``weights_only=True``, which rejects checkpoints pickling numpy globals (capacitron /
70
+ overflow / neural_hmm stats → ``Unsupported global numpy.core.multiarray.scalar``). coqui's
71
+ models are from its own registry (research/internal), so two belts:
72
+ (1) ``add_safe_globals`` for the numpy globals — caller-agnostic (works no matter how/where the
73
+ checkpoint is loaded, incl. ``torch.serialization.load`` or a saved reference);
74
+ (2) FORCE ``weights_only=False`` on both ``torch.load`` and ``torch.serialization.load`` for
75
+ the duration (override even an explicit ``weights_only=True``).
76
+ No-op if torch isn't importable."""
77
+ try:
78
+ import torch
79
+ except Exception: # pragma: no cover - torch always present in the coqui venv
80
+ yield
81
+ return
82
+ try: # (1) allowlist numpy globals for the weights_only unpickler (idempotent, global)
83
+ import numpy as _np
84
+ import numpy.core.multiarray as _ma
85
+ torch.serialization.add_safe_globals([_ma.scalar, _ma._reconstruct, _np.ndarray, _np.dtype])
86
+ except Exception: # noqa: BLE001 - best-effort; the FORCE below still covers attribute callers
87
+ pass
88
+ # (2) FORCE weights_only=False on both attribute bindings (torch.load IS torch.serialization.load)
89
+ mods = [torch]
90
+ _ts = getattr(torch, "serialization", None)
91
+ if _ts is not None and _ts is not torch:
92
+ mods.append(_ts)
93
+ saved = [(m, m.load) for m in mods if hasattr(m, "load")]
94
+
95
+ def _make(orig):
96
+ def _patched(*args, **kwargs):
97
+ kwargs["weights_only"] = False
98
+ return orig(*args, **kwargs)
99
+ return _patched
100
+
101
+ for m, orig in saved:
102
+ m.load = _make(orig)
103
+ try:
104
+ yield
105
+ finally:
106
+ for m, orig in saved:
107
+ m.load = orig
108
+
109
+
110
+ def _ensure_xtts_speakers(model_dir: str) -> None:
111
+ """XTTS-v2's built-in speakers live in ``speakers_xtts.pth``. The ModelScope mirror
112
+ (AI-ModelScope/XTTS-v2) OMITS that file, so an aim/ms-provisioned XTTS can clone from a
113
+ reference clip but exposes NO built-in voices. Materialise it from HF (honoring HF_ENDPOINT /
114
+ OSA's auto-mirror, so HF-blocked boxes get it via hf-mirror) into the model dir, enabling the
115
+ built-in voice library. No-op when already present; best-effort — cloning works without it."""
116
+ if not model_dir or not os.path.isdir(model_dir):
117
+ return
118
+ target = os.path.join(model_dir, "speakers_xtts.pth")
119
+ if os.path.exists(target):
120
+ return
121
+ try:
122
+ from openspeechapi.core.model_hub import ensure_reachable_download_env
123
+ ensure_reachable_download_env() # HF unreachable → route via hf-mirror (ms mirror lacks this file)
124
+ from huggingface_hub import hf_hub_download
125
+ src = hf_hub_download(repo_id="coqui/XTTS-v2", filename="speakers_xtts.pth")
126
+ shutil.copyfile(src, target)
127
+ logger.info("coqui: materialised XTTS speakers_xtts.pth → {} (built-in voices enabled)", target)
128
+ except Exception as e: # noqa: BLE001 — best-effort; cloning still works without built-in voices
129
+ logger.warning("coqui: could not fetch speakers_xtts.pth ({}); built-in voices unavailable, "
130
+ "cloning still works", e)
131
+
132
+
133
+ _MODELS_CACHE: list[str] | None = None
134
+
135
+
136
+ def list_coqui_models() -> list[str]:
137
+ """coqui's full TTS catalog (~71), ordered common-first (cloning/multilingual → English incl.
138
+ VCTK → other languages). Listed via the isolated venv's python WITHOUT loading any model — a
139
+ model picker shouldn't pay a model load. Cached per process; falls back to the curated
140
+ ``field_options.model`` when the venv / listing is unavailable (so the dropdown is never empty).
141
+ Dynamic so new coqui models need no static maintenance here."""
142
+ global _MODELS_CACHE
143
+ if _MODELS_CACHE is not None:
144
+ return _MODELS_CACHE
145
+ models: list[str] = []
146
+ try:
147
+ from openspeechapi.local_engines.isolated_venv import venv_python
148
+ vpy = str(venv_python("coqui"))
149
+ if os.path.exists(vpy):
150
+ script = (
151
+ "import json;from TTS.api import TTS;"
152
+ "m=TTS().list_models();"
153
+ "m=m.list_models() if hasattr(m,'list_models') else m;"
154
+ "print(json.dumps([x for x in m if isinstance(x,str) and x.startswith('tts_models')]))"
155
+ )
156
+ env = {**os.environ, "COQUI_TOS_AGREED": "1"}
157
+ out = subprocess.run([vpy, "-c", script], capture_output=True, text=True, timeout=90, env=env)
158
+ if out.returncode == 0 and out.stdout.strip():
159
+ models = json.loads(out.stdout.strip().splitlines()[-1])
160
+ except Exception as e: # noqa: BLE001 — best-effort; fall back to the curated list
161
+ logger.debug("coqui list_models via venv failed: {}", e)
162
+
163
+ def _rank(m: str) -> tuple:
164
+ parts = m.split("/")
165
+ lang = parts[1] if len(parts) > 1 else ""
166
+ g = 0 if _is_cloning(m) else 1 if lang == "multilingual" else 2 if lang == "en" else 3
167
+ return (g, lang, m)
168
+
169
+ _MODELS_CACHE = sorted(set(models), key=_rank) if models else list(
170
+ CoquiTTS.field_options.get("model", []))
171
+ return _MODELS_CACHE
172
+
173
+
174
+ _ARCH_FAMILIES = ("xtts", "your_tts", "bark", "tortoise", "tacotron2", "glow-tts",
175
+ "fast_pitch", "fastpitch", "speedy-speech", "overflow", "neural_hmm",
176
+ "capacitron", "vits") # specific first; 'vits' is broad → last
177
+
178
+
179
+ def _model_architecture(model_id: str) -> str:
180
+ """Architecture family from the model id's last segment (vits / tacotron2 / glow-tts / …)."""
181
+ seg = model_id.split("/")[-1].lower()
182
+ for fam in _ARCH_FAMILIES:
183
+ if fam in seg:
184
+ return "fast_pitch" if fam == "fastpitch" else fam
185
+ return seg
186
+
187
+
188
+ def _model_capability(model_id: str) -> str:
189
+ """Coarse capability for the Lab filter: 克隆 / 多说话人 / 单说话人."""
190
+ if _is_cloning(model_id):
191
+ return "克隆 Cloning"
192
+ if any(d in model_id.lower() for d in ("vctk", "libri")): # known multi-speaker datasets
193
+ return "多说话人 Multi-speaker"
194
+ return "单说话人 Single-speaker"
195
+
196
+
197
+ def coqui_model_facets() -> dict:
198
+ """``{model_id: {"capability": ..., "architecture": ...}}`` for the Lab's Model filter bar —
199
+ lets the user narrow the ~71 models by need (capability + architecture) before picking one."""
200
+ return {m: {"capability": _model_capability(m), "architecture": _model_architecture(m)}
201
+ for m in list_coqui_models()}
202
+
203
+
204
+ @dataclass
205
+ class CoquiTTSSettings(BaseSettings):
206
+ model: str = "tts_models/multilingual/multi-dataset/xtts_v2" # Coqui registry id (fallback dl)
207
+ model_path: str = "" # aim-resolved local XTTS dir (model.pth + config.json); preferred
208
+ hub: str = "auto" # aim source: auto follows OSA_DEFAULT_MODEL_SOURCE; force hf|ms
209
+ language: str = "en"
210
+ speaker_wav: str = "" # default reference clip path; per-request override via reference_audio
211
+ speaker: str = "" # built-in voice for multi-speaker models (VCTK id / XTTS built-in); per-request via opts.voice
212
+ device: str = "auto" # "auto" → cuda if a GPU is visible (DGX), else cpu; or force "cpu"/"cuda"
213
+
214
+
215
+ class CoquiTTS(TTSProvider):
216
+ name = "coqui"
217
+ provider_type = ProviderType.TTS
218
+ execution_mode = ExecMode.SUBPROCESS # heavy + isolated venv (torch pin)
219
+ settings_cls = CoquiTTSSettings
220
+ capabilities = {Capability.VOICE_CLONE, Capability.MULTILINGUAL}
221
+ supports_param_overrides = True
222
+ field_options = {
223
+ "model": [
224
+ "tts_models/multilingual/multi-dataset/xtts_v2", # zero-shot clone, 17 langs
225
+ "tts_models/multilingual/multi-dataset/your_tts", # zero-shot clone
226
+ "tts_models/en/vctk/vits", # multi-speaker library (~109 voices)
227
+ "tts_models/en/ljspeech/vits", # single-speaker
228
+ "tts_models/en/ljspeech/tacotron2-DDC", # single-speaker
229
+ "tts_models/en/ljspeech/glow-tts", # single-speaker
230
+ ],
231
+ "language": ["en", "es", "fr", "de", "it", "pt", "pl", "tr", "ru", "nl",
232
+ "cs", "ar", "zh-cn", "ja", "hu", "ko", "hi"],
233
+ "device": ["auto", "cpu", "cuda"],
234
+ }
235
+
236
+ def __init__(self, settings: CoquiTTSSettings | None = None) -> None:
237
+ self.settings = settings or CoquiTTSSettings()
238
+ self._tts: Any = None
239
+ self._client: Any = None
240
+ self._loaded_key: tuple | None = None
241
+
242
+ async def start(self) -> None:
243
+ await self._ensure_model(self.settings)
244
+ self._client = self._tts
245
+ logger.info("{} provider started", self.name)
246
+
247
+ async def stop(self) -> None:
248
+ self._tts = None
249
+ self._client = None
250
+ self._loaded_key = None
251
+ logger.info("{} provider stopped", self.name)
252
+
253
+ async def health_check(self) -> bool:
254
+ return self._tts is not None
255
+
256
+ def aim_model_spec(self) -> AimModelSpec | None:
257
+ """Let aim manage the XTTS-v2 weights (hf coqui/XTTS-v2, ms mirror). category tts/model."""
258
+ return build_aim_spec(_XTTS_HF, self.settings.hub, _MS_REPOS, "tts/model")
259
+
260
+ async def _ensure_model(self, s: "CoquiTTSSettings") -> None:
261
+ gpu = _resolve_gpu(s.device)
262
+ key = (s.model.strip(), s.model_path.strip(), gpu)
263
+ if self._tts is not None and self._loaded_key == key:
264
+ return
265
+ # Prefer the aim-provisioned local dir. If there's no local copy AND aim manages this
266
+ # model, fail fast: coqui-tts's TTS(model_name=...) downloads XTTS straight from
267
+ # huggingface.co (its own requests client — ignores HF_ENDPOINT/mirrors) and hangs
268
+ # indefinitely where HF is unreachable. provision should have set model_path; a clear
269
+ # error beats a silent multi-minute hang. (No aim → keep the direct download so
270
+ # unrestricted hosts still auto-download, per the aim-optional design.)
271
+ local = aim_local_path_or(s.model_path, "") if "xtts" in s.model.lower() else "" # model_path (aim) is the XTTS dir; other models download by name
272
+ if not (local and os.path.isdir(local)) and "xtts" in s.model.lower():
273
+ from openspeechapi.local_engines.aim_resolver import aim_available
274
+ if aim_available():
275
+ raise RuntimeError(
276
+ "coqui XTTS not provisioned: settings.model_path is empty. Provision it via the "
277
+ "Engines '下载模型' button (or `aim download ms:AI-ModelScope/XTTS-v2 "
278
+ "--category tts/model`) then set settings.model_path. Refusing the direct-"
279
+ "HuggingFace fallback — coqui ignores the mirror and it hangs on restricted networks.")
280
+ os.environ.setdefault("COQUI_TOS_AGREED", "1") # research/internal: auto-accept CPML (worker has no stdin for the interactive prompt)
281
+ try:
282
+ from TTS.api import TTS
283
+ except ImportError as exc: # pragma: no cover - import guard
284
+ raise ImportError(
285
+ "Install coqui TTS: pip install 'openspeechapi[coqui]'") from exc
286
+
287
+ def _load() -> Any:
288
+ with _torch_weights_only_false(): # torch 2.6+ weights_only=True rejects capacitron/overflow/… numpy-pickled ckpts
289
+ if local and os.path.isdir(local):
290
+ if "xtts" in s.model.lower():
291
+ _ensure_xtts_speakers(local) # ms mirror omits built-in speakers — materialise them
292
+ return TTS(model_path=local, config_path=os.path.join(local, "config.json"),
293
+ gpu=gpu)
294
+ return TTS(model_name=s.model, gpu=gpu) # aim absent → coqui's own HF auto-download
295
+
296
+ self._tts = await asyncio.to_thread(_load)
297
+ self._loaded_key = key
298
+
299
+ async def synthesize(self, text: str, opts: TTSOptions | None = None) -> AudioData:
300
+ if self._tts is None:
301
+ raise RuntimeError("Provider not started — call start() first")
302
+ opts = opts or TTSOptions()
303
+ logger.info("{}: request received, text={} chars", self.name, len(text))
304
+ s = self._effective_settings(opts, typed_map={"model": "model", "language": "language"})
305
+ await self._ensure_model(s)
306
+ lang = (opts.language or s.language or "en").strip()
307
+ ref = self._resolve_reference(opts, s)
308
+ speaker = (opts.voice or s.speaker or "").strip() or None
309
+ # cloning models clone from `ref`; multi-speaker models need a built-in `speaker` (voice);
310
+ # single-speaker models need neither. XTTS is both (clone via ref OR a built-in speaker).
311
+ needs_voice = _is_cloning(s.model) or bool(getattr(self._tts, "is_multi_speaker", False))
312
+ if needs_voice and not ref and not speaker:
313
+ raise ValueError(
314
+ "coqui: this model needs a voice — upload a reference clip to clone (reference_audio) "
315
+ "or pick a built-in speaker (Voice / settings.speaker). Single-speaker models need neither.")
316
+ _t0 = time.perf_counter()
317
+ wav_bytes, sr = await asyncio.to_thread(self._synth, text, ref, lang, speaker)
318
+ logger.info("{}: completed in {:.0f}ms, {} bytes @ {}Hz",
319
+ self.name, (time.perf_counter() - _t0) * 1000, len(wav_bytes), sr)
320
+ return AudioData(data=wav_bytes, sample_rate=sr, channels=1, format=AudioFormat.WAV)
321
+
322
+ def _synth(self, text: str, ref: str | None, lang: str, speaker: str | None = None) -> tuple[bytes, int]:
323
+ """Blocking coqui synth → (wav_bytes, sample_rate). Runs in a worker thread. Builds the
324
+ tts_to_file kwargs from the LOADED model's capabilities: language (multilingual only),
325
+ speaker_wav (clone from a reference) OR speaker (a built-in multi-speaker voice)."""
326
+ t = self._tts
327
+ with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as f:
328
+ out = f.name
329
+ kwargs: dict[str, Any] = {"text": text, "file_path": out}
330
+ if getattr(t, "is_multi_lingual", False) and lang:
331
+ kwargs["language"] = lang
332
+ if ref:
333
+ kwargs["speaker_wav"] = ref # clone from the reference
334
+ elif speaker and getattr(t, "is_multi_speaker", False):
335
+ kwargs["speaker"] = speaker # built-in voice (VCTK / XTTS)
336
+ try:
337
+ t.tts_to_file(**kwargs)
338
+ data = open(out, "rb").read()
339
+ finally:
340
+ try:
341
+ os.unlink(out)
342
+ except OSError:
343
+ pass
344
+ with wave.open(io.BytesIO(data), "rb") as w:
345
+ sr = int(w.getframerate())
346
+ return data, sr
347
+
348
+ def _resolve_reference(self, opts: TTSOptions, s: "CoquiTTSSettings") -> str | None:
349
+ """Reference → a local WAV path. Accepts a path, base64, or raw bytes; bytes/base64 are
350
+ written to a temp WAV."""
351
+ ref = opts.reference_audio if opts.reference_audio is not None else (s.speaker_wav or None)
352
+ if not ref:
353
+ return None
354
+ if isinstance(ref, str):
355
+ if os.path.exists(ref):
356
+ return ref
357
+ try:
358
+ raw = base64.b64decode(ref, validate=True)
359
+ except Exception: # noqa: BLE001 - not base64 → treat as a path/URL string
360
+ return ref
361
+ else:
362
+ raw = ref
363
+ f = tempfile.NamedTemporaryFile(suffix=".wav", delete=False)
364
+ f.write(raw)
365
+ f.close()
366
+ return f.name
367
+
368
+ @classmethod
369
+ def available_models(cls) -> list[str]:
370
+ """Full coqui model catalog for the UI model picker (dynamic, via the venv) — surfaced by
371
+ /admin/provider-templates as field_options.model, replacing the curated static list."""
372
+ return list_coqui_models()
373
+
374
+ @classmethod
375
+ def model_facets(cls) -> dict:
376
+ """Per-model {capability, architecture} for the Lab Model filter bar (surfaced by
377
+ /admin/provider-templates as ``model_facets`` — narrow the model list by need)."""
378
+ return coqui_model_facets()
379
+
380
+ async def list_voices(self, model: str | None = None) -> list[dict]:
381
+ """Built-in speakers of the loaded multi-speaker model (XTTS built-in voices, VCTK speakers,
382
+ …) so the Lab Voice dropdown can offer them — pick one to skip uploading a reference clip.
383
+ Empty for single-speaker models (cloning still works via reference_audio). Drops malformed
384
+ entries (coqui's VCTK list carries a whitespace-wrapped ``'ED\\n'`` artifact that loses its
385
+ newline through the UI → ``'ED is not a valid speaker'``) and de-dups; internal spaces (XTTS
386
+ names like 'Claribel Dervla') are kept. ``model`` (the Lab's selected model — Model↔Voice
387
+ linkage) loads THAT model first so the speakers match it (bad/unprovisioned model → [])."""
388
+ if model and model.strip():
389
+ from dataclasses import replace
390
+ try:
391
+ await self._ensure_model(replace(self.settings, model=model.strip()))
392
+ except Exception as e: # noqa: BLE001 — bad/unprovisioned model → no voices (UI hints)
393
+ logger.debug("coqui list_voices: load model {} failed: {}", model, e)
394
+ return []
395
+ t = self._tts
396
+ if t is None or not getattr(t, "is_multi_speaker", False):
397
+ return []
398
+ out: list[dict] = []
399
+ seen: set[str] = set()
400
+ for s in (getattr(t, "speakers", None) or []):
401
+ sid = str(s).strip()
402
+ if not sid or sid != str(s) or sid in seen: # empty / surrounding-whitespace artifact / dup
403
+ continue
404
+ seen.add(sid)
405
+ out.append({"id": sid, "name": sid})
406
+ return out
407
+
408
+ async def synthesize_stream(
409
+ self, text: str, opts: TTSOptions | None = None
410
+ ) -> AsyncIterator[AudioChunk]:
411
+ raise NotImplementedError("CoquiTTS (XTTS) does not support streaming synthesis")
412
+ yield # pragma: no cover
@@ -33,6 +33,7 @@ class CosyVoiceTTSSettings(BaseSettings):
33
33
  class CosyVoiceTTS(TTSProvider):
34
34
  name = "cosyvoice"
35
35
  provider_type = ProviderType.TTS
36
+ supported_languages = ['zh', 'en', 'yue', 'ja', 'ko'] # tags/filter only (researched)
36
37
  execution_mode = ExecMode.SUBPROCESS
37
38
  settings_cls = CosyVoiceTTSSettings
38
39
  capabilities = {Capability.VOICE_CLONE, Capability.MULTILINGUAL}
@@ -23,6 +23,7 @@ class DeepgramTTSSettings(BaseSettings):
23
23
  class DeepgramTTS(TTSProvider):
24
24
  name = "deepgram-tts"
25
25
  provider_type = ProviderType.TTS
26
+ supported_languages = ['en', 'es'] # tags/filter only (researched)
26
27
  execution_mode = ExecMode.IN_PROCESS
27
28
  settings_cls = DeepgramTTSSettings
28
29
  capabilities = {Capability.STREAMING, Capability.MULTILINGUAL}
@@ -76,6 +76,7 @@ class IflytekTTSSettings(BaseSettings):
76
76
  class IflytekTTS(TTSProvider):
77
77
  name = "iflytek-tts"
78
78
  provider_type = ProviderType.TTS
79
+ supported_languages = ['zh', 'en', 'yue', 'ja', 'ko'] # tags/filter only (researched)
79
80
  execution_mode = ExecMode.IN_PROCESS
80
81
  settings_cls = IflytekTTSSettings
81
82
  capabilities = {Capability.BATCH, Capability.STREAMING, Capability.MULTILINGUAL}
@@ -60,6 +60,7 @@ class MacOSSayTTS(TTSProvider):
60
60
 
61
61
  name = "macos-say"
62
62
  provider_type = ProviderType.TTS
63
+ supported_languages = ['en', 'zh', 'ja', 'ko', 'de', 'fr', 'es', 'it'] # tags/filter only (researched)
63
64
  execution_mode = ExecMode.IN_PROCESS
64
65
  settings_cls = MacOSSaySettings
65
66
  capabilities = {Capability.BATCH, Capability.MULTILINGUAL}