{"record":{"id":"64d13868b84e9fa6","repo":"mudler/LocalAI","slug":"error-failed-to-detect-speech-n","errorCode":null,"errorMessage":"error: failed to detect speech\\n","messagePattern":"error: failed to detect speech\\\\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/go/crispasr/cpp/crispasr_shim.cpp","lineNumber":200,"sourceCode":"  struct whisper_vad_context_params vcparams =\n      whisper_vad_default_context_params();\n\n  // XXX: Overridden to false in upstream due to performance?\n  // vcparams.use_gpu = true;\n\n  vctx = whisper_vad_init_from_file_with_params(model_path, vcparams);\n  if (vctx == nullptr) {\n    fprintf(stderr, \"error: Failed to init model as VAD\\n\");\n    return 1;\n  }\n\n  return 0;\n}\n\nint vad(float pcmf32[], size_t pcmf32_len, float **segs_out,\n        size_t *segs_out_len) {\n  if (!whisper_vad_detect_speech(vctx, pcmf32, pcmf32_len)) {\n    fprintf(stderr, \"error: failed to detect speech\\n\");\n    return 1;\n  }\n\n  struct whisper_vad_params params = whisper_vad_default_params();\n  struct whisper_vad_segments *segs =\n      whisper_vad_segments_from_probs(vctx, params);\n  size_t segn = whisper_vad_segments_n_segments(segs);\n\n  // fprintf(stderr, \"Got segments %zd\\n\", segn);\n\n  flat_segs.clear();\n\n  for (int i = 0; i < segn; i++) {\n    flat_segs.push_back(whisper_vad_segments_get_segment_t0(segs, i));\n    flat_segs.push_back(whisper_vad_segments_get_segment_t1(segs, i));\n  }\n\n  // fprintf(stderr, \"setting out variables: %p=%p -> %p, %p=%zx -> %zx\\n\",","sourceCodeStart":182,"sourceCodeEnd":218,"githubUrl":"https://github.com/mudler/LocalAI/blob/44413a9d06bf5bc52ce088ba8ca74e5a2e8bee26/backend/go/crispasr/cpp/crispasr_shim.cpp#L182-L218","documentation":"vad() failed because whisper_vad_detect_speech() returned false on the loaded VAD context and PCM input. This is an inference-time failure, distinct from load failures: the VAD context exists but probability computation did not complete. Returns 1 without touching segs_out.","triggerScenarios":"Calling vad(pcmf32, len) with pcmf32_len == 0, an extremely short buffer, NaN/garbage PCM data, or when the VAD context (vctx) is NULL because load_model_vad was never called or failed — detect_speech then fails immediately.","commonSituations":"Calling VAD before a successful load_model_vad (ordering bug in the caller); feeding an empty audio frame from an upstream silence-gate; feeding non-float or wrongly-scaled PCM.","solutions":["Ensure load_model_vad succeeded (returned 0) before any vad() call.","Validate pcmf32_len > 0 and that the buffer holds finite float samples at whisper's expected scale.","Check ggml logs for compute-backend errors during detection.","If audio is very short, pad or skip VAD for buffers under the model's minimum window."],"exampleFix":"// before\nvad(pcm, 0, &segs, &n); // empty frame\n// after: skip VAD on empty frames\nif (n_pcm == 0) { *segs_out = NULL; *segs_out_len = 0; return 0; }\nvad(pcm, n_pcm, &segs, &n);","handlingStrategy":"validation","validationCode":"if vctx == nil /* load failed or not called */ {\n    return errors.New(\"VAD not loaded\")\n}\nif len(pcm) == 0 {\n    return nil, 0, nil // nothing to do\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pair vad() with a prior successful load_model_vad().","Skip VAD for empty or below-minimum-window audio frames instead of calling it."],"tags":["crispasr","vad","inference","input-validation"],"backgroundTag":null,"analyzedSha":"44413a9d06bf5bc52ce088ba8ca74e5a2e8bee26","analyzedAt":"2026-08-15T10:13:50.291Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}