Hello friends, welcome back to my YouTube channel. In the previous episode of the ChatGPT series, we learned how to use ChatGPT on our ESP32 boards with the help of the ChatGPT API. In today’s episode, we are going to add a new feature to our project. Now, we can listen to the responses from ChatGPT as an audio output.
To achieve this, we will learn about the i2s audio amplifier module and the Google TTS library. The i2s audio amplifier module allows us to connect a speaker to our ESP32 board. The Google TTS library enables us to convert any text into speech.
To get started, we need the following hardware components: an ESP32 board, an i2s audio amplifier module, and a speaker. You can find the links to these items in the description box.
First, we need to download the audio i2s library from the GitHub page. Once downloaded, we can add the library to the Arduino IDE. Next, we need to define the necessary WiFi settings and volume level in our code.
We have created a basic code to test if we can convert a sample string into speech using our hardware. After uploading the code to the ESP32 board, we can see the output in the serial monitor.
Now, let’s integrate our ChatGPT API code with the audio output code. We will use the Arduino JSON library to decode the JSON response from the ChatGPT API. We extract the response string and convert it into speech using the Google TTS library.
We have provided the necessary headers and defined the payload for the ChatGPT API request. The response from the API is stored in a JSON format, and we extract the answer from it. We then remove unnecessary characters from the answer and convert it into speech using the audio output code.
In the video, we demonstrate how to ask questions to ChatGPT and receive audio responses. We also discuss the possibility of creating an independent project that takes input from a microphone and responds through a speaker, or integrating a keyboard to pass input to the ESP32 board.
If you enjoyed this video, please like and subscribe to my channel. Don’t forget to leave your feedback and suggestions in the comments. Stay tuned for the next episode!