{"record":{"id":"773bb094237a014c","repo":"mudler/LocalAI","slug":"moss-tts-cpp-error-model-not-loaded-n","errorCode":null,"errorMessage":"[moss-tts-cpp] ERROR: model not loaded\\n","messagePattern":"\\[moss-tts-cpp\\] ERROR: model not loaded\\\\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/go/moss-tts-cpp/cpp/mossttscpp.cpp","lineNumber":67,"sourceCode":"            local_path, codec_path, tokenizer_path);\n\n    g_local = moss_local_load(local_path, codec_path, tokenizer_path);\n    if (!g_local) {\n        fprintf(stderr, \"[moss-tts-cpp] FATAL: moss_local_load failed\\n\");\n        return 4;\n    }\n    fprintf(stderr, \"[moss-tts-cpp] Model loaded (%s)\\n\", moss_tts_version());\n    return 0;\n}\n\nfloat *mtl_tts(const char *text, const char *reference_wav, int seed,\n               int *out_n, int *out_sr) {\n    if (out_n)\n        *out_n = 0;\n    if (out_sr)\n        *out_sr = 0;\n    if (!g_local) {\n        fprintf(stderr, \"[moss-tts-cpp] ERROR: model not loaded\\n\");\n        return nullptr;\n    }\n    if (!text || text[0] == '\\0') {\n        fprintf(stderr, \"[moss-tts-cpp] ERROR: text is required\\n\");\n        return nullptr;\n    }\n\n    // An empty reference path means \"no cloning\": pass NULL so the engine skips\n    // the clone branch rather than trying to open \"\".\n    const char *ref = (reference_wav && reference_wav[0] != '\\0')\n                          ? reference_wav\n                          : nullptr;\n\n    int n = 0, sr = 0;\n    float *pcm = moss_local_tts(g_local, text, ref, seed, &n, &sr);\n    if (!pcm || n <= 0) {\n        fprintf(stderr, \"[moss-tts-cpp] ERROR: moss_local_tts failed\\n\");\n        if (pcm)","sourceCodeStart":49,"sourceCodeEnd":85,"githubUrl":"https://github.com/mudler/LocalAI/blob/44413a9d06bf5bc52ce088ba8ca74e5a2e8bee26/backend/go/moss-tts-cpp/cpp/mossttscpp.cpp#L49-L85","documentation":"mtl_tts() was called while g_local is NULL — no model was loaded (mtl_load never succeeded or was never called). The shim returns nullptr with *out_n and *out_sr already zeroed. This is a lifecycle/ordering error, not a synthesis failure.","triggerScenarios":"Invoking mtl_tts before mtl_load, or after mtl_load returned non-zero (e.g., after error 168-171), or after the model was freed by a previous unload.","commonSituations":"Go service starts serving requests before model load completes; load failed earlier and the error code was ignored; retry logic skips the load step.","solutions":["Ensure mtl_load returned 0 before exposing the TTS endpoint.","Treat any non-zero mtl_load return as fatal for the backend instance and re-run the load."],"exampleFix":"// before: ignoring load failure\nC.mtl_load(m, c, t)\npcm := C.mtl_tts(...)\n// after\nif rc := C.mtl_load(m, c, t); rc != 0 {\n    return fmt.Errorf(\"moss-tts-cpp load failed: %d\", rc)\n}","handlingStrategy":"validation","validationCode":"mu.Lock(); loaded := gLocalOK; mu.Unlock()\nif !loaded {\n    return nil, errors.New(\"moss-tts-cpp: model not loaded; call mtl_load first\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Track load state on the Go side and gate the TTS handler on it.","Treat non-zero mtl_load returns as startup failures; do not serve requests."],"tags":["moss-tts-cpp","tts","lifecycle","ordering"],"backgroundTag":null,"analyzedSha":"44413a9d06bf5bc52ce088ba8ca74e5a2e8bee26","analyzedAt":"2026-08-15T10:13:50.291Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}