openspeechapi 0.2.22__tar.gz → 0.2.23__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 (163) hide show
  1. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/PKG-INFO +1 -1
  2. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/config.py +25 -3
  3. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/core/model_hub.py +13 -6
  4. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/providers/stt/canary_qwen_stt.py +21 -3
  5. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/providers/stt/faster_whisper.py +40 -2
  6. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/providers/stt/fireredasr_stt.py +32 -3
  7. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/providers/stt/mms_stt.py +22 -4
  8. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/providers/stt/moonshine_stt.py +27 -8
  9. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/providers/stt/phi4_multimodal_stt.py +22 -4
  10. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/providers/stt/qwen3_omni_stt.py +54 -4
  11. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/providers/stt/vosk_stt.py +80 -5
  12. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/providers/stt/whisper.py +84 -2
  13. openspeechapi-0.2.23/openspeechapi/server/model_downloads.py +396 -0
  14. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/server/routes/management.py +80 -6
  15. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/server/webui/app.js +156 -22
  16. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/server/webui/styles.css +13 -0
  17. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/server/ws/stt_stream.py +25 -0
  18. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/pyproject.toml +1 -1
  19. openspeechapi-0.2.22/openspeechapi/server/model_downloads.py +0 -191
  20. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/.gitignore +0 -0
  21. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/README.md +0 -0
  22. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/__init__.py +0 -0
  23. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/__main__.py +0 -0
  24. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/cli.py +0 -0
  25. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/client/__init__.py +0 -0
  26. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/client/client.py +0 -0
  27. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/core/__init__.py +0 -0
  28. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/core/base.py +0 -0
  29. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/core/enums.py +0 -0
  30. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/core/models.py +0 -0
  31. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/core/registry.py +0 -0
  32. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/core/settings.py +0 -0
  33. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/demo.py +0 -0
  34. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/dispatch/__init__.py +0 -0
  35. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/dispatch/aim_provision.py +0 -0
  36. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/dispatch/context.py +0 -0
  37. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/dispatch/dispatcher.py +0 -0
  38. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/dispatch/executors/__init__.py +0 -0
  39. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/dispatch/executors/base.py +0 -0
  40. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/dispatch/executors/in_process.py +0 -0
  41. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/dispatch/executors/remote.py +0 -0
  42. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/dispatch/executors/subprocess_exec.py +0 -0
  43. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/dispatch/fanout.py +0 -0
  44. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/dispatch/filters.py +0 -0
  45. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/dispatch/lifecycle.py +0 -0
  46. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/dispatch/watcher.py +0 -0
  47. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/engine_catalog.py +0 -0
  48. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/engine_registry.yaml +0 -0
  49. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/exceptions.py +0 -0
  50. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/factory.py +0 -0
  51. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/local_engines/__init__.py +0 -0
  52. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/local_engines/aim_resolver.py +0 -0
  53. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/local_engines/backends/__init__.py +0 -0
  54. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/local_engines/backends/docker_backend.py +0 -0
  55. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/local_engines/backends/native_backend.py +0 -0
  56. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/local_engines/base.py +0 -0
  57. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/local_engines/engines/__init__.py +0 -0
  58. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/local_engines/engines/faster_whisper.py +0 -0
  59. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/local_engines/engines/fish_speech.py +0 -0
  60. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/local_engines/engines/sherpa_onnx.py +0 -0
  61. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/local_engines/engines/whisper.py +0 -0
  62. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/local_engines/engines/whisperlivekit.py +0 -0
  63. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/local_engines/isolated_venv.py +0 -0
  64. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/local_engines/manager.py +0 -0
  65. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/local_engines/models.py +0 -0
  66. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/local_engines/progress.py +0 -0
  67. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/local_engines/registry.py +0 -0
  68. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/local_engines/task_store.py +0 -0
  69. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/local_engines/tasks.py +0 -0
  70. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/logging_config.py +0 -0
  71. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/observe/__init__.py +0 -0
  72. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/observe/base.py +0 -0
  73. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/observe/debug.py +0 -0
  74. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/observe/latency.py +0 -0
  75. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/observe/metrics.py +0 -0
  76. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/observe/tracing.py +0 -0
  77. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/observe/usage.py +0 -0
  78. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/providers/__init__.py +0 -0
  79. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/providers/_template.py +0 -0
  80. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/providers/stt/__init__.py +0 -0
  81. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/providers/stt/_local_audio.py +0 -0
  82. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/providers/stt/alibaba.py +0 -0
  83. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/providers/stt/assemblyai.py +0 -0
  84. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/providers/stt/azure_speech.py +0 -0
  85. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/providers/stt/baidu.py +0 -0
  86. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/providers/stt/deepgram.py +0 -0
  87. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/providers/stt/dolphin_stt.py +0 -0
  88. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/providers/stt/elevenlabs.py +0 -0
  89. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/providers/stt/funasr_stt.py +0 -0
  90. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/providers/stt/gemma4.py +0 -0
  91. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/providers/stt/google_cloud.py +0 -0
  92. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/providers/stt/iflytek.py +0 -0
  93. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/providers/stt/kimi_audio_stt.py +0 -0
  94. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/providers/stt/macos_speech.py +0 -0
  95. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/providers/stt/mlx_whisper_stt.py +0 -0
  96. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/providers/stt/mms_languages.json +0 -0
  97. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/providers/stt/openai.py +0 -0
  98. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/providers/stt/paraformer.py +0 -0
  99. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/providers/stt/parakeet_mlx_stt.py +0 -0
  100. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/providers/stt/qwen3_asr.py +0 -0
  101. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/providers/stt/sensevoice.py +0 -0
  102. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/providers/stt/sherpa_onnx.py +0 -0
  103. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/providers/stt/tencent.py +0 -0
  104. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/providers/stt/volcengine.py +0 -0
  105. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/providers/stt/voxtral_stt.py +0 -0
  106. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/providers/stt/wenet_stt.py +0 -0
  107. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/providers/stt/whisperlivekit.py +0 -0
  108. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/providers/stt/windows_speech.py +0 -0
  109. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/providers/tts/__init__.py +0 -0
  110. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/providers/tts/alibaba.py +0 -0
  111. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/providers/tts/azure_speech.py +0 -0
  112. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/providers/tts/baidu.py +0 -0
  113. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/providers/tts/coqui.py +0 -0
  114. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/providers/tts/cosyvoice.py +0 -0
  115. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/providers/tts/deepgram.py +0 -0
  116. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/providers/tts/elevenlabs.py +0 -0
  117. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/providers/tts/fish_speech.py +0 -0
  118. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/providers/tts/google_cloud.py +0 -0
  119. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/providers/tts/iflytek.py +0 -0
  120. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/providers/tts/macos_say.py +0 -0
  121. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/providers/tts/minimax.py +0 -0
  122. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/providers/tts/openai.py +0 -0
  123. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/providers/tts/piper.py +0 -0
  124. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/providers/tts/tencent.py +0 -0
  125. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/providers/tts/volcengine.py +0 -0
  126. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/providers/tts/windows_sapi.py +0 -0
  127. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/server/__init__.py +0 -0
  128. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/server/app.py +0 -0
  129. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/server/auth.py +0 -0
  130. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/server/extras_installer.py +0 -0
  131. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/server/middleware.py +0 -0
  132. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/server/native_installer.py +0 -0
  133. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/server/routes/__init__.py +0 -0
  134. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/server/routes/stt.py +0 -0
  135. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/server/routes/tts.py +0 -0
  136. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/server/routes/webui.py +0 -0
  137. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/server/system_metrics.py +0 -0
  138. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/server/webui/index.html +0 -0
  139. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/server/ws/__init__.py +0 -0
  140. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/server/ws/tts_stream.py +0 -0
  141. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/telemetry/__init__.py +0 -0
  142. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/telemetry/perf.py +0 -0
  143. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/utils/__init__.py +0 -0
  144. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/utils/audio_converter.py +0 -0
  145. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/utils/audio_playback.py +0 -0
  146. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/openspeechapi/vendor_registry.yaml +0 -0
  147. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/providers.example.yaml +0 -0
  148. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/scripts/aim_adopt.py +0 -0
  149. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/scripts/aim_consumers.py +0 -0
  150. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/scripts/engines/cloud/install.sh +0 -0
  151. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/scripts/engines/faster-whisper/native/install.sh +0 -0
  152. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/scripts/engines/fish-speech/native/install.sh +0 -0
  153. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/scripts/engines/macos-stt/_bundle.sh +0 -0
  154. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/scripts/engines/macos-stt/install.sh +0 -0
  155. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/scripts/engines/macos-stt/macos_stt.swift +0 -0
  156. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/scripts/engines/macos-stt/request_auth.swift +0 -0
  157. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/scripts/engines/sherpa-onnx/native/install.sh +0 -0
  158. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/scripts/engines/sherpa-onnx/native/run_streaming_server.py +0 -0
  159. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/scripts/engines/whisper/native/install.sh +0 -0
  160. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/scripts/engines/whisperlivekit/native/install.sh +0 -0
  161. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/scripts/gen_mms_languages.py +0 -0
  162. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/scripts/preload_stt_model.py +0 -0
  163. {openspeechapi-0.2.22 → openspeechapi-0.2.23}/scripts/release.sh +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: openspeechapi
