mudler/LocalAI · error

[moss-tts-cpp] ERROR: model not loaded\n

Error message

[moss-tts-cpp] ERROR: model not loaded\n

What it means

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.

Source

Thrown at backend/go/moss-tts-cpp/cpp/mossttscpp.cpp:67

            local_path, codec_path, tokenizer_path);

    g_local = moss_local_load(local_path, codec_path, tokenizer_path);
    if (!g_local) {
        fprintf(stderr, "[moss-tts-cpp] FATAL: moss_local_load failed\n");
        return 4;
    }
    fprintf(stderr, "[moss-tts-cpp] Model loaded (%s)\n", moss_tts_version());
    return 0;
}

float *mtl_tts(const char *text, const char *reference_wav, int seed,
               int *out_n, int *out_sr) {
    if (out_n)
        *out_n = 0;
    if (out_sr)
        *out_sr = 0;
    if (!g_local) {
        fprintf(stderr, "[moss-tts-cpp] ERROR: model not loaded\n");
        return nullptr;
    }
    if (!text || text[0] == '\0') {
        fprintf(stderr, "[moss-tts-cpp] ERROR: text is required\n");
        return nullptr;
    }

    // An empty reference path means "no cloning": pass NULL so the engine skips
    // the clone branch rather than trying to open "".
    const char *ref = (reference_wav && reference_wav[0] != '\0')
                          ? reference_wav
                          : nullptr;

    int n = 0, sr = 0;
    float *pcm = moss_local_tts(g_local, text, ref, seed, &n, &sr);
    if (!pcm || n <= 0) {
        fprintf(stderr, "[moss-tts-cpp] ERROR: moss_local_tts failed\n");
        if (pcm)

View on GitHub (pinned to 44413a9d06)

Solutions

  1. Ensure mtl_load returned 0 before exposing the TTS endpoint.
  2. Treat any non-zero mtl_load return as fatal for the backend instance and re-run the load.

Example fix

// before: ignoring load failure
C.mtl_load(m, c, t)
pcm := C.mtl_tts(...)
// after
if rc := C.mtl_load(m, c, t); rc != 0 {
    return fmt.Errorf("moss-tts-cpp load failed: %d", rc)
}
Defensive patterns

Strategy: validation

Validate before calling

mu.Lock(); loaded := gLocalOK; mu.Unlock()
if !loaded {
    return nil, errors.New("moss-tts-cpp: model not loaded; call mtl_load first")
}

Prevention

When it happens

Trigger: 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.

Common situations: Go service starts serving requests before model load completes; load failed earlier and the error code was ignored; retry logic skips the load step.

Related errors


AI-assisted analysis of mudler/LocalAI@44413a9d06 (2026-08-15). Data as JSON: /api/errors/773bb094237a014c. Report an issue: GitHub.