openspeechapi 0.4.0__tar.gz → 0.4.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (178) hide show
  1. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/PKG-INFO +7 -1
  2. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/cli.py +63 -3
  3. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/core/base.py +83 -49
  4. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/core/model_hub.py +179 -21
  5. openspeechapi-0.4.1/openspeechapi/core/model_presence.py +56 -0
  6. openspeechapi-0.4.1/openspeechapi/core/model_profile.py +131 -0
  7. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/dispatch/dispatcher.py +35 -1
  8. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/dispatch/executors/subprocess_exec.py +18 -18
  9. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/engine_registry.yaml +3 -1
  10. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/local_engines/aim_resolver.py +145 -8
  11. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/local_engines/backends/native_backend.py +16 -17
  12. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/local_engines/cosyvoice_venv.py +4 -18
  13. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/local_engines/engines/sherpa_onnx.py +14 -9
  14. openspeechapi-0.4.1/openspeechapi/local_engines/engines/whisperlivekit.py +54 -0
  15. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/local_engines/fish_venv.py +3 -12
  16. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/local_engines/indextts_venv.py +3 -12
  17. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/local_engines/spark_venv.py +3 -12
  18. openspeechapi-0.4.1/openspeechapi/local_engines/venv_common.py +29 -0
  19. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/providers/stt/canary_qwen_stt.py +6 -9
  20. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/providers/stt/dolphin_stt.py +85 -18
  21. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/providers/stt/faster_whisper.py +8 -11
  22. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/providers/stt/fireredasr_stt.py +9 -16
  23. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/providers/stt/funasr_stt.py +19 -12
  24. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/providers/stt/gemma4.py +22 -2
  25. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/providers/stt/kimi_audio_stt.py +7 -6
  26. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/providers/stt/mlx_whisper_stt.py +10 -7
  27. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/providers/stt/mms_stt.py +6 -9
  28. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/providers/stt/moonshine_stt.py +6 -9
  29. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/providers/stt/paraformer.py +4 -3
  30. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/providers/stt/parakeet_mlx_stt.py +10 -7
  31. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/providers/stt/phi4_multimodal_stt.py +6 -9
  32. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/providers/stt/qwen3_asr.py +8 -8
  33. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/providers/stt/qwen3_omni_stt.py +8 -8
  34. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/providers/stt/sensevoice.py +11 -8
  35. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/providers/stt/sherpa_onnx.py +166 -9
  36. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/providers/stt/vosk_stt.py +28 -0
  37. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/providers/stt/voxtral_stt.py +65 -14
  38. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/providers/stt/wenet_stt.py +60 -26
  39. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/providers/tts/coqui.py +35 -5
  40. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/providers/tts/fish_speech.py +7 -7
  41. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/providers/tts/indextts.py +10 -11
  42. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/providers/tts/kokoro.py +7 -5
  43. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/providers/tts/spark.py +9 -12
  44. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/server/app.py +37 -8
  45. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/server/model_downloads.py +79 -80
  46. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/server/routes/management.py +243 -115
  47. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/server/routes/stt.py +45 -27
  48. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/server/routes/webui.py +17 -3
  49. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/server/system_metrics.py +98 -3
  50. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/server/webui/app.js +221 -49
  51. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/server/webui/index.html +5 -1
  52. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/server/webui/styles.css +19 -3
  53. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/server/ws/tts_stream.py +33 -0
  54. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/utils/audio_converter.py +39 -10
  55. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/pyproject.toml +21 -4
  56. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/scripts/engines/fish-speech/native/install.sh +17 -2
  57. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/scripts/engines/sherpa-onnx/native/install.sh +24 -2
  58. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/scripts/engines/sherpa-onnx/native/run_streaming_server.py +33 -15
  59. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/scripts/engines/whisperlivekit/native/install.sh +22 -2
  60. openspeechapi-0.4.0/openspeechapi/local_engines/engines/whisperlivekit.py +0 -60
  61. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/.gitignore +0 -0
  62. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/README.md +0 -0
  63. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/__init__.py +0 -0
  64. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/__main__.py +0 -0
  65. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/client/__init__.py +0 -0
  66. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/client/client.py +0 -0
  67. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/config.py +0 -0
  68. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/core/__init__.py +0 -0
  69. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/core/enums.py +0 -0
  70. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/core/models.py +0 -0
  71. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/core/registry.py +0 -0
  72. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/core/settings.py +0 -0
  73. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/core/voice_presets.py +0 -0
  74. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/demo.py +0 -0
  75. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/dispatch/__init__.py +0 -0
  76. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/dispatch/aim_provision.py +0 -0
  77. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/dispatch/context.py +0 -0
  78. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/dispatch/executors/__init__.py +0 -0
  79. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/dispatch/executors/base.py +0 -0
  80. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/dispatch/executors/in_process.py +0 -0
  81. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/dispatch/executors/remote.py +0 -0
  82. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/dispatch/fanout.py +0 -0
  83. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/dispatch/filters.py +0 -0
  84. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/dispatch/lifecycle.py +0 -0
  85. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/dispatch/watcher.py +0 -0
  86. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/engine_catalog.py +0 -0
  87. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/exceptions.py +0 -0
  88. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/factory.py +0 -0
  89. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/local_engines/__init__.py +0 -0
  90. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/local_engines/backends/__init__.py +0 -0
  91. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/local_engines/backends/docker_backend.py +0 -0
  92. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/local_engines/base.py +0 -0
  93. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/local_engines/engines/__init__.py +0 -0
  94. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/local_engines/engines/faster_whisper.py +0 -0
  95. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/local_engines/engines/fish_speech.py +0 -0
  96. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/local_engines/engines/whisper.py +0 -0
  97. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/local_engines/isolated_venv.py +0 -0
  98. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/local_engines/manager.py +0 -0
  99. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/local_engines/models.py +0 -0
  100. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/local_engines/progress.py +0 -0
  101. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/local_engines/registry.py +0 -0
  102. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/local_engines/task_store.py +0 -0
  103. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/local_engines/tasks.py +0 -0
  104. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/local_engines/vllm_gb10_patch.py +0 -0
  105. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/local_engines/vllm_venv.py +0 -0
  106. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/logging_config.py +0 -0
  107. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/observe/__init__.py +0 -0
  108. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/observe/base.py +0 -0
  109. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/observe/debug.py +0 -0
  110. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/observe/latency.py +0 -0
  111. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/observe/metrics.py +0 -0
  112. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/observe/tracing.py +0 -0
  113. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/observe/usage.py +0 -0
  114. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/providers/__init__.py +0 -0
  115. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/providers/_template.py +0 -0
  116. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/providers/stt/__init__.py +0 -0
  117. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/providers/stt/_local_audio.py +0 -0
  118. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/providers/stt/alibaba.py +0 -0
  119. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/providers/stt/assemblyai.py +0 -0
  120. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/providers/stt/azure_speech.py +0 -0
  121. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/providers/stt/baidu.py +0 -0
  122. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/providers/stt/deepgram.py +0 -0
  123. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/providers/stt/elevenlabs.py +0 -0
  124. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/providers/stt/google_cloud.py +0 -0
  125. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/providers/stt/iflytek.py +0 -0
  126. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/providers/stt/macos_speech.py +0 -0
  127. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/providers/stt/mms_languages.json +0 -0
  128. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/providers/stt/openai.py +0 -0
  129. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/providers/stt/tencent.py +0 -0
  130. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/providers/stt/volcengine.py +0 -0
  131. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/providers/stt/whisper.py +0 -0
  132. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/providers/stt/whisperlivekit.py +0 -0
  133. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/providers/stt/windows_speech.py +0 -0
  134. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/providers/tts/__init__.py +0 -0
  135. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/providers/tts/alibaba.py +0 -0
  136. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/providers/tts/azure_speech.py +0 -0
  137. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/providers/tts/baidu.py +0 -0
  138. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/providers/tts/cosyvoice.py +0 -0
  139. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/providers/tts/deepgram.py +0 -0
  140. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/providers/tts/elevenlabs.py +0 -0
  141. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/providers/tts/f5_tts.py +0 -0
  142. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/providers/tts/google_cloud.py +0 -0
  143. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/providers/tts/iflytek.py +0 -0
  144. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/providers/tts/macos_say.py +0 -0
  145. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/providers/tts/minimax.py +0 -0
  146. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/providers/tts/openai.py +0 -0
  147. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/providers/tts/piper.py +0 -0
  148. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/providers/tts/tencent.py +0 -0
  149. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/providers/tts/volcengine.py +0 -0
  150. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/providers/tts/windows_sapi.py +0 -0
  151. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/server/__init__.py +0 -0
  152. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/server/auth.py +0 -0
  153. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/server/extras_installer.py +0 -0
  154. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/server/middleware.py +0 -0
  155. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/server/native_installer.py +0 -0
  156. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/server/routes/__init__.py +0 -0
  157. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/server/routes/chat.py +0 -0
  158. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/server/routes/tts.py +0 -0
  159. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/server/ws/__init__.py +0 -0
  160. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/server/ws/stt_stream.py +0 -0
  161. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/telemetry/__init__.py +0 -0
  162. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/telemetry/perf.py +0 -0
  163. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/utils/__init__.py +0 -0
  164. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/utils/audio_playback.py +0 -0
  165. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/openspeechapi/vendor_registry.yaml +0 -0
  166. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/providers.example.yaml +0 -0
  167. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/scripts/aim_adopt.py +0 -0
  168. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/scripts/aim_consumers.py +0 -0
  169. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/scripts/engines/cloud/install.sh +0 -0
  170. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/scripts/engines/faster-whisper/native/install.sh +0 -0
  171. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/scripts/engines/macos-stt/_bundle.sh +0 -0
  172. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/scripts/engines/macos-stt/install.sh +0 -0
  173. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/scripts/engines/macos-stt/macos_stt.swift +0 -0
  174. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/scripts/engines/macos-stt/request_auth.swift +0 -0
  175. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/scripts/engines/whisper/native/install.sh +0 -0
  176. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/scripts/gen_mms_languages.py +0 -0
  177. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/scripts/preload_stt_model.py +0 -0
  178. {openspeechapi-0.4.0 → openspeechapi-0.4.1}/scripts/release.sh +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: openspeechapi