3
- Version: 0.2.22
3
+ Version: 0.2.23
4
4
  Summary: Unified speech interface for STT/TTS providers
5
5
  Requires-Python: >=3.11
6
6
  Requires-Dist: httpx>=0.27
@@ -120,6 +120,14 @@ class ServerConfig:
120
120
  # multi-engine / memory-constrained boxes so idle engines free their GPU/RAM after N seconds
121
121
  # of inactivity (auto-reloaded on next request). A per-engine ``keepalive > 0`` overrides this.
122
122
  default_keepalive: int = 0
123
+ # Keepalive FLOOR (seconds) for reload-expensive LOCAL engines (subprocess/local model
124
+ # loaders, e.g. gemma4 / qwen3-omni). A short ``default_keepalive`` (e.g. 600) idle-unloads a
125
+ # multi-GB model between interactive requests; the cold reload (tens of seconds to minutes,
126
+ # worse under concurrent disk I/O) then reads as "no result" in live mic. This floors the
127
+ # INHERITED keepalive for such engines so interactive use stays warm, while cloud/native
128
+ # engines (cheap to reconnect) keep the shorter default. Only raises an inherited value — an
129
+ # explicit per-engine ``keepalive`` (incl. 0 = never unload) is respected. 0 disables.
130
+ keepalive_floor_local: int = 1800
123
131
 
124
132
 
125
133
  @dataclass
@@ -272,17 +280,31 @@ def load_config(path: Path) -> OpenSpeechConfig:
272
280
  0, int(srv.get("default_keepalive", server_cfg.default_keepalive)))
273
281
  except (TypeError, ValueError):
274
282
  pass
283
+ try:
284
+ server_cfg.keepalive_floor_local = max(
285
+ 0, int(srv.get("keepalive_floor_local", server_cfg.keepalive_floor_local)))
286
+ except (TypeError, ValueError):
287
+ pass
275
288
  auth = srv.get("auth", {})
276
289
  if auth:
277
290
  server_cfg.auth_enabled = bool(auth.get("enabled", False))
