OpenAI Translator Component — sgcAI | eSeGeCe

OpenAI Translator

TsgcAIOpenAITranslator turns spoken input in almost any language into spoken English. It records the microphone, posts the audio to the OpenAI translation endpoint, gives you a chance to review the text, then speaks it through a text-to-speech component.

TsgcAIOpenAITranslator

A speech to speech translator. The OpenAI audio translation endpoint always produces English, so the component needs no source language configuration, only a model and an optional review step.

Component class

TsgcAIOpenAITranslator

Purpose

Spoken translation to English

Family

Chat & agents

Platforms

Win32 and Win64

sgcAI is self-contained. This component ships inside sgcAI together with the sgcWebSockets Core runtime it is built on, so there is no base license to buy.

Speak in one language, hear English

Link a recorder and a text-to-speech component, set the API key, call Start.

uses
  sgcAI, sgcAI_OpenAI_Audio_Translator,
  sgcAI_AudioRecorder_MCI, sgcAI_TextToSpeech_System;

var
  oTranslator: TsgcAIOpenAITranslator;
begin
  oTranslator := TsgcAIOpenAITranslator.Create(nil);
  oTranslator.OpenAIOptions.ApiKey := 'sk-...';
  oTranslator.AudioRecorder := sgcAudioRecorderMCI1;
  oTranslator.TextToSpeech  := sgcTextToSpeechSystem1;

  oTranslator.TranslatorOptions.Translation.Model := 'whisper-1';
  oTranslator.OnTranslation := TranslatorTranslation;

  oTranslator.Start;   // Stop ends the session
end;

procedure TForm1.TranslatorTranslation(Sender: TObject;
  var Text: string; var Accept: Boolean);
begin
  memoLog.Lines.Add(Text);
  Accept := True;   // set False to skip speaking this segment
end;
// includes: sgcAI.hpp, sgcAI_OpenAI_Audio_Translator.hpp

TsgcAIOpenAITranslator *oTranslator = new TsgcAIOpenAITranslator(NULL);
oTranslator->OpenAIOptions->ApiKey = "sk-...";
oTranslator->AudioRecorder = sgcAudioRecorderMCI1;
oTranslator->TextToSpeech  = sgcTextToSpeechSystem1;

oTranslator->TranslatorOptions->Translation->Model = "whisper-1";
oTranslator->OnTranslation = TranslatorTranslation;

oTranslator->Start();

Key properties & methods

The members you reach for most often.

AudioRecorder captures the speech and TextToSpeech speaks the translation. Leave TextToSpeech unassigned and the component simply returns text and restarts capture.

TranslatorOptions

Translation.Model selects the transcription model used for the translation request.

OpenAIOptions

API key, endpoint, HTTP, retry and logging settings shared with the other OpenAI components.

Session

Start begins capture and Stop ends it. In automatic recorder mode each silence boundary closes a segment and triggers a translation.

Events

OnTranslation hands you the translated text with an Accept flag, so you can log it, correct it or suppress it before it is spoken. OnAudioStart and OnAudioStop track capture.

Output language

The OpenAI translation endpoint always produces English. To translate into other languages, pair the transcript with a chat call through TsgcAIChat.

Specifications & references

Authoritative sources for the services and protocols this component uses.

Keep exploring

Online HelpFull API reference and usage guide for the sgcAI components.
All sgcAI ComponentsBrowse the full feature matrix of all 15 components.
Download Free TrialTranslate live speech with your own OpenAI key.
PricingSingle, Team and Site licenses, full source code, no base product required.
Best value: All-AccessEvery eSeGeCe product, Premium Support included, from €1,059/year.
See All-Access pricing

Ready to Get Started?

Download the free trial and add live speech translation to your application.