3
- Version: 0.4.0
3
+ Version: 0.4.1
4
4
  Summary: Unified speech interface for STT/TTS providers
5
5
  Requires-Python: >=3.11
6
6
  Requires-Dist: httpx>=0.27
@@ -8,10 +8,13 @@ Requires-Dist: loguru>=0.7
8
8
  Requires-Dist: msgpack>=1.0
9
9
  Requires-Dist: pydantic>=2.0
10
10
  Requires-Dist: pyyaml>=6.0
11
+ Provides-Extra: aim
12
+ Requires-Dist: ai-model-manager>=0.2.1; extra == 'aim'
11
13
  Provides-Extra: alibaba
12
14
  Provides-Extra: alibaba-stt
13
15
  Provides-Extra: alibaba-tts
14
16
  Provides-Extra: all
17
+ Requires-Dist: ai-model-manager>=0.2.1; extra == 'all'
15
18
  Requires-Dist: elevenlabs; extra == 'all'
16
19
  Requires-Dist: faster-whisper; extra == 'all'
17
20
  Requires-Dist: openai; extra == 'all'
@@ -79,6 +82,7 @@ Requires-Dist: pillow; (sys_platform != 'darwin') and extra == 'gemma4-stt'
79
82
  Requires-Dist: torch; (sys_platform != 'darwin') and extra == 'gemma4-stt'
80
83
  Requires-Dist: torchvision; (sys_platform != 'darwin') and extra == 'gemma4-stt'
81
84
  Requires-Dist: transformers; (sys_platform != 'darwin') and extra == 'gemma4-stt'
85
+ Requires-Dist: transformers<5.13,>=5.5; (sys_platform == 'darwin') and extra == 'gemma4-stt'
82
86
  Provides-Extra: google
83
87
  Provides-Extra: google-stt
84
88
  Provides-Extra: google-tts
@@ -143,6 +147,7 @@ Requires-Dist: funasr>=1.1.0; extra == 'sensevoice-stt'
143
147
  Requires-Dist: torch; extra == 'sensevoice-stt'
144
148
  Requires-Dist: torchaudio; extra == 'sensevoice-stt'
145
149
  Provides-Extra: server
150
+ Requires-Dist: ai-model-manager>=0.2.1; extra == 'server'
146
151
  Requires-Dist: fastapi; extra == 'server'
147
152
  Requires-Dist: python-multipart; extra == 'server'
148
153
  Requires-Dist: uvicorn; extra == 'server'
