本帖最后由 etkane 于 2026-7-5 20:29 编辑
这个有点难度,而且需要hf的权限(语音按人分离等功能),不会申请的话有点困难。
采用wisper(large V3)+ollama+qwen3:8b(全本地化模型)
代码片段:(分项链接带源码)
[Python] 纯文本查看 复制代码 def load_models():
global whisper_model, diarize_model, align_models
try:
update_server_state(status_text="正在加载语音识别模型...", loading_progress=10)
import whisperx
from whisperx.diarize import DiarizationPipeline
device = "cuda"; compute_type = "float16"
whisper_model = whisperx.load_model("large-v3", device, compute_type=compute_type)
update_server_state(status_text="正在加载说话人分离模型...", loading_progress=50)
diarize_model = DiarizationPipeline(token=os.environ.get("HF_TOKEN",""), device=device)
align_models = (None, None)
update_server_state(models_loaded=True, status_text="模型就绪", loading_progress=100)
print("模型加载完成。")
except Exception as e:
update_server_state(status_text=f"模型加载失败:{e}", loading_progress=0)
@asynccontextmanager
async def lifespan(app: FastAPI):
global app_event_loop
app_event_loop = asyncio.get_running_loop()
threading.Thread(target=load_models, daemon=True).start()
yield
torch.cuda.empty_cache()
app = FastAPI(lifespan=lifespan)
通过网盘分享的文件:会议纪要助手-wisper版本
链接: https://pan.baidu.com/s/1PIu-qm38JQAztKZKnznBnw?pwd=52pj 提取码: 52pj
--来自百度网盘超级会员v8的分享 |