mirror of
https://github.com/JefferyHcool/BiliNote.git
synced 2026-05-14 20:08:42 +08:00
桌面端用户首次跑视频时挂在 fast-whisper 模型下载(默认 medium ~1.5GB), 两处改动: 1. backend/app/services/transcriber_config_manager.py: 默认 whisper_model_size 从 'medium' (~1.5GB) → 'tiny' (~75MB)。 新装用户没主动设置时不再被首次下载卡住;想要更高精度的用户去配置页主动切。 2. BillNote_frontend/src/pages/SettingPage/transcriber.tsx: handleSave 在保存前判断:选了 fast-whisper / mlx-whisper 且当前 size 在 modelStatuses 里既未下载也不在下载中 → window.confirm 弹一个体积提示, 推荐改用 Groq / 必剪 / 快手 等在线引擎;用户取消则不保存。 不改业务逻辑;零回归风险(已有用户 transcriber.json 里写了什么就还是什么)。 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
64 lines
2.1 KiB
Python
64 lines
2.1 KiB
Python
import json
|
||
import os
|
||
from pathlib import Path
|
||
from typing import Optional, Dict, Any
|
||
|
||
|
||
class TranscriberConfigManager:
|
||
"""管理转写器配置,存储在 JSON 文件中,支持前端动态修改。"""
|
||
|
||
def __init__(self, filepath: str = "config/transcriber.json"):
|
||
self.path = Path(filepath)
|
||
self.path.parent.mkdir(parents=True, exist_ok=True)
|
||
|
||
def _read(self) -> Dict[str, Any]:
|
||
if not self.path.exists():
|
||
return {}
|
||
try:
|
||
with self.path.open("r", encoding="utf-8") as f:
|
||
return json.load(f)
|
||
except Exception:
|
||
return {}
|
||
|
||
def _write(self, data: Dict[str, Any]):
|
||
with self.path.open("w", encoding="utf-8") as f:
|
||
json.dump(data, f, ensure_ascii=False, indent=2)
|
||
|
||
def get_config(self) -> Dict[str, Any]:
|
||
"""获取当前转写器配置,fallback 到环境变量默认值。
|
||
|
||
whisper 默认 size 从 'medium' (~1.5GB) 改为 'tiny' (~75MB):
|
||
新装用户没主动设置时不应该被首次下载卡住。想要更高精度可在「音频转写配置」
|
||
页主动切换。
|
||
"""
|
||
data = self._read()
|
||
return {
|
||
"transcriber_type": data.get(
|
||
"transcriber_type",
|
||
os.getenv("TRANSCRIBER_TYPE", "fast-whisper"),
|
||
),
|
||
"whisper_model_size": data.get(
|
||
"whisper_model_size",
|
||
os.getenv("WHISPER_MODEL_SIZE", "tiny"),
|
||
),
|
||
}
|
||
|
||
def update_config(
|
||
self,
|
||
transcriber_type: str,
|
||
whisper_model_size: Optional[str] = None,
|
||
) -> Dict[str, Any]:
|
||
"""更新转写器配置并持久化。"""
|
||
data = self._read()
|
||
data["transcriber_type"] = transcriber_type
|
||
if whisper_model_size is not None:
|
||
data["whisper_model_size"] = whisper_model_size
|
||
self._write(data)
|
||
return self.get_config()
|
||
|
||
def get_transcriber_type(self) -> str:
|
||
return self.get_config()["transcriber_type"]
|
||
|
||
def get_whisper_model_size(self) -> str:
|
||
return self.get_config()["whisper_model_size"]
|