babalae/better-genshin-impact · critical · FileNotFoundException
Silero VAD 模型文件不存在
Error message
Silero VAD 模型文件不存在
What it means
FileNotFoundException thrown in SileroVadDetector's constructor when the ONNX model file at BgiOnnxModel.SileroVad.ModalPath does not exist. ModalPath resolves via Global.Absolute(@"Assets\Model\Vad\silero_vad.onnx") — the file ships as an asset and must be present beside the executable. Missing it means the deployment is incomplete.
Source
Thrown at BetterGenshinImpact/GameTask/AutoSkip/Audio/SileroVadDetector.cs:27
internal sealed class SileroVadDetector : IDisposable
{
public const int SampleRate = 16000;
public const int FrameSampleCount = 512;
private const int StatePlaneCount = 2;
private const int StateBatchCount = 1;
private const int StateSize = 128;
private readonly InferenceSession _session;
private readonly float[] _state = new float[StatePlaneCount * StateBatchCount * StateSize];
private readonly long[] _sampleRate = [SampleRate];
public SileroVadDetector()
{
var modelPath = BgiOnnxModel.SileroVad.ModalPath;
if (!File.Exists(modelPath))
{
throw new FileNotFoundException("Silero VAD 模型文件不存在", modelPath);
}
_session = new InferenceSession(modelPath, CreateSessionOptions());
}
public void Reset()
{
Array.Clear(_state);
}
public float Predict(float[] samples)
{
if (samples.Length != FrameSampleCount)
{
throw new ArgumentException($"Silero VAD 需要 {FrameSampleCount} 个采样点", nameof(samples));
}
var inputTensor = new DenseTensor<float>(samples, [1, FrameSampleCount]);View on GitHub (pinned to a7cb36712d)
Solutions
- Re-download/re-extract the release so Assets/Model/Vad/silero_vad.onnx exists next to the executable.
- Launch the app from its own directory so Global.Absolute resolves correctly.
- Add an antivirus exclusion for the app folder (onnx models are sometimes flagged).
- Verify the file is included in the .csproj as Content with CopyToOutputDirectory.
- Run a fresh build; confirm the file appears in bin/<config>/netX.X-windows/Assets/Model/Vad/.
Example fix
// before
var modelPath = BgiOnnxModel.SileroVad.ModalPath;
if (!File.Exists(modelPath))
throw new FileNotFoundException("Silero VAD 模型文件不存在", modelPath);
// after: clear message with resolved path for diagnostics
var modelPath = BgiOnnxModel.SileroVad.ModalPath;
if (!File.Exists(modelPath))
throw new FileNotFoundException(
$"Silero VAD 模型文件不存在:{modelPath}。请确认程序目录下 Assets/Model/Vad/silero_vad.onnx 完整。", modelPath); Defensive patterns
Strategy: validation
Validate before calling
var modelPath = BgiOnnxModel.SileroVad.ModalPath;
if (!File.Exists(modelPath))
return Result.Fail($"缺少模型文件 {modelPath},语音跳过检测不可用"); Try / catch
try { vad = new SileroVadDetector(); }
catch (FileNotFoundException) { /* disable voice detection, fall back to silent skip */ } Prevention
- Validate all registered BgiOnnxModel files exist at startup and report missing ones in one summary.
- Mark model .onnx files as Content/CopyToOutputDirectory in the .csproj.
- Add the app folder to antivirus exclusions; verify assets after each publish.
When it happens
Trigger: Constructing a SileroVadDetector (via DialogueOptionVoiceDetector.Create) when Assets/Model/Vad/silero_vad.onnx was not copied to the output directory, was deleted by an antivirus, or the working directory is wrong so Global.Absolute resolves to a non-existent path.
Common situations: Build output cleaned/published without the Assets folder; running the exe from a different working directory; antivirus quarantined the .onnx; partial git checkout excluding large binary assets; extracted a release zip incompletely.
Related errors
- Unable to GetLabelByIndex: index {i} out of range {labels.Co
- 无效的推理设备
- PaddleOCR config file {modelConfigFileName} not found: {conf
- Yap字典文件不存在
- 自动钓鱼模型文件不存在
AI-assisted analysis of babalae/better-genshin-impact@a7cb36712d (2026-08-13).
Data as JSON: /api/errors/4a6e1ff4f2735f07.
Report an issue: GitHub.