OpenAI RealTime API

From sgcWebSockets 2025.5.0 the OpenAI RealTime API is supported (currently only transcription mode).

The OpenAI Realtime API enables low-latency, multimodal interactions including speech-to-speech conversational experiences and real-time transcription.

The component TsgcWSAPI_OpenAI implements the RealTime OpenAI API.

Configuration

Use the method property to select Conversation or Transcription, currently only Transcription mode is supported.

The InputAudio property allows to customize the following data:

  • Language: example english (value = 'en').
  • Model: which model will be used, example: whisper-1
  • Prompt: optional prompt to provide instructions to the model.

OpenAI

The OpenAI API uses API keys for authentication. Visit your API Keys page to retrieve the API key you'll use in your requests.

Remember that your API key is a secret! Do not share it with others or expose it in any client-side code (browsers, apps). Production requests must be routed through your own backend server where your API key can be securely loaded from an environment variable or key management service.

This API Key must be configured in the OpenAIOptions.ApiKey property of the component. Optionally, for users who belong to multiple organizations, you can set your Organization in the property OpenAIOptions.Organization if your account belongs to an organization.

Once the API Key is configured, find below a list of available functions to interactuate with the OpenAI API.

Azure

The client supports Microsoft Azure OpenAI Services, so you can use your Azure account to interactuate with the Azure OpenAI API too. In order to configure the client to work with Azure, follow the next steps:

  1. Configure the property OpenAIOptions.Provider = oapvAzure
  2. Set the values of ResourceName and DeploymentId (these values can be located in your Azure Account)
    1. OpenAIOptions.AzureOptions.ResourceName = <your resource name>.
    2. OpenAIOptions.AzureOptions.DeploymentId = <your deployment id>.
  3. Set the API Key of your Azure Account
    1. OpenAIOptions.ApiKey = <azure api key>.

Transcription Example

WSClient := TsgcWebSocketClient.Create(nil);
oAudio := TsgcAudioRecorderWave.Create(nil);
OpenAI := TsgcWSAPI_OpenAI.Create(nil);

OpenAI.Client := WSClient;
OpenAI.AudioRecorder := oAudio;
OpenAI.OpenAIOptions.APIKey := 'your-api-key-here';
OpenAI.OpenAIOptions.method := sgcoaimTranscription;
OpenAI.OpenAIOptions.provider := sgcoaipOpenAI;
OpenAI.InputAudio.Language := 'en';
OpenAI.InputAudio.Model := 'whisper-1';

procedure OnOpenAIAudioTranscriptionCompleted(Sender: TObject; const aItem: TsgcWSOpenAIConversation_Item_Completed);
begin
  Log('#transcription_completed: ' + aItem.Transcript);
end; 

Demo

 Find below a Delphi Demo showing the main features of the OpenAI RealTime API

sgcRealTime
2.9 mb
×
Stay Informed

When you subscribe to the blog, we will send you an e-mail when there are new updates on the site so you wouldn't miss them.

sgcWebSockets 2025.5
sgcWebSockets 2025.4

Related Posts