Class OpenAiAudioSpeechModel

java.lang.Object
org.springframework.ai.openai.OpenAiAudioSpeechModel
All Implemented Interfaces:
org.springframework.ai.audio.tts.StreamingTextToSpeechModel, org.springframework.ai.audio.tts.TextToSpeechModel, org.springframework.ai.model.Model<org.springframework.ai.audio.tts.TextToSpeechPrompt, org.springframework.ai.audio.tts.TextToSpeechResponse>, org.springframework.ai.model.StreamingModel<org.springframework.ai.audio.tts.TextToSpeechPrompt, org.springframework.ai.audio.tts.TextToSpeechResponse>

public class OpenAiAudioSpeechModel extends Object implements org.springframework.ai.audio.tts.TextToSpeechModel
OpenAI audio speech client implementation for backed by OpenAiAudioApi.
Since:
1.0.0-M1
Author:
Ahmed Yousri, Hyunjoon Choi, Thomas Vitale, Jonghoon Park
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    Initializes a new instance of the OpenAiAudioSpeechModel class with the provided OpenAiAudioApi.
    Initializes a new instance of the OpenAiAudioSpeechModel class with the provided OpenAiAudioApi and options.
    OpenAiAudioSpeechModel(OpenAiAudioApi audioApi, OpenAiAudioSpeechOptions options, org.springframework.core.retry.RetryTemplate retryTemplate)
    Initializes a new instance of the OpenAiAudioSpeechModel class with the provided OpenAiAudioApi and options.
  • Method Summary

    Modifier and Type
    Method
    Description
    byte[]
    call(String text)
     
    org.springframework.ai.audio.tts.TextToSpeechResponse
    call(org.springframework.ai.audio.tts.TextToSpeechPrompt prompt)
     
    org.springframework.ai.audio.tts.TextToSpeechOptions
     
    reactor.core.publisher.Flux<org.springframework.ai.audio.tts.TextToSpeechResponse>
    stream(org.springframework.ai.audio.tts.TextToSpeechPrompt prompt)
    Streams the audio response for the given speech prompt.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface org.springframework.ai.audio.tts.StreamingTextToSpeechModel

    stream, stream
  • 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.core.retry.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)
      Specified by:
      call in interface org.springframework.ai.audio.tts.TextToSpeechModel
    • call

      public org.springframework.ai.audio.tts.TextToSpeechResponse call(org.springframework.ai.audio.tts.TextToSpeechPrompt prompt)
      Specified by:
      call in interface org.springframework.ai.model.Model<org.springframework.ai.audio.tts.TextToSpeechPrompt, org.springframework.ai.audio.tts.TextToSpeechResponse>
      Specified by:
      call in interface org.springframework.ai.audio.tts.TextToSpeechModel
    • stream

      public reactor.core.publisher.Flux<org.springframework.ai.audio.tts.TextToSpeechResponse> stream(org.springframework.ai.audio.tts.TextToSpeechPrompt prompt)
      Streams the audio response for the given speech prompt.
      Specified by:
      stream in interface org.springframework.ai.model.StreamingModel<org.springframework.ai.audio.tts.TextToSpeechPrompt, org.springframework.ai.audio.tts.TextToSpeechResponse>
      Specified by:
      stream in interface org.springframework.ai.audio.tts.StreamingTextToSpeechModel
      Parameters:
      prompt - The speech prompt containing the text and options for speech synthesis.
      Returns:
      A Flux of TextToSpeechResponse objects containing the streamed audio and metadata.
    • getDefaultOptions

      public org.springframework.ai.audio.tts.TextToSpeechOptions getDefaultOptions()
      Specified by:
      getDefaultOptions in interface org.springframework.ai.audio.tts.TextToSpeechModel