Package org.springframework.ai.openai
Class OpenAiAudioSpeechModel
java.lang.Object
org.springframework.ai.openai.OpenAiAudioSpeechModel
- All Implemented Interfaces:
Model<SpeechPrompt,
,SpeechResponse> StreamingModel<SpeechPrompt,
,SpeechResponse> SpeechModel
,StreamingSpeechModel
OpenAI audio speech client implementation for backed by
OpenAiAudioApi
.- Since:
- 1.0.0-M1
- Author:
- Ahmed Yousri, Hyunjoon Choi, Thomas Vitale
- See Also:
-
Constructor Summary
ConstructorDescriptionOpenAiAudioSpeechModel
(OpenAiAudioApi audioApi) Initializes a new instance of the OpenAiAudioSpeechModel class with the provided OpenAiAudioApi.OpenAiAudioSpeechModel
(OpenAiAudioApi audioApi, OpenAiAudioSpeechOptions options) Initializes a new instance of the OpenAiAudioSpeechModel class with the provided OpenAiAudioApi and options.OpenAiAudioSpeechModel
(OpenAiAudioApi audioApi, OpenAiAudioSpeechOptions options, org.springframework.retry.support.RetryTemplate retryTemplate) Initializes a new instance of the OpenAiAudioSpeechModel class with the provided OpenAiAudioApi and options. -
Method Summary
Modifier and TypeMethodDescriptionbyte[]
Generates spoken audio from the provided text message.call
(SpeechPrompt speechPrompt) Sends a speech request to the OpenAI TTS API and returns the resulting speech response.reactor.core.publisher.Flux<SpeechResponse>
stream
(SpeechPrompt speechPrompt) Streams the audio response for the given speech prompt.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.springframework.ai.openai.audio.speech.StreamingSpeechModel
stream
-
Constructor Details
-
OpenAiAudioSpeechModel
Initializes a new instance of the OpenAiAudioSpeechModel class with the provided OpenAiAudioApi. It uses the model tts-1, response format mp3, voice alloy, and the default speed of 1.0.- Parameters:
audioApi
- The OpenAiAudioApi to use for speech synthesis.
-
OpenAiAudioSpeechModel
Initializes a new instance of the OpenAiAudioSpeechModel class with the provided OpenAiAudioApi and options.- Parameters:
audioApi
- The OpenAiAudioApi to use for speech synthesis.options
- The OpenAiAudioSpeechOptions containing the speech synthesis options.
-
OpenAiAudioSpeechModel
public OpenAiAudioSpeechModel(OpenAiAudioApi audioApi, OpenAiAudioSpeechOptions options, org.springframework.retry.support.RetryTemplate retryTemplate) Initializes a new instance of the OpenAiAudioSpeechModel class with the provided OpenAiAudioApi and options.- Parameters:
audioApi
- The OpenAiAudioApi to use for speech synthesis.options
- The OpenAiAudioSpeechOptions containing the speech synthesis options.retryTemplate
- The retry template.
-
-
Method Details
-
call
Description copied from interface:SpeechModel
Generates spoken audio from the provided text message.- Specified by:
call
in interfaceSpeechModel
- Parameters:
text
- the text message to be converted to audio- Returns:
- the resulting audio bytes
-
call
Description copied from interface:SpeechModel
Sends a speech request to the OpenAI TTS API and returns the resulting speech response.- Specified by:
call
in interfaceModel<SpeechPrompt,
SpeechResponse> - Specified by:
call
in interfaceSpeechModel
- Parameters:
speechPrompt
- the speech prompt containing the input text and other parameters- Returns:
- the speech response containing the generated audio
-
stream
Streams the audio response for the given speech prompt.- Specified by:
stream
in interfaceStreamingModel<SpeechPrompt,
SpeechResponse> - Specified by:
stream
in interfaceStreamingSpeechModel
- Parameters:
speechPrompt
- The speech prompt containing the text and options for speech synthesis.- Returns:
- A Flux of SpeechResponse objects containing the streamed audio and metadata.
-