{"record":{"id":"f57977c15d94b447","repo":"mudler/LocalAI","slug":"moss-tts-cpp-error-text-is-required-n","errorCode":null,"errorMessage":"[moss-tts-cpp] ERROR: text is required\\n","messagePattern":"\\[moss-tts-cpp\\] ERROR: text is required\\\\n","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/go/moss-tts-cpp/cpp/mossttscpp.cpp","lineNumber":71,"sourceCode":"        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)\n            moss_free(pcm);\n        return nullptr;\n    }\n","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/mudler/LocalAI/blob/44413a9d06bf5bc52ce088ba8ca74e5a2e8bee26/backend/go/moss-tts-cpp/cpp/mossttscpp.cpp#L53-L89","documentation":"mtl_tts() rejects the call because text is NULL or empty (model already loaded at this point). Returns nullptr. Synthesis of an empty prompt is meaningless, so the shim refuses before invoking moss_local_tts.","triggerScenarios":"Calling mtl_tts(\"\", ref, seed, ...) — e.g., an API request with an absent/blank input field serialized to an empty C string.","commonSituations":"OpenAI-compatible TTS request with missing \"input\" field; upstream text-extraction produced empty string after sanitization.","solutions":["Validate the request text is non-empty before calling the backend.","Return a 400-style error to the API client instead of attempting synthesis."],"exampleFix":"// before\nif req.Input == nil { req.Input = &[]string{}[0] }\n// after\nif strings.TrimSpace(text) == \"\" {\n    return errors.New(\"tts: input text is required\")\n}","handlingStrategy":"validation","validationCode":"if strings.TrimSpace(text) == \"\" {\n    return nil, errors.New(\"tts: input text is required\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Reject empty/whitespace input at the API boundary with a 400.","Do not default missing input to an empty string."],"tags":["moss-tts-cpp","tts","argument-validation"],"backgroundTag":null,"analyzedSha":"44413a9d06bf5bc52ce088ba8ca74e5a2e8bee26","analyzedAt":"2026-08-15T10:13:50.291Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}