feat: Docker 构建预置 ASR 模型,支持离线使用

- Dockerfile 构建时预下载 faster-whisper 模型到镜像
- docker-compose 增加 ASR_MODEL_CACHE_DIR 环境变量
- asr_service 支持从缓存目录加载本地模型,无需运行时联网下载

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
iammm0
2026-02-10 15:08:00 +08:00
parent 80b3981188
commit 0b7bd37d5d
3 changed files with 13 additions and 1 deletions

View File

@@ -16,6 +16,8 @@ logger = logging.getLogger(__name__)
ASR_MODEL_SIZE = os.getenv("ASR_MODEL_SIZE", "small")
ASR_DEVICE = os.getenv("ASR_DEVICE", "auto") # auto, cpu, cuda
ASR_COMPUTE_TYPE = os.getenv("ASR_COMPUTE_TYPE", "auto") # auto, int8, float16, float32
# 镜像内预置模型目录,设置后直接使用本地模型不联网下载(与 Dockerfile 中 download_root 一致)
ASR_MODEL_CACHE_DIR = os.getenv("ASR_MODEL_CACHE_DIR")
class ASRService:
@@ -58,10 +60,14 @@ class ASRService:
else:
compute_type = "int8" # CPU 使用 int8 量化,速度更快
download_root = ASR_MODEL_CACHE_DIR if ASR_MODEL_CACHE_DIR else None
local_files_only = bool(ASR_MODEL_CACHE_DIR)
self.model = WhisperModel(
ASR_MODEL_SIZE,
device=device,
compute_type=compute_type
compute_type=compute_type,
download_root=download_root,
local_files_only=local_files_only,
)
self._model_loaded = True