To build a Translator with voice commands, the following steps are required:
Create a new Translator, using the default Text-To-Speech from Microsoft Windows. Use Start to Start the recording of the audio and Stop to Stop the recording and send the audio to the OpenAI API and translate it.
// ... create the translator component
sgcTranslator := TsgcAIOpenAITranslator.Create(nil);
sgcTranslator.OpenAIOptions.ApiKey := 'your_openapi_api_key';
// ... create audio recorder and tex-to-speech
sgcAudioRecorder := TsgcAudioRecorderMCI.Create(nil);
sgcTextToSpeech := TsgcTextToSpeechSystem.Create(nil);
// ... assign audio components to translator
sgcTranslator.AudioRecorder := sgcAudioRecorder;
sgcTranslator.TextToSpeech := sgcTextToSpeech;
// ... start the translator, speak with a microphone to capture the audio and stop to translate it
sgcTranslator.Start;
... speak
sgcTranslator.Stop;