278
291
  server_cfg.api_keys = list(auth.get("api_keys", []))
279
292
 
280
293
  # Engines that didn't set their own keepalive inherit the global default (so operators can
281
- # set one idle-unload policy via server.default_keepalive instead of per-engine).
294
+ # set one idle-unload policy via server.default_keepalive instead of per-engine). Reload-
295
+ # expensive LOCAL loaders (subprocess/local) additionally get a keepalive FLOOR so a short
296
+ # global default doesn't idle-unload a multi-GB model between interactive requests (the cold
297
+ # reload reads as "no result" in live mic). Only an INHERITED value (keepalive == 0) is
298
+ # adjusted — an explicit per-engine keepalive is respected as-is.
299
+ _LOCAL_LOADERS = {"subprocess", "local"}
282
300
  if server_cfg.default_keepalive > 0:
283
301
  for eng in engines.values():
284
- if eng.keepalive == 0:
285
- eng.keepalive = server_cfg.default_keepalive
302
+ if eng.keepalive != 0:
303
+ continue
304
+ eng.keepalive = server_cfg.default_keepalive
305
+ if (server_cfg.keepalive_floor_local > 0
306
+ and str(eng.exec_mode).strip().lower() in _LOCAL_LOADERS):
307
+ eng.keepalive = max(eng.keepalive, server_cfg.keepalive_floor_local)
286
308
 
287
309
  return OpenSpeechConfig(
288
310
  engines=engines,
@@ -112,10 +112,12 @@ def effective_source(hub: str) -> str:
112
112
  """Effective download source for a model: 'hf' or 'ms'.
113
113
 
114
114
  - explicit engine hub 'ms'/'hf' wins
115
- - ``'auto'`` → reachability-aware: the operator default (OSA_DEFAULT_MODEL_SOURCE) when
116
- its source is reachable; else ModelScope if reachable (funasr-native, works on
117
- HF-blocked nets); else HuggingFace (direct or via auto-mirror). This only decides a
118
- *fresh* download's source — _materialise reuses any already-downloaded copy first.
115
+ - ``'auto'`` → explicit ms default is TRUSTED unconditionally (a transient probe must not flip
116
+ an ms-preferred, usually HF-blocked box to HF — that caused FunASR engines to re-fetch from
117
+ HF and stall); explicit hf default uses hf when reachable, else falls back to ms (HF-block-
118
+ proofing); with NO explicit default: ModelScope if reachable (funasr-native) else HuggingFace
119
+ (direct or via auto-mirror). Only decides a *fresh* download's source — _materialise reuses
120
+ any already-downloaded copy first.
119
121
  - hub '' → global OSA_DEFAULT_MODEL_SOURCE (default 'hf')
120
122
  - back-compat: OSA_PREFER_MODELSCOPE=1 with no explicit default → 'ms'
121
123
  """
@@ -124,11 +126,16 @@ def effective_source(hub: str) -> str:
124
126
  return h
125
127
  glob = os.environ.get("OSA_DEFAULT_MODEL_SOURCE", "").strip().lower()
126
128
  if h == "auto":
129
+ # Explicit ms default → TRUST it, no reachability gate. ms-preferred boxes are typically
130
+ # HF-blocked, so a transient ms probe failure must NOT flip them to HF — that made
131
+ # FunASR-style engines re-fetch the model/VAD from HF, causing duplicate downloads +
132
+ # stalls. (hf default keeps its probe + ms fallback below, which is the HF-block-proofing
133
+ # for hf-preferred boxes; only ms-trust is unconditional.)
134
+ if glob == "ms":
135
+ return "ms"
127
136
  reach = reachable_sources()
128
137
  if glob == "hf" and (reach["hf"] or reach["hf_mirror"]):
129
138
  return "hf"
130
- if glob == "ms" and reach["ms"]:
131
- return "ms"
132
139
  if reach["ms"]:
133
140
  return "ms" # ModelScope reachable → prefer it (HF-block-proof)
134
141
  return "hf" # HF direct, or auto-mirror via ensure_reachable_download_env
@@ -16,8 +16,9 @@ from collections.abc import AsyncIterator
16
16
  from dataclasses import dataclass
17
17
  from typing import Any
18
18
 
19
- from openspeechapi.core.base import STTProvider
19
+ from openspeechapi.core.base import AimModelSpec, STTProvider, aim_local_path_or
20
20
  from openspeechapi.core.enums import Capability, ExecMode, ProviderType
21
+ from openspeechapi.core.model_hub import build_aim_spec
21
22
  from openspeechapi.core.models import AudioData, STTOptions, Transcription
22
23
  from openspeechapi.core.settings import BaseSettings
23
24
  from openspeechapi.logging_config import logger
@@ -27,6 +28,10 @@ from openspeechapi.providers.stt._local_audio import duration_ms, write_temp_wav
27
28
  @dataclass
28
29
  class CanaryQwenSTTSettings(BaseSettings):
29
30
  model: str = "nvidia/canary-qwen-2.5b"
31
+ # aim-resolved local path, set by the main-process aim provisioning step and
32
+ # persisted to providers.yaml. When set + present on disk, the loader uses it
33
+ # instead of `model` (keeps working when aim is absent — falls back to the repo id).
34
+ model_path: str = ""
30
35
  device: str = "cpu" # cpu | cuda (GPU strongly recommended)
31
36
  dtype: str = "bfloat16" # bfloat16 | float32
32
37
  max_new_tokens: int = 128
@@ -66,8 +71,17 @@ class CanaryQwenSTT(STTProvider):
66
71
  async def health_check(self) -> bool:
67
72
  return self._model is not None
68
73
 
74
+ def aim_model_spec(self) -> AimModelSpec | None:
75
+ """Let aim (ai-model-manager) download + manage the weights, per CLAUDE.md's aim
76
+ rule. ``SALM.from_pretrained`` loads from a HF repo id; ``build_aim_spec`` adds
77
+ existing-copy-first (defers to a copy already in the HF cache instead of having aim
78
+ re-download) and the ``hf:`` scheme. canary-qwen has no ModelScope mirror, so the
79
+ hub is fixed to ``hf``."""
80
+ return build_aim_spec(self.settings.model, "hf", None, "asr/model")
81
+
69
82
  async def _ensure_model(self, s: "CanaryQwenSTTSettings") -> None:
70
- key = (s.model.strip(), s.device.strip(), s.dtype.strip())
83
+ # model_path changes the resolved load target → part of the reload key.
84
+ key = (s.model.strip(), s.model_path.strip(), s.device.strip(), s.dtype.strip())
71
85
  if self._model is not None and self._loaded_key == key:
72
86
  return
73
87
  try:
@@ -79,8 +93,12 @@ class CanaryQwenSTT(STTProvider):
79
93
  "pip install 'nemo_toolkit[asr] @ git+https://github.com/NVIDIA/NeMo.git'"
80
94
  ) from exc
