TsgcAIOpenAITranslator › Events › OnTranslation
Fires when the OpenAI Whisper API returns the translated text; lets the application inspect, edit, or discard the translation.
property OnTranslation: TsgcOpenAITranslation;
// TsgcOpenAITranslation = procedure(Sender: TObject; var Text: string; var Accept: Boolean) of object
—
The translator fires this event after the Whisper API returns a response for the audio captured between Start and Stop. The Text parameter is passed by reference and initially contains the translated phrase as produced by OpenAI — the handler may modify it (for example, to clean up punctuation or redact content) and the updated value will be the one spoken by the assigned TextToSpeech component. The Accept parameter is True by default when Text is not empty; set it to False to suppress the text-to-speech playback while still keeping your own handling of the translation. When Accept remains True but no TextToSpeech component is assigned, the translator simply returns to recording mode by calling Start.
procedure TForm1.sgcTranslatorTranslation(Sender: TObject;
var Text: string; var Accept: Boolean);
begin
Memo1.Lines.Add('Translation: ' + Text);
// keep Accept := True to let the TextToSpeech play it aloud
end;