Class OpenAiRealtimeClient

java.lang.Object
com.sap.ai.sdk.foundationmodels.openai.realtime.OpenAiRealtimeClient

@Beta public class OpenAiRealtimeClient extends Object
OpenAI client implementation of Realtime API. Abstracts technical implementation, transport and threading and exposes business-level operations (high level interface)
  • Constructor Details

    • OpenAiRealtimeClient

      @Beta public OpenAiRealtimeClient(@Nonnull com.sap.cloud.sdk.cloudplatform.connectivity.Destination destination)
      Created OpenAI Realtime client for a specific destination
      Parameters:
      destination - - destination to use
  • Method Details

    • textToSpeech

      @Nonnull @Beta public TextInputChannel textToSpeech(@Nonnull AudioOutputChannel audioOutputConsumer, @Nonnull RealtimeParam... params)
      Creates a realtime channel allowing to input text and voice it (receive audio output)

      The input channel should be used with a try-with-resources block to ensure that the underlying connection is closed.

      Example:

      
       try (var textInputChannel = client.textToSpeech(audioOutputConsumer)) {
             textInputChannel.sendText("...");
             ....
       }
       
      This API implements full duplex (input + output) communication channels. Application should logically synchronize their state and close the input channel when it is appropriate (e.g. the last part of the response has been received via the output channel and the application does not need to send any other input). When the input channel is closed, the output channel will be closed automatically and the output consumer will not be called anymore.
      Parameters:
      audioOutputConsumer - - audio consumer of raw PCM mono 24000 Hz little endian output, 16 bit depth
      params - - allows for various additional features (e.g. voice configuration or conversation turn recognition options)
      Returns:
      input channel, allowing for text input
    • speechToSpeech

      @Nonnull @Beta public AudioInputChannel speechToSpeech(@Nonnull AudioOutputChannel audioOutputConsumer, @Nonnull RealtimeParam... params)
      Creates a realtime channel allowing for audio conversation with a model.

      The input channel should be used with a try-with-resources block to ensure that the underlying connection is closed.

      Example:

      
       try (var audioInputChannel = client.speechToSpeech(audioOutputConsumer)) {
             audioInputChannel.inputAudio(audioBytesData);
             ....
       }
       
      This API implements full duplex (input + output) communication channels. An application should logically synchronize their state and close the input channel when it is appropriate (e.g. the last part of the response has been received via the output channel and the application does not need to send any other input). When the input channel is closed, the output channel will be closed automatically and the output consumer will not be called anymore.
      Parameters:
      audioOutputConsumer - - audio consumer of raw PCM mono 24000 Hz little endian output, 16 bit depth
      params - - optional configuration params
      Returns:
      input channel, allowing for audio data input (bytes, PCM mono 24000 Hz little endian 16 bit)