Delphi ChatGPT ChatBot



Delphi ChatGPT ChatBot

Delphi ChatGPT ChatBot

Hello and Welcome to a new SGC e-learning session. Today we will show how to create a ChatBot using the OpenAI API and how to send voice commands to interactuate with the ChatBot and convert the response to Voice.

First we create a new form with 2 buttons and 1 memo. Then we drop a ChatBot component which encapsulates the Transcription and ChatCompletion API which will be used to interactuate with ChatGPT. The ChatBot requires to set the OpenAI Api Key, which can be obtained from OpenAI Servers. We drop 2 additional components, an Audio Recorder component that it’s used to capture the microphone audio and create a wave file which will be sent to OpenAI; and a Text To Speech component that converts text to audio, we will use the SpeechToText component that comes with Windows.

Then, we handle the ChatBot events to know when the audio is recording and when is stopped. OnTranscription event returns the text captured by the microphone and OnChatCompletion shows the response returned by the OpenAI ChatCompletion API.

Now, we compile the application and we show a simple example where we say hello to the chatbot and we get a response from him.