@@ -164,6 +169,7 @@ Requires-Dist: vosk; extra == 'vosk-stt'
164
169
  Provides-Extra: voxtral-stt
165
170
  Requires-Dist: accelerate; extra == 'voxtral-stt'
166
171
  Requires-Dist: mistral-common[audio]>=1.8.1; extra == 'voxtral-stt'
172
+ Requires-Dist: sentencepiece; extra == 'voxtral-stt'
167
173
  Requires-Dist: torch; extra == 'voxtral-stt'
168
174
  Requires-Dist: transformers>=4.54.0; extra == 'voxtral-stt'
169
175
  Provides-Extra: wenet-stt
@@ -70,12 +70,18 @@ def _server_base_url(args: argparse.Namespace) -> str:
70
70
  return f"http://127.0.0.1:{port}"
71
71
 
72
72
 
73
- def _http_json(method: str, url: str, timeout: float = 15.0) -> dict:
74
- """Minimal stdlib HTTP JSON call — keeps the client CLI path dependency-free."""
73
+ def _http_json(method: str, url: str, timeout: float = 15.0, body: dict | None = None) -> dict:
74
+ """Minimal stdlib HTTP JSON call — keeps the client CLI path dependency-free.
75
+ ``body`` (optional dict) is JSON-encoded for POST/PUT."""
75
76
  import json
76
77
  import urllib.error
77
78
  import urllib.request
78
- req = urllib.request.Request(url, method=method)
79
+ data = None
80
+ headers = {}
81
+ if body is not None:
82
+ data = json.dumps(body).encode("utf-8")
83
+ headers["Content-Type"] = "application/json"
84
+ req = urllib.request.Request(url, method=method, data=data, headers=headers)
79
85
  try:
80
86
  with urllib.request.urlopen(req, timeout=timeout) as resp:
81
87
  body = resp.read().decode("utf-8")
@@ -341,6 +347,43 @@ def _load_dotenv() -> None:
341
347
  pass
342
348
 
343
349
 
350
+ def _cmd_aim(args: argparse.Namespace) -> None:
351
+ """aim (ai-model-manager) integration: status + user-initiated adopt(回纳管). Talks to a
352
+ running server over HTTP (the adopt scan needs the server's engine list)."""
353
+ base = _server_base_url(args)
354
+ try:
355
+ if args.aim_cmd == "status":
356
+ cfg = _http_json("GET", f"{base}/v1/admin/server-config")
357
+ adoptable = _http_json("GET", f"{base}/v1/models/aim/adoptable").get("adoptable", [])
358
+ print(f"aim available : {cfg.get('aim_available')}")
359
+ print(f"aim version : {cfg.get('aim_version')}")
360
+ print(f"store root : {cfg.get('aim_store_root')}")
361
+ print(f"adoptable : {len(adoptable)}")
362
+ for a in adoptable:
363
+ print(f" - {a['engine']}: {a['repo']}")
364
+ return
365
+ # adopt
366
+ adoptable = _http_json("GET", f"{base}/v1/models/aim/adoptable").get("adoptable", [])
367
+ if args.dry_run:
368
+ print("would adopt:" if adoptable else "nothing to adopt")
369
+ for a in adoptable:
370
+ print(f" - {a['engine']}: {a['repo']}")
371
+ return
372
+ if not args.all and not args.repo:
373
+ print("specify --all or --repo <id> (use --dry-run to preview)", file=sys.stderr)
374
+ sys.exit(2)
375
+ body = {"all": True} if args.all else {"repos": args.repo}
376
+ res = _http_json("POST", f"{base}/v1/models/aim/adopt", body=body)
377
+ adopting = res.get("adopting", [])
378
+ for t in adopting:
379
+ print(f"adopting {t['repo']} (task {t['task_id']})")
380
+ if not adopting:
381
+ print("nothing adopted")
382
+ except RuntimeError as e:
383
+ print(str(e), file=sys.stderr)
384
+ sys.exit(1)
385
+
386
+
344
387
  def _add_logging_args(parser: argparse.ArgumentParser) -> None:
