Class OpenAiAudioSpeechModel

java.lang.Object
org.springframework.ai.openai.OpenAiAudioSpeechModel
All Implemented Interfaces:
Model<SpeechPrompt,SpeechResponse>, StreamingModel<SpeechPrompt,SpeechResponse>, SpeechModel, StreamingSpeechModel

public class OpenAiAudioSpeechModel extends Object implements 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 Details

    • OpenAiAudioSpeechModel

      public OpenAiAudioSpeechModel(OpenAiAudioApi audioApi)
      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

      public OpenAiAudioSpeechModel(OpenAiAudioApi audioApi, OpenAiAudioSpeechOptions options)
      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

      public byte[] call(String text)
      Description copied from interface: SpeechModel
      Generates spoken audio from the provided text message.
      Specified by:
      call in interface SpeechModel
      Parameters:
      text - the text message to be converted to audio
      Returns:
      the resulting audio bytes
    • call

      public SpeechResponse call(SpeechPrompt speechPrompt)
      Description copied from interface: SpeechModel
      Sends a speech request to the OpenAI TTS API and returns the resulting speech response.
      Specified by:
      call in interface Model<SpeechPrompt,SpeechResponse>
      Specified by:
      call in interface SpeechModel
      Parameters:
      speechPrompt - the speech prompt containing the input text and other parameters
      Returns:
      the speech response containing the generated audio
    • stream

      public reactor.core.publisher.Flux<SpeechResponse> stream(SpeechPrompt speechPrompt)
      Streams the audio response for the given speech prompt.
      Specified by:
      stream in interface StreamingModel<SpeechPrompt,SpeechResponse>
      Specified by:
      stream in interface StreamingSpeechModel
      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.