SpeechPrompt packages text for speech synthesis and can carry optional generation settings. Passing it to SpeechModel.call() returns a SpeechResponse whose output contains the generated audio bytes. section 8.1.2
Use SpeechPrompt when speech generation requires explicit control over:
- The voice, such as Nova instead of the default Alloy. section 8.1.2
- The audio model, including tts-1 or tts-1-hd. section 8.1.2
- The response format, such as AAC. section 8.1.2
Basic prompt-based synthesis
Create a SpeechPrompt from the text to speak, call the SpeechModel, extract the response output, and wrap the resulting bytes as a Resource for an HTTP response. section 8.1.2
public Resource textToSpeech(String text) {
SpeechPrompt speechPrompt = new SpeechPrompt(text);
SpeechResponse response = speechModel.call(speechPrompt);
byte[] speechBytes = response.getResult().getOutput();
return new ByteArrayResource(speechBytes);
}
Shows the complete Java flow from SpeechPrompt construction to audio-byte extraction. section 8.1.2