345
388
  """Register common logging flags on ``parser``.
346
389
 
@@ -514,6 +557,22 @@ def main(argv: list[str] | None = None) -> None:
514
557
  task_cancel_p = task_sub.add_parser("cancel", help="Request cancellation for a task")
515
558
  task_cancel_p.add_argument("--task-id", required=True, help="Task ID")
516
559
 
560
+ # aim (ai-model-manager) integration: status + user-initiated adopt (re-ingest cached models)
561
+ aim_p = sub.add_parser("aim", help="Manage aim (ai-model-manager) integration")
562
+ aim_sub = aim_p.add_subparsers(dest="aim_cmd", required=True)
563
+ # --url/--config live on a shared parent so they follow the subcommand (natural
564
+ # `aim status --url X`), not `aim --url X status`.
565
+ _aim_conn = argparse.ArgumentParser(add_help=False)
566
+ _aim_conn.add_argument("--url", default=None, help="Server base URL (default http://127.0.0.1:<port>)")
567
+ _aim_conn.add_argument("--config", default=None, help="Config path (to resolve default port)")
568
+ aim_sub.add_parser("status", parents=[_aim_conn],
569
+ help="aim detection + store root + adoptable count")
570
+ adopt_p = aim_sub.add_parser("adopt", parents=[_aim_conn],
571
+ help="Re-ingest already-downloaded models into aim")
572
+ adopt_p.add_argument("--all", action="store_true", help="Adopt all adoptable models")
573
+ adopt_p.add_argument("--repo", action="append", default=[], help="Specific repo id (repeatable)")
574
+ adopt_p.add_argument("--dry-run", action="store_true", help="Preview only (no changes)")
575
+
517
576
  args = parser.parse_args(argv)
518
577
  _apply_logging_args(args)
519
578
  if args.command is None:
@@ -527,6 +586,7 @@ def main(argv: list[str] | None = None) -> None:
527
586
  "load": _cmd_load,
528
587
  "unload": _cmd_unload,
529
588
  "engine": _cmd_engine,
589
+ "aim": _cmd_aim,
530
590
  }
531
591
  commands[args.command](args)
532
592
 
@@ -14,6 +14,11 @@ from openspeechapi.core.enums import AudioFormat, Capability, ExecMode, Provider
14
14
  from openspeechapi.core.models import AudioChunk, AudioData, STTOptions, TTSOptions, Transcription
15
15
  from openspeechapi.core.settings import BaseSettings
16
16
 
17
+ # Sentinel for _resolve_model(aim_spec=…): distinguishes "caller passed no spec →
18
+ # use self.aim_model_spec()" from "caller explicitly passed None → no aim". None is a
19
+ # valid aim_spec value (no aim), so a distinct sentinel is required.
20
+ _USE_SELF_AIM_SPEC = object()
21
+
17
22
 
18
23
  @dataclass
19
24
  class AimModelSpec:
@@ -94,49 +99,66 @@ class SpeechProvider(ABC):
94
99
  # (long, model-load-appropriate) start timeout. None (default) = no pre-check.
95
100
  required_import: str | None = None
96
101
 
97
- def aim_model_spec(self) -> "AimModelSpec | None":
98
- """Override to let ``aim`` (ai-model-manager) download + manage this model.
99
-
100
- Return an :class:`AimModelSpec` to opt in: the main-process provisioning
101
- step ``aim download``s the model, ``aim resolve``s its local path, and sets
102
- ``self.settings.model_path`` (persisted to providers.yaml). Return ``None``
103
- (default) to stay on the provider's own direct download. Providers that opt
104
- in must prefer ``settings.model_path`` (when set and present on disk) in
105
- their model-loading code, falling back to the repo id otherwise.
106
- """
102
+ @classmethod
103
+ def model_profile(cls, settings): # noqa: ANN001
104
+ """声明式模型契约(server 进程内、纯字符串、绝不 import torch/mlx)。返回
105
+ :class:`~openspeechapi.core.model_profile.ModelProfile` 让框架派生所有静态钩子
106
+ (aim_model_spec / expected_local_repo / local_model_present / download_spec /
107
+ pending_aux_models);``None``(默认)= 未迁移 / 无本地下载,各钩子退回旧默认。
108
+ 见 docs/superpowers/specs/2026-07-05-unified-model-management-design.md。"""
107
109
  return None
108
110
 
109
- @staticmethod
110
- def local_model_present(settings) -> bool | None: # noqa: ANN001
111
- """该 config 的模型权重是否已在本机(用于「是否已下载」预检的**非标准**判定)。
111
+ def aim_model_spec(self) -> "AimModelSpec | None":
112
+ """让 ``aim`` (ai-model-manager) 下载 + 管理本模型。默认从 :meth:`model_profile`
113
+ 派生(主源可 aim → AimModelSpec;部分下载 → None);provider 若直接 override 本方法则
114
+ 其 override 优先(Python MRO)。未迁移(model_profile=None)→ None,provider 自行 override
115
+ 提供。opt-in 的 provider 加载时须优先用 ``settings.model_path``(已解析且在盘上时),否则
116
+ 回退 repo id。"""
117
+ return self._aim_spec_for(self.settings)
118
+
119
+ def _aim_spec_for(self, settings) -> "AimModelSpec | None": # noqa: ANN001
120
+ """从 **任意** settings 派生 aim spec(不限于静态 ``self.settings``)。
121
+
122
+ ``aim_model_spec()`` = ``self._aim_spec_for(self.settings)`` 的静态特例。**按请求换
123
+ model 的引擎**(如 dolphin 的 small/base per-request 覆盖)在加载路径拿到有效配置 ``s``
124
+ 后,须用 ``self._aim_spec_for(s)`` 取**该请求模型**的 spec —— 否则 ``_resolve_model``
125
+ 默认用静态 config 的 spec,会把请求模型的目录错链到 config 模型的 store(踩过:base 被
126
+ 链到 small store,base.pt 找不到 → 无结果)。"""
127
+ from openspeechapi.core.model_profile import derive_aim_spec
128
+ profile = type(self).model_profile(settings)
129
+ if profile is None:
130
+ return None
131
+ hub = getattr(settings, "hub", "") or ""
132
+ return derive_aim_spec(profile, hub)
133
+
134
+ @classmethod
135
+ def local_model_present(cls, settings) -> bool | None: # noqa: ANN001
136
+ """该 config 的模型权重是否已在本机(「是否已下载」预检的**非标准**判定,如 piper)。
112
137
 
113
- 默认返回 ``None`` —— 表示「按标准 repo/aim 流程判断」(交回 ``expected_local_repo`` +
114
- ``model_is_cached`` / aim store 检测)。**仅当**引擎走非标准的部分下载(典型:piper 从
115
- 10.9GB 单仓只取某 voice 的 2 个文件,``expected_local_repo`` 给不出可整仓校验的 id)
116
- 才 override,直接报告**本 config** 的权重是否齐备。
138
+ 默认从 :meth:`model_profile` 的部分下载源派生(有 ``allow_patterns`` → 校验那几个文件在否);
139
+ 未迁移 / 无部分源 → ``None``(交标准 ``expected_local_repo`` + ``model_is_cached`` / aim 判断)。
140
+ provider 若直接 override 本方法则其 override 优先(MRO)。
117
141
 
118
142
  与 ``expected_local_repo`` 同纪律:在 **server 进程** 调用 → 纯字符串/文件存在性逻辑,
119
143
  绝不 import torch/transformers/mlx、绝不加载模型、绝不触发下载。``settings`` 可能是
120
- dataclass 实例或 dict。任何不确定 → 返回 ``None``(放行,交标准流程)。返回 ``True``/
121
- ``False`` 时,预检以此为准、不再走 repo/aim 判断。"""
122
- return None
144
+ dataclass 实例或 dict。"""
145
+ from openspeechapi.core.model_profile import derive_partial_present
146
+ return derive_partial_present(cls.model_profile(settings))
123
147
 
124
- @staticmethod
125
- def download_spec(settings) -> dict | None: # noqa: ANN001
126
- """该引擎「下载模型」按钮触发的**部分 snapshot 下载**描述,默认 ``None``。
127
-
128
- 走 aim 纳管的引擎用 ``aim_model_spec()``;无法 aim 纳管、又需从一个大仓只取若干文件
129
- 的引擎(典型:piper —— aim 无「部分仓/多文件」下载能力,``AimModelSpec`` 是单源)
130
- override 本方法,返回::
148
+ @classmethod
149
+ def download_spec(cls, settings) -> dict | None: # noqa: ANN001
150
+ """该引擎「下载模型」按钮触发的**部分 snapshot 下载**描述,默认从 :meth:`model_profile`
151
+ 的非 aim-able 主源派生(piper 式部分下载),形如::
131
152
 
132
153
  {"repo": "<hf repo>", "allow_patterns": ["<glob>", ...], "label": "<str>"}
133
154
 
134
- ``repo`` 为 HF 仓库 id;``allow_patterns`` 为只下这几个文件的 glob;``label`` 用于区分
135
- 同仓不同目标(如不同 voice)的下载任务。被「下载模型」按钮 + 进度面板使用。
155
+ 走 aim 纳管的引擎(整仓 hf/ms 或单文件 url)→ ``None``(交 ``aim_model_spec()``)。未迁移 /
156
+ 无部分源 → ``None``。provider 若直接 override 本方法则其 override 优先(MRO)。
136
157
 
137
158
  同 ``expected_local_repo`` 纪律:server 进程内调用,纯字符串逻辑、不加载模型、不下载。
138
- ``settings`` 可能是 dataclass 实例或 dict。无可下载目标 → ``None``。"""
139
- return None
159
+ ``settings`` 可能是 dataclass 实例或 dict。"""
160
+ from openspeechapi.core.model_profile import derive_download_spec
161
+ return derive_download_spec(cls.model_profile(settings))
140
162
 
141
163
  @staticmethod
142
164
  def pending_reference_asr(settings, opts) -> dict | None: # noqa: ANN001
@@ -151,30 +173,37 @@ class SpeechProvider(ABC):
151
173
  ``settings`` 可能是 dataclass 或 dict;``opts`` 为本次请求的 ``TTSOptions``。"""
