Struggling to understand the Espressif Open AI Chat GPT Library

Thread Starter

teenflon5

Joined Apr 19, 2021
27
Hello,

Working on an undergrad project and struggling to interpret the library built by espressif for ESP32 which makes using the Open AI APIs easier. There are some examples in the github for the chat element, but I am struggling to use the documentation to use the Audio Transcription and Audio Output elements. Has anyone used these before and has an example code I can use, or can anyone interpret the documentation to make it clear what I need to do?

Documentation - https://docs.espressif.com/projects/esp-iot-solution/en/latest/ai/openai.html#

Github with some examples - https://github.com/me-no-dev/OpenAI-ESP32

So far my line to run the Audio Transcription is as follows;




OpenAI_AudioTranscription STT(openai);


STT.setResponseFormat(OPENAI_AUDIO_RESPONSE_FORMAT_TEXT);


Serial.println(STT.file(wavBuffer, bytesRead, OPENAI_AUDIO_INPUT_FORMAT_WAV));



Where wavBuffer is the file allocated to memory, and bytesRead is the length. Code for those sections below;




File wavFile = SD.open("/Test/CapitalofEngland.wav", FILE_READ);
if (!wavFile) {
Serial.println("Error opening WAV file");
return;
}
// Get the size of the WAV file
size_t fileSize = wavFile.size();
// Allocate memory for the WAV file content
uint8_t* wavBuffer = (uint8_t*)malloc(fileSize);
if (!wavBuffer) {
Serial.println("Memory allocation failed");
wavFile.close();
return;
}
// Read the WAV file content into the buffer
size_t bytesRead = wavFile.read(wavBuffer, fileSize);
wavFile.close();
if (bytesRead == fileSize) {
Serial.println("WAV file content read into buffer successfully");
} else {
Serial.println("Error reading WAV file content into buffer");
free(wavBuffer);
return;
}



 

Thread Starter

teenflon5

Joined Apr 19, 2021
27
I should add, printing the line below just returns nothing but an empty carriage return in the serial monitor.

Serial.println(STT.file(wavBuffer, bytesRead, OPENAI_AUDIO_INPUT_FORMAT_WAV));
 
Top