一、开始常规编译
# 1. 进入 whisper.cpp 源代码目录
cd path\to\whisper.cpp
# 2. 创建一个专门的构建目录,并进入
mkdir build && cd build
# 3. 使用 CMake 配置项目,生成 MSVC 解决方案文件
cmake .. -A x64
# 4. 开始编译,生成库文件和示例程序(例如 whisper-cli.exe)
cmake --build . --config Release
二、编译带SDL2支持的whisper.cpp
地址下载SDL2,版本要是:2.30.8-VC
https://github.com/libsdl-org/SDL/tree/release-3.4.10
cd E:\digitalHuman\libs\whisper.cpp\build
# 清理之前的缓存(重要!)
Remove-Item * -Recurse -Force
# 关键:使用 -DSDL2_DIR 指向包含 sdl2-config.cmake 的目录
cmake .. -A x64 -DWHISPER_SDL2=ON -DSDL2_DIR=E:\digitalHuman\libs\SDL2-devel-2.30.8-VC\SDL2-2.30.8\cmake
编译成功后,所有生成的文件(包括静态库whisper.lib和ggml.lib)都会位于 build\bin\Release 和 build\src\Release目录下
三、下载模型:
先到路径:whisper.cpp\models
./download-ggml-model.cmd base
cd E:\digitalHuman\libs\whisper.cpp
.\models\download-ggml-model.cmd small # 约 488 MB
# 或
.\models\download-ggml-model.cmd medium # 约 1.5 GB
四、在PowerShell中执行指令
.\whisper-stream.exe -m E:\digitalHuman\libs\whisper.cpp\models\ggml-base.bin -t 4 --step 300 --length 6000 -l zh -vth 0.6
增加 -vth 参数,让模型只在语音能量较高时识别:
--length 5000 --step 500 更长的窗口(5 秒)可以提供更多上下文,帮助模型纠正错误。
.\whisper-stream.exe -m E:\digitalHuman\libs\whisper.cpp\models\ggml-medium.bin -t 4 --step 500 --length 3000 -l zh
.\whisper-stream.exe -m E:\digitalHuman\libs\whisper.cpp\models\ggml-base.bin -t 4 --step 500 --length 3000 -l zh
五、在 PowerShell 中设置输出编码
先执行[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
再执行指令