将FunASR自动更新参数加入到环境变量

main
Bifang 2026-10-09 14:17:43 +08:00
parent a1193a5f4a
commit 83bbdd5d5f
3 changed files with 10 additions and 7 deletions

View File

@ -94,6 +94,8 @@
# -----------------------------------------------------------------------------
# API_KEY=your_api_key_here
# LOG_LEVEL=INFO
# true 跳过 FunASR 启动时的联网更新检查;false 时允许检查更新。
# FUNASR_DISABLE_UPDATE=true
# FUNASR_STARTUP_UI=auto
# QWENASR_LIBRARY_PATH=/absolute/path/to/libqwen_asr.so

View File

@ -53,11 +53,11 @@ class Settings:
FUNASR_AUTOMODEL_KWARGS = {
"trust_remote_code": False,
"disable_update": True,
"disable_pbar": True,
"disable_log": True, # 禁用FunASR的tables输出
"local_files_only": True, # 强制使用本地模型,禁止联网下载
}
FUNASR_DISABLE_UPDATE: bool = True # 跳过 FunASR 启动时的联网更新检查
ASR_MODELS_CONFIG: str = str(BASE_DIR / "app/services/asr/models.json")
ASR_ENABLE_REALTIME_PUNC: bool = True # 是否启用实时标点模型(用于中间结果展示)
VAD_MODEL: str = "damo/speech_fsmn_vad_zh-cn-16k-common-pytorch"
@ -266,6 +266,10 @@ class Settings:
self.FUNASR_WORKERS = int(
os.getenv("FUNASR_WORKERS", str(self.FUNASR_WORKERS))
)
self.FUNASR_DISABLE_UPDATE = (
os.getenv("FUNASR_DISABLE_UPDATE", str(self.FUNASR_DISABLE_UPDATE)).lower()
== "true"
)
self.SPEAKER_DB_ENABLED = (
os.getenv("SPEAKER_DB_ENABLED", str(self.SPEAKER_DB_ENABLED)).lower()

View File

@ -33,10 +33,10 @@ _punc_realtime_inference_lock = threading.Lock() # 推理互斥锁,防止并
def _auto_model_common_kwargs() -> Dict[str, Any]:
"""Copy shared FunASR options and prevent callers from re-enabling update checks."""
"""Copy shared FunASR options and apply the configured update-check behavior."""
kwargs = dict(settings.FUNASR_AUTOMODEL_KWARGS)
# Keep this explicit at each AutoModel boundary: startup must not wait on PyPI access.
kwargs.pop("disable_update", None)
# Keep all AutoModel instances consistent with the environment setting.
kwargs["disable_update"] = settings.FUNASR_DISABLE_UPDATE
return kwargs
@ -65,7 +65,6 @@ def get_global_vad_model(device: str):
_global_vad_model = AutoModel(
model=resolved_vad_path,
device=resolved_device,
disable_update=True,
speech_noise_thres=0.6, # VAD 语音噪声阈值(FunASR默认0.6,设为0.7稍微严格一些,分段更碎)
**_auto_model_common_kwargs(),
)
@ -101,7 +100,6 @@ def get_global_punc_model(device: str):
_global_punc_model = AutoModel(
model=resolved_punc_path,
device=resolved_device,
disable_update=True,
**_auto_model_common_kwargs(),
)
logger.info("全局标点符号模型(离线)加载成功")
@ -136,7 +134,6 @@ def get_global_punc_realtime_model(device: str):
_global_punc_realtime_model = AutoModel(
model=resolved_punc_realtime_path,
device=resolved_device,
disable_update=True,
**_auto_model_common_kwargs(),
)
logger.info("全局标点符号模型(实时)加载成功")