{"record":{"id":"263d55378f4db0db","repo":"xtekky/gpt4free","slug":"prompt-is-empty-263d55","errorCode":null,"errorMessage":"Prompt is empty.","messagePattern":"Prompt is empty\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"g4f/Provider/audio/gTTS.py","lineNumber":66,"sourceCode":"    default_tld = \"com\"\n    default_format = \"mp3\"\n\n    default_model = \"en-US\"\n    models = list(models.keys())\n    audio_models = models\n\n    @classmethod\n    async def create_async_generator(\n        cls,\n        model: str,\n        messages: Messages,\n        prompt: str = None,\n        audio: dict = {},\n        **kwargs,\n    ) -> AsyncResult:\n        prompt = get_last_message(messages, prompt)\n        if not prompt:\n            raise ValueError(\"Prompt is empty.\")\n        format = audio.get(\"format\", cls.default_format)\n        filename = get_filename([cls.model_id], prompt, f\".{format}\", prompt)\n        target_path = os.path.join(get_media_dir(), filename)\n        ensure_media_dir()\n\n        if \"language\" in audio:\n            model = (\n                locals[audio[\"language\"]][0] if audio[\"language\"] in locals else model\n            )\n\n        gTTS_Service(\n            prompt,\n            **{\n                \"lang\": audio.get(\"language\", cls.default_language),\n                \"tld\": audio.get(\"tld\", cls.default_tld),\n                \"slow\": audio.get(\"slow\", False),\n                **models.get(model, {}),\n            },","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/xtekky/gpt4free/blob/973504e1770928ed5fb82f43da528f441ad9ddc3/g4f/Provider/audio/gTTS.py#L48-L84","documentation":"ValueError from gTTS.create_async_generator when get_last_message(messages, prompt) yields empty text. Google TTS needs the string to vocalize; with neither a non-empty message nor prompt the call aborts before constructing the output file.","triggerScenarios":"Audio request through gTTS with an empty messages list and no prompt, or all message contents empty.","commonSituations":"Empty user input forwarded to speech; upstream text-generation step returned '' and the result is piped straight into TTS.","solutions":["Pass the text explicitly via prompt='...'","Guarantee the last message has non-empty content","Add a guard in the pipeline: skip TTS when the text is blank"],"exampleFix":"# before\nawait client.speech.create(model='gTTS', text=user_input)  # user_input == ''\n\n# after\nif user_input.strip():\n    await client.speech.create(model='gTTS', text=user_input)","handlingStrategy":"validation","validationCode":"text = (prompt or '').strip() or (messages[-1]['content'] if messages else '')\nif not text:\n    return  # nothing to speak; skip gTTS call","typeGuard":null,"tryCatchPattern":"except ValueError as e:\n    if 'Prompt is empty' in str(e):\n        log.warning('gTTS skipped: empty input'); return None","preventionTips":["Check .strip() on text before TTS — whitespace-only also triggers this","Make empty input a no-op in speech pipelines instead of an error"],"tags":["gtts","tts","validation","empty-input"],"backgroundTag":null,"analyzedSha":"973504e1770928ed5fb82f43da528f441ad9ddc3","analyzedAt":"2026-08-14T23:45:32.408Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}