{"record":{"id":"e8518c44d3a31b5b","repo":"spring-projects/spring-ai","slug":"no-speech-response-returned-for-prompt-prompt","errorCode":null,"errorMessage":"No speech response returned for prompt: + prompt","messagePattern":"No speech response returned for prompt: \\+ prompt","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"models/spring-ai-openai/src/main/java/org/springframework/ai/openai/OpenAiAudioSpeechModel.java","lineNumber":148,"sourceCode":"\n\t\tSpeechCreateParams params = buildSpeechCreateParams(mergedOptions, inputText, false);\n\n\t\tRequestOptions requestOptions = this.buildRequestOptions(mergedOptions);\n\n\t\tHttpResponse httpResponse = this.openAiClient.audio().speech().create(params, requestOptions);\n\t\tHeaders headers = httpResponse.headers();\n\n\t\tbyte[] audioBytes;\n\t\ttry (InputStream inputStream = httpResponse.body()) {\n\t\t\taudioBytes = inputStream.readAllBytes();\n\t\t}\n\t\tcatch (IOException e) {\n\t\t\tthrow new RuntimeException(\"Failed to read audio speech response\", e);\n\t\t}\n\n\t\tif (audioBytes.length == 0) {\n\t\t\tif (logger.isWarnEnabled()) {\n\t\t\t\tlogger.warn(\"No speech response returned for prompt: \" + prompt);\n\t\t\t}\n\t\t\treturn new TextToSpeechResponse(List.of(new Speech(new byte[0])));\n\t\t}\n\n\t\tSpeech speech = new Speech(audioBytes);\n\t\tOpenAiAudioSpeechResponseMetadata metadata = OpenAiAudioSpeechResponseMetadata.from(headers);\n\n\t\treturn new TextToSpeechResponse(List.of(speech), metadata);\n\t}\n\n\t@Override\n\tpublic Flux<TextToSpeechResponse> stream(TextToSpeechPrompt prompt) {\n\t\tAssert.notNull(prompt, \"Prompt must not be null\");\n\n\t\t// Lets openSpeechStream/emitNextChunk tell a deliberate cancellation\n\t\t// apart from a genuine I/O failure.\n\t\tAtomicBoolean cancelled = new AtomicBoolean(false);\n","sourceCodeStart":130,"sourceCodeEnd":166,"githubUrl":"https://github.com/spring-projects/spring-ai/blob/98a7beda4f29d80a71c5837eb4053b03a93a46f7/models/spring-ai-openai/src/main/java/org/springframework/ai/openai/OpenAiAudioSpeechModel.java#L130-L166","documentation":"Warning logged by OpenAiAudioSpeechModel.call() when the speech synthesis request produced zero audio bytes (audioBytes.length == 0). The model returns a TextToSpeechResponse containing one Speech with an empty byte array rather than throwing, so callers can silently end up with empty audio files.","triggerScenarios":"The OpenAI /audio/speech endpoint returns an empty body (read fully into a zero-length byte[]); IOException during reading is separate and thrown as RuntimeException. Triggered when the API returns 2xx with no payload or the response stream is empty.","commonSituations":"Invalid OpenAI API key or billing issues returning unusual empty responses; unsupported/invalid voice or model option values; proxies/gateways stripping response bodies; OpenAI service incidents.","solutions":["Verify OPENAI_API_KEY and billing/quota status for the audio endpoints.","Validate speech options (voice, model, speed, response format) against current OpenAI supported values.","Check the raw HTTP response via an interceptor; an error body may be collapsed into empty bytes.","Treat zero-length Speech audio as a failure in application code and retry or alert."],"exampleFix":"// before\nbyte[] audio = speechModel.call(new SpeechPrompt(text, opts)).getResult().getOutput();\nFiles.write(path, audio); // creates empty file\n// after\nif (audio == null || audio.length == 0) throw new IllegalStateException(\"OpenAI TTS returned no audio for prompt\");\nFiles.write(path, audio);","handlingStrategy":"try-catch","validationCode":"// validate options before calling\nAssert.notNull(options.getVoice(), \"voice is required\");\nAssert.hasText(prompt.getText(), \"prompt text is required\");","typeGuard":"static boolean hasAudio(SpeechPromptResult r) {\n    return r != null && r.getSpeeches() != null && r.getSpeeches().stream().anyMatch(s -> s.getAudio() != null && s.getAudio().length > 0);\n}","tryCatchPattern":"byte[] audio = speechModel.call(prompt).getResult().getOutput();\nif (audio == null || audio.length == 0) throw new IllegalStateException(\"OpenAI TTS produced no audio\");","preventionTips":["Validate OPENAI_API_KEY and billing before audio workloads","Check voice/model/speed values against current OpenAI docs","Verify file size before writing/serving generated audio"],"tags":["openai","text-to-speech","empty-response","audio"],"backgroundTag":"empty-response-body","analyzedSha":"98a7beda4f29d80a71c5837eb4053b03a93a46f7","analyzedAt":"2026-09-11T14:15:49.441Z","contentChangedAt":"2026-09-11T14:15:49.441Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}