152
174
  return None
153
175
 
154
- @staticmethod
155
- def pending_aux_models(settings, opts) -> "list[dict] | None": # noqa: ANN001
156
- """该引擎首次加载时要下的**辅助模型**里,尚未缓存的那些(默认 ``None``)。
176
+ @classmethod
177
+ def pending_aux_models(cls, settings, opts) -> "list[dict] | None": # noqa: ANN001, ARG003
178
+ """该引擎首次加载时要下的**辅助模型**里,尚未缓存的那些(默认从 :meth:`model_profile` 的
179
+ ``aux`` 派生:检查各 aux 源缓存缺失项)。
157
180
 
158
181
  某些 SDK(如 IndexTTS2)在加载主模型时,会在 worker 里静默现下若干 GB 的辅助模型
159
- (w2v-bert / codec / vocoder 等)——违反「前后台状态同步」+「绝不 worker 静默现下」。
160
- 引擎 override 本钩子返回**缺失** aux 的列表 ``[{repo, allow_patterns, label}, ...]``,合成
161
- 前置 gate 据此起**追踪下载**(上 Dashboard 面板)+ 返回 409 ``model_downloading`` + 前端
162
- 自动重试;待全部就绪后 provider 把它们显式喂给 SDK(绕开其静默下载)。返回 ``None`` = 无
163
- 待下 aux(已全缓存,或引擎无此需求)。
182
+ (w2v-bert / codec / vocoder 等)——违反「前后台状态同步」+「绝不 worker 静默现下」。合成
183
+ 前置 gate 据本钩子的缺失列表 ``[{repo, allow_patterns, label}, ...]`` 起**追踪下载**(上
184
+ Dashboard)+ 返回 409 ``model_downloading`` + 前端自动重试;待全部就绪后 provider 把它们
185
+ 显式喂给 SDK。未迁移 / 无 aux → ``None``。provider 若直接 override 则其 override 优先(MRO)。
186
+ ``opts`` 保留签名兼容(aux 恒为静态,不依赖单次请求)。
164
187
 
165
188
  同 ``download_spec`` 纪律:server 进程内调用,纯字符串/缓存存在性逻辑,绝不加载模型/下载。"""
166
- return None
189
+ from openspeechapi.core.model_profile import derive_missing_aux
190
+ return derive_missing_aux(cls.model_profile(settings))
167
191
 
168
192
  @classmethod
169
193
  def expected_local_repo(cls, settings) -> str | None: # noqa: ANN001
170
194
  """该引擎在本机会从本地缓存加载的 HF repo id(用于「是否已下载」预检)。
171
195
 
172
- 在 **server 进程** 里调用以判断本地模型是否已缓存 —— 因此本方法及其所有 override
173
- 必须是 **纯字符串逻辑**:绝不 import torch / transformers / mlx 等重依赖,绝不加载
174
- 模型(重依赖只在 worker 进程)。``settings`` 可能是 dataclass 实例或 dict。默认取
175
- ``model`` 字段;不是 ``org/name`` 形式的 HF id(本地路径、单段名等)则返回 None,
176
- 预检随即跳过(无法判断是否已下载 → 不拦截)。平台会重映射 repo 的引擎(如 gemma4)
177
- 应 override 返回本平台实际加载的那个 id。"""
196
+ 已迁移(:meth:`model_profile` 非空)→ 从 profile 派生(``expected_repo or primary.repo``,
197
+ 且形如合法 HF id);未迁移 → 旧默认(``settings.model`` 且含 ``/``)。平台会重映射 repo 的
198
+ 引擎(如 gemma4)经 ``profile.expected_repo`` 表达。provider 若直接 override 则其 override
199
+ 优先(MRO)。
200
+
201
+ 在 **server 进程** 里调用 —— 本方法及其所有 override 必须是 **纯字符串逻辑**:绝不 import
202
+ torch / transformers / mlx,绝不加载模型。``settings`` 可能是 dataclass 实例或 dict。"""
203
+ from openspeechapi.core.model_profile import derive_expected_repo
204
+ profile = cls.model_profile(settings)
205
+ if profile is not None:
206
+ return derive_expected_repo(profile)
178
207
  model = settings.get("model") if isinstance(settings, dict) else getattr(settings, "model", None)
179
208
  model = (model or "").strip()
180
209
  return model if "/" in model else None
@@ -183,17 +212,22 @@ class SpeechProvider(ABC):
183
212
  self, repo: str, *, hub: str = "", model_path: str = "",
184
213
  ms_repo_map: "dict[str, str] | None" = None, custom_url: str = "",
185
214
  fixed_path: str = "", category: str = "asr/model",
186
- snapshot: bool = False,
215
+ snapshot: bool = False, aim_spec: Any = _USE_SELF_AIM_SPEC,
187
216
  ) -> str:
188
217
  """Resolve this provider's model via the unified chain
189
218
  (model_path → aim → global source → custom url → symlink). See model_hub.
190
219
 
191
220
  Pass ``snapshot=True`` for loaders that require a real local directory
192
221
  even when the source is HF (e.g. dolphin). The resolver will call
193
- ``huggingface_hub.snapshot_download`` and return the local dir path."""
222
+ ``huggingface_hub.snapshot_download`` and return the local dir path.
223
+
224
+ ``aim_spec``: 默认(sentinel)用 ``self.aim_model_spec()``(静态 config 的 spec)——
225
+ 对「加载即 config 模型」的引擎正确。**按请求换 model 的引擎**须显式传 ``self._aim_spec_for(s)``
226
+ (该请求模型的 spec),否则 aim 会把请求模型的 ``fixed_path`` 错链到 config 模型的 store。"""
194
227
  from openspeechapi.core.model_hub import resolve_model_source # local: avoid cycle
228
+ spec = self.aim_model_spec() if aim_spec is _USE_SELF_AIM_SPEC else aim_spec
195
229
  return resolve_model_source(
196
- repo, hub=hub, model_path=model_path, aim_spec=self.aim_model_spec(),
230
+ repo, hub=hub, model_path=model_path, aim_spec=spec,
197
231
  ms_repo_map=ms_repo_map, custom_url=custom_url, fixed_path=fixed_path,
198
232
  category=category, snapshot=snapshot,
199
233
  )
@@ -87,14 +87,33 @@ def reachable_sources() -> dict[str, bool]:
87
87
  }
88
88
 
89
89
 
90
+ def huggingface_reachable() -> bool:
91
+ """Whether real huggingface.co is reachable right now (cached, 5-min TTL). Drives the
92
+ reachability-GATED HF-mirror decision at server startup: a configured ``hf_endpoint``
93
+ mirror is force-exported only when real HF is unreachable, so one config works on both
94
+ China (HF blocked → mirror) and overseas (HF up → real HF) boxes — and a down/slow mirror
95
+ never breaks a box that can reach HF directly."""
96
+ return _reachable("https://huggingface.co")
97
+
98
+
90
99
  def ensure_reachable_download_env() -> None:
91
100
  """Point HF downloads at a reachable endpoint so a loader's OWN sub-downloads