81
95
 
96
+ # Load from the aim-provisioned local path when set + present on disk; else the repo
97
+ # id (NeMo downloads it). Keeps working when aim is absent (falls back to the id).
98
+ target = aim_local_path_or(s.model_path, s.model)
99
+
82
100
  def _load() -> Any:
83
- m = SALM.from_pretrained(s.model)
101
+ m = SALM.from_pretrained(target)
84
102
  if s.dtype.strip().lower() == "bfloat16":
85
103
  m = m.bfloat16()
86
104
  return m.eval().to(s.device)
@@ -10,15 +10,36 @@ from collections.abc import AsyncIterator
10
10
  from dataclasses import dataclass
11
11
  from typing import Any
12
12
 
13
- from openspeechapi.core.base import STTProvider
13
+ from openspeechapi.core.base import AimModelSpec, STTProvider, aim_local_path_or
14
14
 
15
15
  from openspeechapi.core.enums import Capability, ExecMode, ProviderType
16
+ from openspeechapi.core.model_hub import build_aim_spec
16
17
  from openspeechapi.core.models import AudioData, STTOptions, Transcription, Word
17
18
  from openspeechapi.core.settings import BaseSettings
18
19
 
20
+ # faster-whisper's own size→HF-repo map (faster_whisper.utils._MODELS), restricted to the
21
+ # sizes we offer in field_options. Used to give aim a concrete `hf:<repo>` source — aim
22
+ # can't act on a bare size alias like "large-v3". NOTE: the turbo + large aliases live
23
+ # under different orgs (mobiuslabsgmbh / large-v3), so this can't be derived by f-string.
24
+ _FW_REPOS = {
25
+ "tiny": "Systran/faster-whisper-tiny",
26
+ "base": "Systran/faster-whisper-base",
27
+ "small": "Systran/faster-whisper-small",
28
+ "medium": "Systran/faster-whisper-medium",
29
+ "large-v2": "Systran/faster-whisper-large-v2",
30
+ "large-v3": "Systran/faster-whisper-large-v3",
31
+ "large-v3-turbo": "mobiuslabsgmbh/faster-whisper-large-v3-turbo",
32
+ }
33
+
34
+
19
35
  @dataclass
20
36
  class FasterWhisperSTTSettings(BaseSettings):
21
37
  model_size: str = "base"
38
+ # aim-resolved local path, set by the main-process aim provisioning step and persisted
39
+ # to providers.yaml. When set + present on disk, the loader uses it instead of the size
40
+ # alias (keeps working when aim is absent — falls back to the size, which faster-whisper
41
+ # resolves to its HF repo itself).
42
+ model_path: str = ""
22
43
  device: str = "auto"
23
44
  compute_type: str = "default"
24
45
  download_root: str | None = None
@@ -53,6 +74,18 @@ class FasterWhisperSTT(STTProvider):
53
74
  )
54
75
  logger.info("{} provider started", self.name)
55
76
 
77
+ def aim_model_spec(self) -> AimModelSpec | None:
78
+ """Let aim (ai-model-manager) download + manage the weights, per CLAUDE.md's aim
79
+ rule. faster-whisper resolves a size alias (e.g. "large-v3") to a HF repo
80
+ internally; map it back via ``_FW_REPOS`` so aim gets a concrete ``hf:<repo>``.
81
+ ``build_aim_spec`` adds existing-copy-first (defers to a copy already in the HF
82
+ cache) and the ``hf:`` scheme. None when the configured size is a local dir or an
83
+ unknown alias (no repo to map → fall back to faster-whisper's own download)."""
84
+ repo = _FW_REPOS.get((self.settings.model_size or "").strip())
85
+ if not repo:
86
+ return None
87
+ return build_aim_spec(repo, "hf", None, "asr/model")
88
+
56
89
  async def _ensure_model(
57
90
  self,
58
91
  *,
@@ -67,7 +100,12 @@ class FasterWhisperSTT(STTProvider):
67
100
  "Install faster-whisper: pip install openspeechapi[faster-whisper]"
68
101
  )
69
102
 
70
- normalized_model_size = self._resolve_model_dir(model_size)
103
+ # Prefer the aim-provisioned local dir when set + present on disk; else the size
104
+ # alias (faster-whisper resolves it to its HF repo and downloads). Keeps working
105
+ # when aim is absent (falls back to the alias).
106
+ normalized_model_size = self._resolve_model_dir(
107
+ aim_local_path_or(self.settings.model_path, model_size)
108
+ )
71
109
 
