openspeechapi 0.2.21__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.
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/PKG-INFO +1 -1
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/config.py +25 -3
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/core/base.py +14 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/core/model_hub.py +26 -6
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/dispatch/dispatcher.py +36 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/providers/stt/canary_qwen_stt.py +21 -3
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/providers/stt/faster_whisper.py +40 -2
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/providers/stt/fireredasr_stt.py +32 -3
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/providers/stt/gemma4.py +33 -6
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/providers/stt/mms_stt.py +22 -4
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/providers/stt/moonshine_stt.py +27 -8
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/providers/stt/phi4_multimodal_stt.py +22 -4
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/providers/stt/qwen3_omni_stt.py +26 -4
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/providers/stt/vosk_stt.py +80 -5
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/providers/stt/whisper.py +84 -2
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/server/app.py +2 -0
- openspeechapi-0.2.23/openspeechapi/server/model_downloads.py +396 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/server/routes/management.py +118 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/server/routes/stt.py +38 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/server/routes/webui.py +10 -2
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/server/webui/app.js +274 -5
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/server/webui/index.html +2 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/server/webui/styles.css +61 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/server/ws/stt_stream.py +53 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/pyproject.toml +1 -1
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/.gitignore +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/README.md +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/__init__.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/__main__.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/cli.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/client/__init__.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/client/client.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/core/__init__.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/core/enums.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/core/models.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/core/registry.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/core/settings.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/demo.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/dispatch/__init__.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/dispatch/aim_provision.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/dispatch/context.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/dispatch/executors/__init__.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/dispatch/executors/base.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/dispatch/executors/in_process.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/dispatch/executors/remote.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/dispatch/executors/subprocess_exec.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/dispatch/fanout.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/dispatch/filters.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/dispatch/lifecycle.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/dispatch/watcher.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/engine_catalog.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/engine_registry.yaml +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/exceptions.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/factory.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/local_engines/__init__.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/local_engines/aim_resolver.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/local_engines/backends/__init__.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/local_engines/backends/docker_backend.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/local_engines/backends/native_backend.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/local_engines/base.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/local_engines/engines/__init__.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/local_engines/engines/faster_whisper.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/local_engines/engines/fish_speech.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/local_engines/engines/sherpa_onnx.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/local_engines/engines/whisper.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/local_engines/engines/whisperlivekit.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/local_engines/isolated_venv.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/local_engines/manager.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/local_engines/models.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/local_engines/progress.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/local_engines/registry.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/local_engines/task_store.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/local_engines/tasks.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/logging_config.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/observe/__init__.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/observe/base.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/observe/debug.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/observe/latency.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/observe/metrics.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/observe/tracing.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/observe/usage.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/providers/__init__.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/providers/_template.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/providers/stt/__init__.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/providers/stt/_local_audio.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/providers/stt/alibaba.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/providers/stt/assemblyai.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/providers/stt/azure_speech.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/providers/stt/baidu.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/providers/stt/deepgram.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/providers/stt/dolphin_stt.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/providers/stt/elevenlabs.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/providers/stt/funasr_stt.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/providers/stt/google_cloud.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/providers/stt/iflytek.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/providers/stt/kimi_audio_stt.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/providers/stt/macos_speech.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/providers/stt/mlx_whisper_stt.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/providers/stt/mms_languages.json +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/providers/stt/openai.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/providers/stt/paraformer.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/providers/stt/parakeet_mlx_stt.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/providers/stt/qwen3_asr.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/providers/stt/sensevoice.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/providers/stt/sherpa_onnx.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/providers/stt/tencent.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/providers/stt/volcengine.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/providers/stt/voxtral_stt.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/providers/stt/wenet_stt.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/providers/stt/whisperlivekit.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/providers/stt/windows_speech.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/providers/tts/__init__.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/providers/tts/alibaba.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/providers/tts/azure_speech.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/providers/tts/baidu.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/providers/tts/coqui.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/providers/tts/cosyvoice.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/providers/tts/deepgram.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/providers/tts/elevenlabs.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/providers/tts/fish_speech.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/providers/tts/google_cloud.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/providers/tts/iflytek.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/providers/tts/macos_say.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/providers/tts/minimax.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/providers/tts/openai.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/providers/tts/piper.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/providers/tts/tencent.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/providers/tts/volcengine.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/providers/tts/windows_sapi.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/server/__init__.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/server/auth.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/server/extras_installer.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/server/middleware.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/server/native_installer.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/server/routes/__init__.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/server/routes/tts.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/server/system_metrics.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/server/ws/__init__.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/server/ws/tts_stream.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/telemetry/__init__.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/telemetry/perf.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/utils/__init__.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/utils/audio_converter.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/utils/audio_playback.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/vendor_registry.yaml +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/providers.example.yaml +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/scripts/aim_adopt.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/scripts/aim_consumers.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/scripts/engines/cloud/install.sh +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/scripts/engines/faster-whisper/native/install.sh +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/scripts/engines/fish-speech/native/install.sh +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/scripts/engines/macos-stt/_bundle.sh +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/scripts/engines/macos-stt/install.sh +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/scripts/engines/macos-stt/macos_stt.swift +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/scripts/engines/macos-stt/request_auth.swift +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/scripts/engines/sherpa-onnx/native/install.sh +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/scripts/engines/sherpa-onnx/native/run_streaming_server.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/scripts/engines/whisper/native/install.sh +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/scripts/engines/whisperlivekit/native/install.sh +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/scripts/gen_mms_languages.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/scripts/preload_stt_model.py +0 -0
- {openspeechapi-0.2.21 → openspeechapi-0.2.23}/scripts/release.sh +0 -0
|
@@ -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
|
|
285
|
-
|
|
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,
|
|
@@ -94,6 +94,20 @@ class SpeechProvider(ABC):
|
|
|
94
94
|
"""
|
|
95
95
|
return None
|
|
96
96
|
|
|
97
|
+
@classmethod
|
|
98
|
+
def expected_local_repo(cls, settings) -> str | None: # noqa: ANN001
|
|
99
|
+
"""该引擎在本机会从本地缓存加载的 HF repo id(用于「是否已下载」预检)。
|
|
100
|
+
|
|
101
|
+
在 **server 进程** 里调用以判断本地模型是否已缓存 —— 因此本方法及其所有 override
|
|
102
|
+
必须是 **纯字符串逻辑**:绝不 import torch / transformers / mlx 等重依赖,绝不加载
|
|
103
|
+
模型(重依赖只在 worker 进程)。``settings`` 可能是 dataclass 实例或 dict。默认取
|
|
104
|
+
``model`` 字段;不是 ``org/name`` 形式的 HF id(本地路径、单段名等)则返回 None,
|
|
105
|
+
预检随即跳过(无法判断是否已下载 → 不拦截)。平台会重映射 repo 的引擎(如 gemma4)
|
|
106
|
+
应 override 返回本平台实际加载的那个 id。"""
|
|
107
|
+
model = settings.get("model") if isinstance(settings, dict) else getattr(settings, "model", None)
|
|
108
|
+
model = (model or "").strip()
|
|
109
|
+
return model if "/" in model else None
|
|
110
|
+
|
|
97
111
|
def _resolve_model(
|
|
98
112
|
self, repo: str, *, hub: str = "", model_path: str = "",
|
|
99
113
|
ms_repo_map: "dict[str, str] | None" = None, custom_url: str = "",
|
|
@@ -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'`` →
|
|
116
|
-
|
|
117
|
-
HF
|
|
118
|
-
|
|
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
|
|
@@ -410,6 +417,19 @@ def local_model_path(repo: str, ms_repo_map: Mapping[str, str] | None = None) ->
|
|
|
410
417
|
return _hf_local(repo) or _ms_local(ms_repo)
|
|
411
418
|
|
|
412
419
|
|
|
420
|
+
def model_is_cached(repo: str, ms_repo_map: Mapping[str, str] | None = None) -> bool:
|
|
421
|
+
"""True 表示 repo 的【完整】本地副本已存在(部分/未完成下载算 False)。
|
|
422
|
+
|
|
423
|
+
用于 STT 转写/流式的「是否已下载」预检 —— 未下载时路由层立即返回 409 引导去下载,
|
|
424
|
+
而不是在请求里现下大模型导致 300s 超时。委托给 ``local_model_path``(对不完整下载返回
|
|
425
|
+
None,正合需要;完成度由 ``_hf_local`` 的 snapshot 校验 + ``_dir_has_model_weights``
|
|
426
|
+
把关)。任何异常都当作「未缓存」处理,绝不让预检本身抛错阻塞请求。"""
|
|
427
|
+
try:
|
|
428
|
+
return local_model_path(repo, ms_repo_map) is not None
|
|
429
|
+
except Exception: # noqa: BLE001 - 预检失败时退回「未缓存」,不阻断/不误报
|
|
430
|
+
return False
|
|
431
|
+
|
|
432
|
+
|
|
413
433
|
def build_aim_spec(model: str, hub: str, ms_repo_map: Mapping[str, str] | None = None,
|
|
414
434
|
category: str = "asr/model") -> AimModelSpec | None:
|
|
415
435
|
"""Shared ``aim_model_spec`` body for HF⇄ModelScope-mirrored models.
|
|
@@ -452,6 +452,42 @@ class ServiceDispatcher:
|
|
|
452
452
|
raise ProviderNotFoundError(alias)
|
|
453
453
|
return self._handles[alias]
|
|
454
454
|
|
|
455
|
+
# Local execution modes: the model is loaded/downloaded on THIS box (so a
|
|
456
|
+
# missing local model means an in-request download). Remote/cloud engines
|
|
457
|
+
# download nothing locally → never pre-checked.
|
|
458
|
+
_LOCAL_EXEC_MODES = frozenset({"subprocess", "local", "in_process"})
|
|
459
|
+
|
|
460
|
+
def expected_repo_for(self, alias: str, model_override: str | None = None) -> str | None:
|
|
461
|
+
"""本地引擎在本机预期加载的 HF repo id;远程/云引擎或取不到时返回 None。
|
|
462
|
+
|
|
463
|
+
给路由层的「模型是否已下载」预检用:仅对本地类引擎(subprocess/local/in_process,
|
|
464
|
+
排除 remote)返回 repo,远程引擎一律 None(不在本机下载模型)。委托给 provider 类的
|
|
465
|
+
``expected_local_repo``(纯字符串、不加载模型、不 import 重依赖)。
|
|
466
|
+
|
|
467
|
+
``model_override`` 非空时(Lab Advanced Options 的按请求 model 覆盖),解析的是**被覆盖
|
|
468
|
+
的** model(保留 backend 等其它配置),这样预检对照的是该请求实际会加载的模型,而非引擎
|
|
469
|
+
静态配置。任何异常/找不到都返回 None —— 预检宁可放行也不误拦。"""
|
|
470
|
+
handle = self._handles.get(alias)
|
|
471
|
+
if handle is None:
|
|
472
|
+
return None
|
|
473
|
+
exec_mode = (
|
|
474
|
+
handle.exec_mode.value
|
|
475
|
+
if hasattr(handle.exec_mode, "value")
|
|
476
|
+
else str(handle.exec_mode)
|
|
477
|
+
)
|
|
478
|
+
if str(exec_mode).strip().lower() not in self._LOCAL_EXEC_MODES:
|
|
479
|
+
return None
|
|
480
|
+
try:
|
|
481
|
+
settings = getattr(handle, "settings_dict", None)
|
|
482
|
+
if settings is None:
|
|
483
|
+
settings = getattr(handle, "settings", None) or {}
|
|
484
|
+
if model_override:
|
|
485
|
+
base = settings if isinstance(settings, dict) else (getattr(settings, "__dict__", {}) or {})
|
|
486
|
+
settings = {**base, "model": model_override}
|
|
487
|
+
return handle.provider_cls.expected_local_repo(settings)
|
|
488
|
+
except Exception: # noqa: BLE001 - 预检取 repo 失败 → 当作无法判断,放行
|
|
489
|
+
return None
|
|
490
|
+
|
|
455
491
|
async def _negotiate_audio_format(
|
|
456
492
|
self, handle: "_ProviderHandle", audio: AudioData
|
|
457
493
|
) -> AudioData:
|
{openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/providers/stt/canary_qwen_stt.py
RENAMED
|
@@ -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
|
-
|
|
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(
|
|
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
|
-
|
|
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
|
|
9
|
-
|
|
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:
|
|
@@ -143,19 +143,46 @@ class Gemma4STT(STTProvider):
|
|
|
143
143
|
"google/gemma-4-E2B-it": "mlx-community/gemma-4-E2B-it-8bit",
|
|
144
144
|
}
|
|
145
145
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
146
|
+
@classmethod
|
|
147
|
+
def _resolve_repo_for_platform(cls, model: str, backend: str) -> tuple[str, str]:
|
|
148
|
+
"""Pure-string (backend, model) resolver — NO torch/mlx import, NO model load.
|
|
149
|
+
'auto' picks by platform (Apple Silicon→mlx, else→cuda) and remaps the model to
|
|
150
|
+
that backend's repo namespace when they disagree. Shared by the instance
|
|
151
|
+
``_resolve_backend_and_model`` (worker) and the classmethod ``expected_local_repo``
|
|
152
|
+
(server-process download pre-check), so both agree on the id this box loads."""
|
|
153
|
+
b = (backend or "auto").strip().lower()
|
|
150
154
|
if b == "auto":
|
|
151
155
|
import sys
|
|
152
156
|
b = "mlx" if sys.platform == "darwin" else "cuda"
|
|
153
157
|
if b == "mlx" and model.startswith("google/"):
|
|
154
|
-
model =
|
|
158
|
+
model = cls._HF_TO_MLX.get(model, model)
|
|
155
159
|
elif b == "cuda" and model.startswith("mlx-community/"):
|
|
156
|
-
model =
|
|
160
|
+
model = cls._MLX_TO_HF.get(model, model)
|
|
157
161
|
return b, model
|
|
158
162
|
|
|
163
|
+
def _resolve_backend_and_model(self, model: str) -> tuple[str, str]:
|
|
164
|
+
"""(backend, model): 'auto' picks by platform (Apple Silicon→mlx, else→cuda) and
|
|
165
|
+
remaps the model to that backend's repo namespace when they disagree."""
|
|
166
|
+
return self._resolve_repo_for_platform(model, self.settings.backend)
|
|
167
|
+
|
|
168
|
+
@classmethod
|
|
169
|
+
def expected_local_repo(cls, settings) -> str | None: # noqa: ANN001
|
|
170
|
+
"""The HF repo this box actually loads from cache — i.e. the **remapped** id, so
|
|
171
|
+
the «is it downloaded» pre-check looks for the right copy (e.g. on Linux/CUDA the
|
|
172
|
+
configured MLX ``mlx-community/gemma-4-E4B-it-8bit`` maps to ``google/gemma-4-E4B-it``,
|
|
173
|
+
which is what ``_load_cuda`` would download). Reuses the pure-string platform/backend
|
|
174
|
+
mapping (no torch/mlx import). Local paths / non-HF ids → None (pre-check skipped)."""
|
|
175
|
+
if isinstance(settings, dict):
|
|
176
|
+
model = (settings.get("model") or "").strip()
|
|
177
|
+
backend = settings.get("backend") or "auto"
|
|
178
|
+
else:
|
|
179
|
+
model = (getattr(settings, "model", None) or "").strip()
|
|
180
|
+
backend = getattr(settings, "backend", None) or "auto"
|
|
181
|
+
if "/" not in model:
|
|
182
|
+
return None
|
|
183
|
+
_backend, resolved = cls._resolve_repo_for_platform(model, backend)
|
|
184
|
+
return resolved if "/" in resolved else None
|
|
185
|
+
|
|
159
186
|
def aim_model_spec(self) -> AimModelSpec | None:
|
|
160
187
|
"""Let aim (ai-model-manager) download + manage the model, per CLAUDE.md's aim
|
|
161
188
|
rule. Resolve the backend first so the source targets the repo this box runs
|
|
@@ -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
|
-
|
|
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
|
-
|
|
153
|
+
target, target_lang=s.language, local_files_only=local_only
|
|
136
154
|
)
|
|
137
155
|
model = Wav2Vec2ForCTC.from_pretrained(
|
|
138
|
-
|
|
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.
|
|
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.
|
|
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.
|
|
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
|
-
|
|
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(
|
|
77
|
-
m = MoonshineForConditionalGeneration.from_pretrained(
|
|
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.
|
|
100
|
+
self._loaded_key = key
|
|
82
101
|
|
|
83
102
|
# ── transcription ──────────────────────────────────────────────────────
|
|
84
103
|
async def transcribe(
|
{openspeechapi-0.2.21 → openspeechapi-0.2.23}/openspeechapi/providers/stt/phi4_multimodal_stt.py
RENAMED
|
@@ -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
|
-
|
|
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(
|
|
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
|
-
|
|
132
|
+
target, trust_remote_code=True, torch_dtype=s.dtype,
|
|
115
133
|
_attn_implementation=impl,
|
|
116
134
|
)
|
|
117
135
|
return m.to(d)
|