92
101
  (e.g. funasr's VAD model) also succeed on HF-blocked nets — not just the main
93
102
  weights we materialise ourselves.
94
103
 
95
104
  Respects an existing HF_ENDPOINT (operator/config override). Otherwise, when
96
- huggingface.co is unreachable but a known mirror is up, exports the mirror and
97
- disables Xet (mirrors don't proxy HF's Xet CAS → classic LFS). Idempotent."""
105
+ huggingface.co is unreachable but a known mirror is up, exports the mirror. Also
106
+ disables HF Xet by default on every path (see below). Idempotent."""
107
+ # Disable HF Xet by DEFAULT (real-HF AND mirror paths). Xet's chunk CDN
108
+ # (cas-bridge.xethub.hf.co / *.cdn.hf.co) stalls on many China/restricted nets EVEN WHEN
109
+ # a reachability probe of its host succeeds — the host answers 200 but the chunk transfer
110
+ # hangs at 0 bytes (empirically on 20.3: real HF + both Xet hosts all "reachable" per
111
+ # _probe, yet weights.npz / large safetensors never progress, while classic LFS downloads
112
+ # fine). Probing the Xet CDN can't distinguish this, so we can't gate on reachability.
113
+ # Xet only buys dedup/parallel speedups on Xet-friendly (overseas) nets → default it off;
114
+ # re-enable there with OSA_HF_ENABLE_XET=1 (or HF_HUB_DISABLE_XET=0 directly).
115
+ if os.environ.get("OSA_HF_ENABLE_XET", "").strip().lower() not in ("1", "true", "yes"):
116
+ os.environ.setdefault("HF_HUB_DISABLE_XET", "1")
98
117
  if os.environ.get("HF_ENDPOINT", "").strip():
99
118
  return
100
119
  if _reachable("https://huggingface.co"):
@@ -108,6 +127,22 @@ def ensure_reachable_download_env() -> None:
108
127
  return
109
128
 
110
129
 
130
+ def funasr_safe_device(device: str) -> str:
131
+ """Coerce a requested ``mps`` device to ``cpu`` for funasr-backed providers.
132
+
133
+ funasr's feature extraction forces float64 on Apple Silicon (``Cannot convert a MPS
134
+ Tensor to float64 dtype as the MPS framework doesn't support float64``), so Metal
135
+ placement crashes. ``cpu``/``cuda`` pass through unchanged; ``mps`` → ``cpu`` with a
136
+ warning so the user knows the requested device was declined. Shared by the funasr
137
+ providers (paraformer / funasr / sensevoice)."""
138
+ if (device or "").strip().lower() == "mps":
139
+ logger.warning(
140
+ "funasr can't run on Apple Silicon MPS (float64 unsupported on Metal) — using cpu"
141
+ )
142
+ return "cpu"
143
+ return device
144
+
145
+
111
146
  def effective_source(hub: str) -> str:
112
147
  """Effective download source for a model: 'hf' or 'ms'.
113
148
 
@@ -317,9 +352,17 @@ def _download_candidates(
317
352
  return [c for c in ordered if c is not None]
318
353
 
319
354
 
355
+ # A loadable transformers tokenizer ships as one of these (bare filename, any repo). Used to
356
+ # catch a snapshot whose big weights finished but whose (small) tokenizer file never got
357
+ # fetched — no ``.incomplete`` marker exists for a file that was never started.
358
+ _TOKENIZER_FILES = frozenset({
359
+ "tokenizer.json", "tokenizer.model", "tokenizer_config.json", "tekken.json",
360
+ "vocab.json", "vocab.txt", "spiece.model", "merges.txt", "sentencepiece.bpe.model",
361
+ })
362
+
363
+
320
364
  def _hf_snapshot_complete(snapshot_path: str) -> bool:
321
- """False if the snapshot's repo still has an in-progress download — a
322
- ``blobs/<etag>.incomplete`` block.
365
+ """False if the snapshot's repo still has an in-progress OR missing-file download.
323
366
 
324
367
  ``snapshot_download(..., local_files_only=True)`` returns the snapshot folder as soon as
325
368
  it exists, *without* checking the files are all there (its own source says "we can't
@@ -329,14 +372,43 @@ def _hf_snapshot_complete(snapshot_path: str) -> bool:
329
372
  repo has its small configs symlinked but *no* weight symlink, and the snapshot folder
330
373
  looks populated. We therefore inspect the sibling ``blobs/`` ourselves. Format-agnostic:
331
374
  catches a truncated ct2 ``model.bin`` / NeMo ``.nemo`` / MLX ``.npz`` / sharded
332
- ``.safetensors`` alike, with no per-engine weight-name list to keep in sync."""
375
+ ``.safetensors`` alike, with no per-engine weight-name list to keep in sync.
376
+
377
+ Also catches the *inverse* gap: a **sharded** transformers model (has a ``*.index.json``
378
+ weight map) whose big shards all finished but whose small tokenizer file never got fetched
379
+ — there is no ``.incomplete`` for a file that was never started, so the blob check alone
380
+ misses it (observed: Voxtral-Small-24B had all 11 shards + config but no ``tekken.json`` →
381
+ ``AutoProcessor`` died "need sentencepiece or tiktoken", yet ``model_is_cached`` lied True →
382
+ the gate 放行'd it → worker crash instead of a tracked re-download of the missing file)."""
333
383
  blobs = os.path.join(os.path.dirname(os.path.dirname(snapshot_path)), "blobs")
334
384
  try:
335
- return not any(name.endswith(".incomplete") for name in os.listdir(blobs))
385
+ if any(name.endswith(".incomplete") for name in os.listdir(blobs)):
386
+ return False
336
387
  except OSError:
337
388
  # No blobs/ dir (non-standard layout, e.g. a local_dir copy) → can't prove it's
338
389
  # incomplete; trust the snapshot rather than spuriously re-downloading.
339
390
  return True
391
+ try:
392
+ names = set(os.listdir(snapshot_path))
393
+ except OSError:
394
+ return True
395
+ # Sharded transformers model missing its tokenizer → incomplete (a complete one always
396
+ # ships a tokenizer). Only gates on ``*.index.json`` so single-file / non-transformers
397
+ # models (funasr yaml, whisper .pt, vosk …) are never spuriously flagged.
398
+ if any(n.endswith(".index.json") for n in names) and not (names & _TOKENIZER_FILES):
399
+ return False
400
+ return True
401
+
402
+
403
+ # Redundant alternative-format weights that a repo ships alongside the sharded transformers
404
+ # weights but that transformers (and thus our providers) NEVER load — so a snapshot missing ONLY
405
+ # these is still complete/usable. Excluded from the strict all-files snapshot check, else e.g.
406
+ # Voxtral-Small-24B (ships the 48GB Mistral ``consolidated.safetensors`` on top of its 11
407
+ # transformers shards) reads as "incomplete" forever → gate 409-loops a loadable model.
408
+ _REDUNDANT_REPO_PATTERNS = (
409
+ "consolidated.safetensors", "consolidated-*-of-*.safetensors", "consolidated.*.pth",
410
+ "original/**", "original/*",
411
+ )
340
412
 
341
413
 
342
414
  def _hf_local(repo: str) -> str | None:
@@ -344,6 +416,11 @@ def _hf_local(repo: str) -> str | None:
344
416
  None. Checks both the default HF cache (where funasr/transformers download) and our
345
417
  storage root, so an existing copy is reused no matter which path originally fetched it.
346
418
 
419
+ ``ignore_patterns`` drops redundant alternative-format weights (Mistral ``consolidated.*``,
420
+ Llama ``original/**``) that transformers never loads — otherwise a repo that ships them makes
421
+ the strict all-files snapshot check raise ``IncompleteSnapshotError`` for a copy the engine
422
+ can in fact load from its shards.
423
+
347
424
  A snapshot still mid-download is skipped (``_hf_snapshot_complete``): without this an
348
425
  interrupted fetch masquerades as cached — ``model_is_cached`` would lie and
349
426
  ``build_aim_spec`` would skip aim pre-provisioning, leaving the engine to load a broken
@@ -355,11 +432,20 @@ def _hf_local(repo: str) -> str | None:
355
432
  return None
356
433
  for cache_dir in (None, os.path.join(default_storage_root(), "huggingface")):
357
434
  try:
358
- path = snapshot_download(repo, cache_dir=cache_dir, local_files_only=True)
435
+ path = snapshot_download(
436
+ repo, cache_dir=cache_dir, local_files_only=True,
437
+ ignore_patterns=list(_REDUNDANT_REPO_PATTERNS),
438
+ )
359
439
  except Exception: # noqa: BLE001 - not in this cache → try the next / give up
360
440
  continue
361
- if _hf_snapshot_complete(path):
362
- return path # else: in-progress download in this cache → try the next / give up
441
+ # Require BOTH: no in-progress/missing-tokenizer partial (_hf_snapshot_complete) AND actual
442
+ # weight bytes on disk (_dir_has_model_weights). An interrupted large download can leave a
443
+ # full snapshot *skeleton* — every file a symlink, but the weight blobs never fetched
444
+ # (dangling) — with no ``*.incomplete`` marker; snapshot_download(local_files_only) then
445
+ # returns the path and _hf_snapshot_complete passes, so model_is_cached would lie True for a
446
+ # 4KB "model" (bocciDeRock/mlx_qwen3_omni_4bit: 0 blobs of a 21.7GB repo, 19 stale locks).
447
+ if _hf_snapshot_complete(path) and _dir_has_model_weights(path):
448
+ return path # else: partial / skeleton-only → try the next cache / give up
363
449
  return None
364
450
 
365
451
 
@@ -389,26 +475,85 @@ def _ms_local(repo: str) -> str | None:
389
475
  # files (config.yaml, am.mvn, tokenizer …) but not the big weights (e.g. a ModelScope
390
476
  # "Task failed" that never finished model.pt). Reusing such a dir loads the architecture
391
477
  # from config with RANDOM weights → structured-but-garbage transcripts.
392
- _WEIGHT_SUFFIXES = (".pt", ".pth", ".bin", ".safetensors", ".onnx", ".gguf", ".ckpt")
478
+ # Recognised weight-file extensions. Keep BROAD — a missing format makes a *complete* model look
479
+ # weightless → the download gate 409-loops forever (MLX ``.npz`` was the first casualty). Covers
480
+ # torch / safetensors / onnx / gguf + MLX (.npz) / flax (.msgpack) / keras-tf (.h5) / tflite / coreml.
481
+ _WEIGHT_SUFFIXES = (
482
+ ".pt", ".pth", ".pth.tar", ".bin", ".safetensors", ".onnx", ".gguf", ".ckpt",
483
+ ".npz", ".msgpack", ".h5", ".tflite", ".mlmodel",
484
+ )
485
+ # Obvious non-weight files — excluded from the "large unrecognised file = weights" fallback below.
486
+ _METADATA_SUFFIXES = (
487
+ ".json", ".txt", ".md", ".yaml", ".yml", ".model", ".vocab", ".ark", ".cfg", ".cfgg",
488
+ ".gitattributes", ".py", ".sh", ".png", ".jpg", ".jpeg", ".ipynb", ".spm", ".list",
489
+ )
393
490
 
394
491
 
395
492
  def _dir_has_model_weights(d: str) -> bool:
396
- """True if ``d`` holds a substantial (>1MB) model-weights file at its top level.
397
- (Catches missing/stub weights; it can't detect a large-but-truncated file — for HF a
398
- truncated/in-progress download is caught upstream by ``_hf_snapshot_complete``'s
399
- ``*.incomplete`` blob check in ``_hf_local``.)"""
493
+ """True if ``d`` holds a substantial model-weights file at its top level.
494
+
495
+ A known weight suffix (>1MB) is the fast path. **Fallback**: any large (>10MB) top-level file
496
+ that isn't obvious metadata counts as weights too — a suffix allowlist can never keep up with
497
+ every framework's format, and a *complete* model that ships an unlisted weight file (MLX
498
+ ``weights.npz``, FireRedASR ``model.pth.tar``, …) must NOT be judged weightless, or the download
499
+ gate 409-loops it forever. Config/vocab/tokenizer files stay well under the threshold (and are
500
+ suffix-excluded), so a stub/metadata-only dir still returns False.
501
+ (Can't detect a large-but-truncated file — an in-progress HF download is caught upstream by
502
+ ``_hf_snapshot_complete``'s ``*.incomplete`` blob check.)"""
400
503
  try:
401
504
  names = os.listdir(d)
402
505
  except OSError:
403
506
  return False
507
+ largest_other = 0
404
508
  for name in names:
405
- if name.lower().endswith(_WEIGHT_SUFFIXES):
406
- try:
407
- if os.path.getsize(os.path.join(d, name)) > 1_000_000:
408
- return True
409
- except OSError:
410
- continue
411
- return False
509
+ low = name.lower()
510
+ try:
511
+ size = os.path.getsize(os.path.join(d, name))
512
+ except OSError:
513
+ continue
514
+ if low.endswith(_WEIGHT_SUFFIXES) and size > 1_000_000:
515
+ return True
516
+ if not name.startswith(".") and not low.endswith(_METADATA_SUFFIXES):
517
+ largest_other = max(largest_other, size)
518
+ return largest_other > 10_000_000
519
+
520
+
521
+ def local_copy_is_complete(path: str) -> bool:
522
+ """Whether a resolved local model dir is a COMPLETE, loadable copy (not a partial/
523
+ interrupted download). Handles an HF-cache repo dir (``models--org--name`` with
524
+ ``refs/`` + ``snapshots/``) by resolving its current ref's snapshot; a plain dir is
525
+ checked as-is. Runs the same weights + sharded-tokenizer + ``*.incomplete`` checks used
526
+ for the HF cache.
527
+
528
+ Lets aim's *registry-present* check (``aim_has_model``) reject an aim-ingested download
529
+ that was interrupted — aim records the entry (and full expected size) the moment ingest
530
+ starts, so registry-present ≠ usable (Voxtral-Small-24B: all 11 shards but no
531
+ ``tekken.json``, registered at 48GB → the gate would 放行 it and the worker crash)."""
532
+ try:
533
+ if not path or not os.path.isdir(path):
534
+ return False
535
+ d = path
536
+ ref = os.path.join(path, "refs", "main")
537
+ if os.path.isfile(ref):
538
+ with open(ref) as f:
539
+ commit = f.read().strip()
540
+ snap = os.path.join(path, "snapshots", commit)
541
+ if os.path.isdir(snap):
542
+ d = snap
543
+ # aim native-CAS wrapper (``trees/`` + ``refs/``, no ``snapshots/``): the weights live
544
+ # content-addressed under ``trees/``, NOT as plain files we can list — a weight-file scan
545
+ # would spuriously report "no weights" and 409-loop EVERY aim-ingested HF model (mlx-whisper,
546
+ # firered, …). We can't file-inspect the CAS, so trust it unless a truncated
547
+ # ``blobs/*.incomplete`` positively proves it partial (``_hf_snapshot_complete``).
548
+ try:
549
+ entries = set(os.listdir(d))
550
+ except OSError:
551
+ return True
552
+ if "trees" in entries and "snapshots" not in entries:
553
+ return _hf_snapshot_complete(d)
554
+ return _dir_has_model_weights(d) and _hf_snapshot_complete(d)
555
+ except Exception: # noqa: BLE001 - can't verify → trust it (don't spuriously re-download)
556
+ return True
412
557
 
413
558
 
414
559
  def _local_hit(kind: str, rid: str) -> str | None:
@@ -574,6 +719,19 @@ def resolve_hub_model(
574
719
  local = aim_local_path_or(model_path, "")
575
720
  if local:
576
721
  return local
722
+ # aim-store fallback: an aim-ingested (native-CAS) model whose HF cache aim's relink left
723
+ # inconsistent (refs/main → a missing snapshot / IncompleteSnapshot) fails to load by repo id
724
+ # ("cannot find the requested files in the local cache"), though its store copy is intact —
725
+ # resolve the store dir for THIS model (mirrors gemma4._resolve_load_target). None (not
726
+ # aim-ingested) → the normal repo-id / download path below. Needs ``aim`` on PATH (the server
727
+ # launches with ~/.local/bin). Fixes e.g. a Lab-picked whisper/funasr model auto-downloaded via
728
+ # aim then failing to load.
729
+ from openspeechapi.local_engines.aim_resolver import aim_local_path
730
+ scheme = "ms" if effective_source(hub) == "ms" else "hf"
731
+ repo = (ms_repo_map or {}).get(model, model) if scheme == "ms" else model
732
+ store = aim_local_path(aim_model_id(repo, scheme))
733
+ if store:
734
+ return store
577
735
  return resolve_model_source(
578
736
  model, hub=hub, model_path=model_path, ms_repo_map=ms_repo_map,
579
737
  aim_spec=None, snapshot=False,