72
110
  if (
73
111
  self._model is not None
@@ -5,8 +5,12 @@ strong singing-lyrics recognition. Two variants:
5
5
  * ``aed`` — FireRedASR-AED-L (attention-encoder-decoder), audio ≤ 60s
6
6
  * ``llm`` — FireRedASR-LLM-L (LLM-based), audio ≤ 30s
7
7
 
8
- Weights are downloaded from HuggingFace to a local dir (the FireRedAsr API loads
9
- from a directory, not a repo id), then ``from_pretrained(type, dir)`` loads them.
8
+ Weights are pulled from **ModelScope** by fireredasr itself — its
9
+ ``FireRedAsr.from_pretrained(asr_type)`` calls ``modelscope.snapshot_download(
10
+ "pengzhendong/FireRedASR-<TYPE>-L")`` internally (it takes ONLY the type, computes the
11
+ repo + cache dir itself, and exposes no path/repo override). So aim can pre-fetch the
12
+ weights (download button + lazy-start), but the load call can't be redirected to an
13
+ aim-resolved ``model_path`` the way the other engines are — see ``aim_model_spec``.
10
14
 
11
15
  Capabilities: BATCH + MULTILINGUAL. Offline batch model.
12
16
  """
@@ -19,13 +23,21 @@ from collections.abc import AsyncIterator
19
23
  from dataclasses import dataclass
20
24
  from typing import Any
21
25
 
22
- from openspeechapi.core.base import STTProvider
26
+ from openspeechapi.core.base import AimModelSpec, STTProvider
23
27
  from openspeechapi.core.enums import Capability, ExecMode, ProviderType
28
+ from openspeechapi.core.model_hub import build_aim_spec
24
29
  from openspeechapi.core.models import AudioData, STTOptions, Transcription
25
30
  from openspeechapi.core.settings import BaseSettings
26
31
  from openspeechapi.logging_config import logger
27
32
  from openspeechapi.providers.stt._local_audio import duration_ms, write_temp_wav
28
33
 
34
+ # fireredasr's hardcoded ModelScope repo per variant (FireRedAsr.from_pretrained →
35
+ # snapshot_download(f"pengzhendong/FireRedASR-{TYPE}-L")). Drives the aim source.
36
+ _FIRERED_REPOS = {
37
+ "aed": "pengzhendong/FireRedASR-AED-L",
38
+ "llm": "pengzhendong/FireRedASR-LLM-L",
39
+ }
40
+
29
41
 
30
42
  @dataclass
31
43
  class FireRedASRSTTSettings(BaseSettings):
@@ -68,6 +80,23 @@ class FireRedASRSTT(STTProvider):
68
80
  async def health_check(self) -> bool:
69
81
  return self._model is not None
70
82
 
83
+ def aim_model_spec(self) -> AimModelSpec | None:
84
+ """Let aim (ai-model-manager) pre-fetch the weights, per CLAUDE.md's aim rule.
85
+ fireredasr downloads from **ModelScope** (``snapshot_download("pengzhendong/
86
+ FireRedASR-<TYPE>-L")``), so the aim source uses the ``ms:`` scheme via
87
+ ``build_aim_spec`` (which also defers to an already-downloaded copy → returns None).
88
+
89
+ NOTE: this only makes aim DOWNLOAD the weights ahead of time (WebUI button /
90
+ lazy-start). fireredasr's ``from_pretrained(asr_type)`` takes no path/repo and
91
+ re-runs its own ``snapshot_download`` into the ModelScope cache at load time, so —
92
+ unlike the other engines — there's no ``model_path`` for the loader to consume.
93
+ aim pre-fetching the same ModelScope repo warms that cache so the load is a no-op
94
+ re-resolve (``snapshot_download`` is idempotent)."""
95
+ repo = _FIRERED_REPOS.get((self.settings.model_type or "").strip().lower())
96
+ if not repo:
97
+ return None
98
+ return build_aim_spec(repo, "ms", None, "asr/model")
99
+
71
100
  async def _ensure_model(self, s: "FireRedASRSTTSettings") -> None:
72
101
  key = (s.model_type.strip(), s.device.strip())
73
102
  if self._model is not None and self._loaded_key == key:
@@ -17,8 +17,9 @@ from dataclasses import dataclass
17
17
  from pathlib import Path
18
18
  from typing import Any
19
19
 
20
- from openspeechapi.core.base import STTProvider
20
+ from openspeechapi.core.base import AimModelSpec, STTProvider, aim_local_path_or
21
21
  from openspeechapi.core.enums import Capability, ExecMode, ProviderType
22
+ from openspeechapi.core.model_hub import build_aim_spec
22
23
  from openspeechapi.core.models import AudioData, STTOptions, Transcription
23
24
  from openspeechapi.core.settings import BaseSettings
24
25
  from openspeechapi.logging_config import logger
@@ -51,6 +52,10 @@ for _x in _MMS_LANGS:
51
52
  @dataclass
52
53
  class MMSSTTSettings(BaseSettings):
53
54
  model: str = "facebook/mms-1b-all"
55
+ # aim-resolved local path, set by the main-process aim provisioning step and
56
+ # persisted to providers.yaml. When set + present on disk, the loader uses it
57
+ # instead of `model` (keeps working when aim is absent — falls back to the repo id).
58
+ model_path: str = ""
54
59
  language: str = "eng" # ISO 639-3 (eng, cmn, yue, jpn, ...)
55
60
  device: str = "auto" # auto | cpu | cuda | mps (auto: cuda > mps > cpu)
56
61
 
@@ -118,8 +123,17 @@ class MMSSTT(STTProvider):
118
123
  pass
119
124
  return "cpu"
120
125
 
126
+ def aim_model_spec(self) -> AimModelSpec | None:
127
+ """Let aim (ai-model-manager) download + manage the model, per CLAUDE.md's aim
128
+ rule. ``build_aim_spec`` adds existing-copy-first (defers to a copy already in the
129
+ HF cache instead of having aim re-download it) and the ``hf:`` scheme, consistent
130
+ with the other STT engines. Meta MMS has no ModelScope mirror, so the hub is fixed
131
+ to ``hf``."""
132
+ return build_aim_spec(self.settings.model, "hf", None, "asr/model")
133
+
121
134
  async def _ensure_model(self, s: "MMSSTTSettings") -> None:
122
- key = (s.model.strip(), s.language.strip(), s.device.strip())
135
+ # model_path changes the resolved load target → part of the reload key.
136
+ key = (s.model.strip(), s.model_path.strip(), s.language.strip(), s.device.strip())
123
137
  if self._model is not None and self._loaded_key == key:
124
138
  return
125
139
  try:
@@ -130,12 +144,16 @@ class MMSSTT(STTProvider):
130
144
  "pip install 'openspeechapi[mms-stt]'"
131
145
  ) from exc
132
146
 
147
+ # Load from the aim-provisioned local path when set + present on disk; else the repo
148
+ # id (transformers downloads it). Keeps working when aim is absent (falls back to id).
149
+ target = aim_local_path_or(s.model_path, s.model)
150
+
133
151
  def _build(local_only: bool) -> tuple[Any, Any]:
134
152
  processor = AutoProcessor.from_pretrained(
135
- s.model, target_lang=s.language, local_files_only=local_only
153
+ target, target_lang=s.language, local_files_only=local_only
136
154
  )
137
155
  model = Wav2Vec2ForCTC.from_pretrained(
138
- s.model, target_lang=s.language, ignore_mismatched_sizes=True,
156
+ target, target_lang=s.language, ignore_mismatched_sizes=True,
139
157
  local_files_only=local_only,
140
158
  )
141
159
  return model, processor
@@ -14,8 +14,9 @@ from collections.abc import AsyncIterator
14
14
  from dataclasses import dataclass
15
15
  from typing import Any
16
16
 
17
- from openspeechapi.core.base import STTProvider
17
+ from openspeechapi.core.base import AimModelSpec, STTProvider, aim_local_path_or
18
18
  from openspeechapi.core.enums import Capability, ExecMode, ProviderType
19
+ from openspeechapi.core.model_hub import build_aim_spec
19
20
  from openspeechapi.core.models import AudioData, STTOptions, Transcription
20
21
  from openspeechapi.core.settings import BaseSettings
21
22
  from openspeechapi.logging_config import logger
@@ -25,6 +26,10 @@ from openspeechapi.providers.stt._local_audio import duration_ms, write_temp_wav
25
26
  @dataclass
26
27
  class MoonshineSTTSettings(BaseSettings):
27
28
  model: str = "UsefulSensors/moonshine-base" # base | tiny (English)
29
+ # aim-resolved local path, set by the main-process aim provisioning step and
30
+ # persisted to providers.yaml. When set + present on disk, the loader uses it
31
+ # instead of `model` (keeps working when aim is absent — falls back to the repo id).
32
+ model_path: str = ""
28
33
 
29
34
 
30
35
  class MoonshineSTT(STTProvider):
@@ -44,25 +49,35 @@ class MoonshineSTT(STTProvider):
44
49
  self.settings = settings or MoonshineSTTSettings()
45
50
  self._model: Any = None
46
51
  self._processor: Any = None
47
- self._loaded_model: str | None = None
52
+ self._loaded_key: tuple | None = None
48
53
 
49
54
  # ── lifecycle ──────────────────────────────────────────────────────────
50
55
  async def start(self) -> None:
51
56
  await self._ensure_model(self.settings.model)
52
- logger.info("{} provider started (model={})", self.name, self._loaded_model)
57
+ logger.info("{} provider started (model={})", self.name, self.settings.model)
53
58
 
54
59
  async def stop(self) -> None:
55
60
  self._model = None
56
61
  self._processor = None
57
- self._loaded_model = None
62
+ self._loaded_key = None
58
63
  logger.info("{} provider stopped", self.name)
59
64
 
60
65
  async def health_check(self) -> bool:
61
66
  return self._model is not None
62
67
 
68
+ def aim_model_spec(self) -> AimModelSpec | None:
69
+ """Let aim (ai-model-manager) download + manage the model, per CLAUDE.md's aim
70
+ rule. ``build_aim_spec`` adds existing-copy-first (defers to a copy already in the
71
+ HF cache instead of having aim re-download it) and the ``hf:`` scheme, consistent
72
+ with the other STT engines. Moonshine has no ModelScope mirror, so the hub is
73
+ fixed to ``hf``."""
74
+ return build_aim_spec(self.settings.model, "hf", None, "asr/model")
75
+
63
76
  async def _ensure_model(self, model: str) -> None:
64
77
  model = (model or self.settings.model).strip()
65
- if self._model is not None and self._loaded_model == model:
78
+ # model_path changes the resolved load target → part of the reload key.
79
+ key = (model, self.settings.model_path.strip())
80
+ if self._model is not None and self._loaded_key == key:
66
81
  return
67
82
  try:
68
83
  from transformers import AutoProcessor, MoonshineForConditionalGeneration
@@ -72,13 +87,17 @@ class MoonshineSTT(STTProvider):
72
87
  "pip install 'openspeechapi[moonshine-stt]'"
73
88
  ) from exc
74
89
 
90
+ # Load from the aim-provisioned local path when set + present on disk; else the repo
91
+ # id (transformers downloads it). Keeps working when aim is absent (falls back to id).
92
+ target = aim_local_path_or(self.settings.model_path, model)
93
+
75
94
  def _load() -> tuple[Any, Any]:
76
- processor = AutoProcessor.from_pretrained(model)
77
- m = MoonshineForConditionalGeneration.from_pretrained(model)
95
+ processor = AutoProcessor.from_pretrained(target)
96
+ m = MoonshineForConditionalGeneration.from_pretrained(target)
78
97
  return m, processor
79
98
 
80
99
  self._model, self._processor = await asyncio.to_thread(_load)
81
- self._loaded_model = model
100
+ self._loaded_key = key
82
101
 
83
102
  # ── transcription ──────────────────────────────────────────────────────
84
103
  async def transcribe(
@@ -15,8 +15,9 @@ from collections.abc import AsyncIterator
15
15
  from dataclasses import dataclass
16
16
  from typing import Any
17
17
 
18
- from openspeechapi.core.base import STTProvider
18
+ from openspeechapi.core.base import AimModelSpec, STTProvider, aim_local_path_or
19
19
  from openspeechapi.core.enums import Capability, ExecMode, ProviderType
20
+ from openspeechapi.core.model_hub import build_aim_spec
20
21
  from openspeechapi.core.models import AudioData, STTOptions, Transcription
21
22
  from openspeechapi.core.settings import BaseSettings
22
23
  from openspeechapi.logging_config import logger
@@ -26,6 +27,10 @@ from openspeechapi.providers.stt._local_audio import duration_ms, write_temp_wav
26
27
  @dataclass
27
28
  class Phi4MultimodalSTTSettings(BaseSettings):
28
29
  model: str = "microsoft/Phi-4-multimodal-instruct"
30
+ # aim-resolved local path, set by the main-process aim provisioning step and
31
+ # persisted to providers.yaml. When set + present on disk, the loader uses it
32
+ # instead of `model` (keeps working when aim is absent — falls back to the repo id).
33
+ model_path: str = ""
29
34
  device: str = "auto" # auto | cpu | cuda | mps (auto: cuda > mps > cpu)
30
35
  dtype: str = "auto" # auto | bfloat16 | float16
31
36
  prompt: str = "Transcribe the audio clip into text."
@@ -88,8 +93,17 @@ class Phi4MultimodalSTT(STTProvider):
88
93
  pass
89
94
  return "cpu"
90
95
 
96
+ def aim_model_spec(self) -> AimModelSpec | None:
97
+ """Let aim (ai-model-manager) download + manage the model, per CLAUDE.md's aim
98
+ rule. ``build_aim_spec`` adds existing-copy-first (defers to a copy already in the
99
+ HF cache instead of having aim re-download it) and the ``hf:`` scheme, consistent
100
+ with the other STT engines. Phi-4-multimodal has no ModelScope mirror, so the hub
101
+ is fixed to ``hf``."""
102
+ return build_aim_spec(self.settings.model, "hf", None, "asr/model")
103
+
91
104
  async def _ensure_model(self, s: "Phi4MultimodalSTTSettings") -> None:
92
- key = (s.model.strip(), s.device.strip(), s.dtype.strip())
105
+ # model_path changes the resolved load target → part of the reload key.
106
+ key = (s.model.strip(), s.model_path.strip(), s.device.strip(), s.dtype.strip())
93
107
  if self._model is not None and self._loaded_key == key:
94
108
  return
95
109
  try:
@@ -100,18 +114,22 @@ class Phi4MultimodalSTT(STTProvider):
100
114
  "pip install 'openspeechapi[phi4-multimodal-stt]'"
101
115
  ) from exc
102
116
 
117
+ # Load from the aim-provisioned local path when set + present on disk; else the repo
118
+ # id (transformers downloads it). Keeps working when aim is absent (falls back to id).
119
+ target = aim_local_path_or(s.model_path, s.model)
120
+
103
121
  def _load() -> tuple[Any, Any, Any]:
104
122
  dev = self._resolve_device(s.device)
105
123
  # Phi-4 defaults to flash_attention_2 (CUDA-only). MPS/CPU must use eager;
106
124
  # use sdpa on CUDA so no flash-attn package is required.
107
125
  attn = "eager" if dev in ("mps", "cpu") else "sdpa"
108
- processor = AutoProcessor.from_pretrained(s.model, trust_remote_code=True)
126
+ processor = AutoProcessor.from_pretrained(target, trust_remote_code=True)
109
127
 
110
128
  def _from(d: str, impl: str) -> Any:
111
129
  # Phi-4 pins transformers==4.48.2 (its isolated venv), where the kwarg
112
130
  # is `torch_dtype` (the `dtype` alias only exists in newer transformers).
113
131
  m = AutoModelForCausalLM.from_pretrained(
114
- s.model, trust_remote_code=True, torch_dtype=s.dtype,
132
+ target, trust_remote_code=True, torch_dtype=s.dtype,
115
133
  _attn_implementation=impl,
116
134
  )
117
135
  return m.to(d)
@@ -16,8 +16,9 @@ from collections.abc import AsyncIterator
16
16
  from dataclasses import dataclass
17
17
  from typing import Any
18
18
 
19
- from openspeechapi.core.base import STTProvider
19
+ from openspeechapi.core.base import AimModelSpec, STTProvider, aim_local_path_or
20
20
  from openspeechapi.core.enums import Capability, ExecMode, ProviderType
21
+ from openspeechapi.core.model_hub import build_aim_spec
21
22
  from openspeechapi.core.models import AudioData, STTOptions, Transcription
22
23
  from openspeechapi.core.settings import BaseSettings
23
24
  from openspeechapi.logging_config import logger
@@ -27,6 +28,13 @@ from openspeechapi.providers.stt._local_audio import duration_ms, write_temp_wav
27
28
  @dataclass
28
29
  class Qwen3OmniSTTSettings(BaseSettings):
29
30
  model: str = "Qwen/Qwen3-Omni-30B-A3B-Instruct"
31
+ # aim-resolved local path, set by the main-process aim provisioning step and
32
+ # persisted to providers.yaml. When set + present on disk, the loader uses it
33
+ # instead of `model` (keeps working when aim is absent — falls back to the repo id).
34
+ model_path: str = ""
35
+ # Download source for aim: "auto" follows OSA_DEFAULT_MODEL_SOURCE (ModelScope on
36
+ # the DGX box); force with "hf" | "ms". The repo id is identical on both hubs.
37
+ hub: str = "auto"
30
38
  dtype: str = "auto" # auto | bfloat16 | float16
31
39
  device_map: str = "auto" # auto | cuda | cpu
32
40
  attn_implementation: str = "sdpa" # sdpa | flash_attention_2 | eager
@@ -47,6 +55,7 @@ class Qwen3OmniSTT(STTProvider):
47
55
  supports_param_overrides = True
48
56
  field_options = {
49
57
  "model": ["Qwen/Qwen3-Omni-30B-A3B-Instruct"],
58
+ "hub": ["auto", "hf", "ms"],
50
59
  "dtype": ["auto", "bfloat16", "float16"],
51
60
  "device_map": ["auto", "cuda", "cpu"],
52
61
  "attn_implementation": ["sdpa", "flash_attention_2", "eager"],
@@ -72,8 +81,39 @@ class Qwen3OmniSTT(STTProvider):
72
81
  async def health_check(self) -> bool:
73
82
  return self._model is not None
74
83
 
84
+ @staticmethod
85
+ def _resolve_device_map(device_map: str) -> str:
86
+ """Resolve the configured device_map to a concrete placement.
87
+
88
+ device_map="auto" mis-reads unified-memory GPUs (DGX/GB10, Jetson) whose free
89
+ VRAM reports as N/A → accelerate concludes nothing "fits" and offloads the whole
90
+ 30B model to CPU (~20x slower). Pin the GPU when CUDA is present (mirrors gemma4's
91
+ _load_cuda fix); fall back to CPU only when there's no CUDA at all. Explicit
92
+ "cuda"/"cpu" are user overrides and pass through untouched (no torch probe).
93
+
94
+ NOTE: pinning "cuda" places the whole model on a single device — correct for the
95
+ unified-memory targets this engine is gated to (GB10 128GB / Jetson). True
96
+ multi-GPU sharding of the 30B MoE would need a separate explicit option (e.g.
97
+ "balanced"), not "auto".
98
+ """
99
+ dm = (device_map or "auto").strip().lower()
100
+ if dm != "auto":
101
+ return dm
102
+ import torch
103
+ return "cuda" if torch.cuda.is_available() else "cpu"
104
+
105
+ def aim_model_spec(self) -> AimModelSpec | None:
106
+ """Let aim (ai-model-manager) download + manage the 30B weights, per CLAUDE.md's
107
+ aim rule. ``build_aim_spec`` adds existing-copy-first (defers to a copy already in
108
+ cache instead of re-downloading) and the ``hf:``/``ms:`` scheme by ``effective_source``
109
+ (hub 'auto' → ModelScope on the DGX box). The repo id is identical on HF and
110
+ ModelScope, so no ms_repo_map is needed."""
111
+ return build_aim_spec(self.settings.model, self.settings.hub, None, "asr/model")
112
+
75
113
  async def _ensure_model(self, s: "Qwen3OmniSTTSettings") -> None:
76
- key = (s.model.strip(), s.dtype.strip(), s.device_map.strip(), s.attn_implementation.strip())
114
+ # model_path/hub change the resolved load target → part of the reload key.
115
+ key = (s.model.strip(), s.model_path.strip(), s.hub.strip(),
116
+ s.dtype.strip(), s.device_map.strip(), s.attn_implementation.strip())
77
117
  if self._model is not None and self._loaded_key == key:
78
118
  return
79
119
  try:
@@ -87,12 +127,22 @@ class Qwen3OmniSTT(STTProvider):
87
127
  "pip install 'openspeechapi[qwen3-omni-stt]'"
88
128
  ) from exc
89
129
 
130
+ # Resolve device placement on THIS (event-loop) thread, before the heavy load is
131
+ # offloaded to a worker. Probing CUDA imports torch, and the FIRST torch import in
132
+ # an asyncio worker thread segfaults on macOS; resolving here also avoids relying on
133
+ # transformers having already pre-imported torch. _load() then loads with a concrete
134
+ # device only.
135
+ device_map = self._resolve_device_map(s.device_map)
136
+ # Load from the aim-provisioned local path when set + present on disk; else the repo
137
+ # id (transformers downloads it). Keeps working when aim is absent (falls back to id).
138
+ target = aim_local_path_or(s.model_path, s.model)
139
+
90
140
  def _load() -> tuple[Any, Any]:
91
141
  model = Qwen3OmniMoeForConditionalGeneration.from_pretrained(
92
- s.model, dtype=s.dtype, device_map=s.device_map,
142
+ target, dtype=s.dtype, device_map=device_map,
93
143
  attn_implementation=s.attn_implementation,
94
144
  )
95
- processor = Qwen3OmniMoeProcessor.from_pretrained(s.model)
145
+ processor = Qwen3OmniMoeProcessor.from_pretrained(target)
96
146
  return model, processor
97
147
 
98
148
  self._model, self._processor = await asyncio.to_thread(_load)