I got the example from Drone bot GUY working, I realised that I had the wrong “Audio.h” library and that this was the right one. Still a lot more to implement, but getting close
EDIT: added code
#include "Arduino.h"
#include "WiFi.h"
#include "Audio.h"
#include "HTTPClient.h"
#include "FS.h"
#include "LittleFS.h"
#define I2S_DOUT 9
#define I2S_BCLK 8
#define I2S_LRC 7
Audio audio;
const char* ssid = "SSID";
const char* password = "PASSWORD";
void setup() {
Serial.begin(115200);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("WiFi connected");
// Initialize and mount LittleFS
if (!LittleFS.begin(true)) {
Serial.println("An error has occurred while mounting LittleFS");
return;
}
// Delete the existing response file if it exists
if (LittleFS.exists("/response.mp3")) {
LittleFS.remove("/response.mp3");
Serial.println("Existing MP3 file deleted");
}
// Initialize the I2S output
audio.setPinout(I2S_BCLK, I2S_LRC, I2S_DOUT);
audio.setVolume(100); // Adjust volume as needed
HTTPClient http;
http.begin("http://192.168.1.137:8000/api/audio"); // Your API endpoint
http.addHeader("Content-Type", "application/json");
int httpResponseCode = http.POST("{\"data\":\"Your data here\"}"); // Send POST request
if (httpResponseCode > 0) {
File file = LittleFS.open("/response.mp3", FILE_WRITE);
if (file) {
http.writeToStream(&file);
file.close();
Serial.println("MP3 saved");
} else {
Serial.println("Failed to open file for writing");
}
} else {
Serial.print("Error on sending POST: ");
Serial.println(httpResponseCode);
}
http.end();
// Play the saved MP3 file using LittleFS
audio.connecttoFS(LittleFS, "/response.mp3");
}
void loop() {
audio.loop();
}