{"record":{"id":"641c06e420c1176a","repo":"mudler/LocalAI","slug":"moss-tts-cpp-error-moss-local-tts-failed-n","errorCode":null,"errorMessage":"[moss-tts-cpp] ERROR: moss_local_tts failed\\n","messagePattern":"\\[moss-tts-cpp\\] ERROR: moss_local_tts failed\\\\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/go/moss-tts-cpp/cpp/mossttscpp.cpp","lineNumber":84,"sourceCode":"    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)\n            moss_free(pcm);\n        return nullptr;\n    }\n\n    // Copy into a plain malloc buffer the Go side frees via mtl_pcm_free, then\n    // release the engine-owned buffer with moss_free (mirrors qwen3-tts-cpp,\n    // keeping ownership on the C runtime's malloc/free).\n    size_t bytes = (size_t)n * sizeof(float);\n    float *buf = (float *)malloc(bytes);\n    if (!buf) {\n        fprintf(stderr, \"[moss-tts-cpp] ERROR: malloc(%zu) failed\\n\", bytes);\n        moss_free(pcm);\n        return nullptr;\n    }\n    memcpy(buf, pcm, bytes);\n    moss_free(pcm);\n","sourceCodeStart":66,"sourceCodeEnd":102,"githubUrl":"https://github.com/mudler/LocalAI/blob/44413a9d06bf5bc52ce088ba8ca74e5a2e8bee26/backend/go/moss-tts-cpp/cpp/mossttscpp.cpp#L66-L102","documentation":"moss_local_tts() ran but returned NULL or a non-positive sample count (n <= 0). The engine started synthesis and failed mid-run, or produced zero audio. The shim frees any partial engine buffer and returns nullptr. Distinct from 172/173: inputs were valid and the model was loaded; this is an inference-time failure.","triggerScenarios":"Text the engine cannot vocalize (unsupported script/language), a reference_wav that fails to load or is incompatible for voice cloning, numerical/backend faults during decoding, or seed-dependent generation collapsing to zero length.","commonSituations":"Cloning with a corrupt or wrong-format reference WAV; text entirely in a script Moss TTS does not support; GPU backend numerical issues; very long text overflowing engine limits.","solutions":["Retry once without the reference_wav (plain synthesis) to isolate the cloning branch.","Inspect engine logs above the error for the failing stage (tokenization vs. decode vs. codec).","Shorten or sanitize the input text; confirm the reference WAV is a valid PCM file the engine supports.","Try a different seed — degenerate zero-length output can be seed-dependent."],"exampleFix":"// before: only clone path\npcm := mtlTTS(text, refWav, seed)\n// after: fall back to no-clone synthesis\npcm := mtlTTS(text, refWav, seed)\nif pcm == nil { pcm = mtlTTS(text, \"\", seed) }","handlingStrategy":"fallback","validationCode":"if refWav != \"\" {\n    if _, err := os.Stat(refWav); err != nil {\n        refWav = \"\" // drop clone reference rather than fail synthesis\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate reference WAV exists and is a supported PCM format before cloning.","Retry without the reference (plain synthesis) when the clone branch fails.","Vary the seed on retry to avoid degenerate zero-length output."],"tags":["moss-tts-cpp","tts","inference","voice-cloning"],"backgroundTag":null,"analyzedSha":"44413a9d06bf5bc52ce088ba8ca74e5a2e8bee26","analyzedAt":"2026-08-15T10:13:50.291Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}