{"record":{"id":"08ff993856e9aca5","repo":"mudler/LocalAI","slug":"omnivoice-cpp-error-model-not-loaded-n","errorCode":null,"errorMessage":"[omnivoice-cpp] ERROR: model not loaded\\n","messagePattern":"\\[omnivoice-cpp\\] ERROR: model not loaded\\\\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/go/omnivoice-cpp/cpp/gomnivoicecpp.cpp","lineNumber":88,"sourceCode":"        tp->instruct = instruct;\n    if (ref_samples && ref_n > 0) {\n        tp->ref_audio_24k = ref_samples;\n        tp->ref_n_samples = ref_n;\n        if (ref_text && ref_text[0] != '\\0')\n            tp->ref_text = ref_text;\n        tp->denoise = denoise != 0;\n    }\n    if (seed >= 0)\n        tp->mg_seed = (uint64_t)seed;\n}\n\nfloat *omni_tts(const char *text, const char *lang, const char *instruct,\n                const float *ref_samples, int ref_n, const char *ref_text,\n                long long seed, int denoise, int *out_n) {\n    if (out_n)\n        *out_n = 0;\n    if (!g_ctx) {\n        fprintf(stderr, \"[omnivoice-cpp] ERROR: model not loaded\\n\");\n        return nullptr;\n    }\n    if (!text || text[0] == '\\0') {\n        fprintf(stderr, \"[omnivoice-cpp] ERROR: text is required\\n\");\n        return nullptr; // omni_tts: out_n already 0\n    }\n    ov_tts_params tp;\n    fill_params(&tp, text, lang, instruct, ref_samples, ref_n, ref_text, seed,\n                denoise);\n\n    ov_audio out = {0};\n    enum ov_status rc = ov_synthesize(g_ctx, &tp, &out);\n    if (rc != OV_STATUS_OK || out.n_samples <= 0 || !out.samples) {\n        fprintf(stderr, \"[omnivoice-cpp] ERROR: synthesize failed (rc=%d): %s\\n\",\n                (int)rc, ov_last_error());\n        ov_audio_free(&out);\n        return nullptr;\n    }","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/mudler/LocalAI/blob/44413a9d06bf5bc52ce088ba8ca74e5a2e8bee26/backend/go/omnivoice-cpp/cpp/gomnivoicecpp.cpp#L70-L106","documentation":"omni_tts() was called while g_ctx is NULL — no model loaded (omni_load never succeeded or never called). The shim zeroes *out_n first and returns nullptr; a later comment in the file confirms out_n stays 0. Lifecycle/ordering error identical in shape to moss-tts error 172.","triggerScenarios":"Calling omni_tts before a successful omni_load, or after omni_load returned 1/2/3 (errors 176-178) and the return code was ignored.","commonSituations":"Serving requests before the model finishes loading; load failure swallowed by the caller; backend restart raced with an in-flight request.","solutions":["Gate the TTS endpoint on omni_load returning 0.","On load failure, fail backend startup loudly instead of continuing to serve."],"exampleFix":"// before\nC.omni_load(m, c, 0, 0)\naudio := C.omni_tts(...)\n// after\nif rc := C.omni_load(m, c, 0, 0); rc != 0 {\n    return fmt.Errorf(\"omnivoice-cpp load failed: %d\", rc)\n}\naudio := C.omni_tts(...)","handlingStrategy":"validation","validationCode":"mu.Lock(); loaded := gCtxOK; mu.Unlock()\nif !loaded {\n    return nil, errors.New(\"omnivoice-cpp: model not loaded; call omni_load first\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Gate omni_tts on omni_load returning 0.","Check out_n == 0 && ptr == nil as the not-loaded / failed signature and return a clear error."],"tags":["omnivoice-cpp","tts","lifecycle","ordering"],"backgroundTag":null,"analyzedSha":"44413a9d06bf5bc52ce088ba8ca74e5a2e8bee26","analyzedAt":"2026-08-15T10:13:50.291Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}