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.
Use the method property to select Conversation or Transcription, currently only Transcription mode is supported.
The InputAudio property allows you to customize the following data:
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 interact with the OpenAI API.
Azure
The client supports Microsoft Azure OpenAI Services, so you can use your Azure account to interact with the Azure OpenAI API too. In order to configure the client to work with Azure, follow the next steps:
Find below an example of real-time transcription using openAI API
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;