Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Add support for ESP32S3 #76

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions devices/esp32/testHTTP.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#include <Arduino.h>
#include <WiFi.h>
#include <HTTPClient.h>
#include <WiFiClientSecure.h>

const char* ssid = ">ENTER WIFI NAME>"; // Your WiFi SSID
const char* password = "<ENTER PASS>"; // Your WiFi password


// Function to send WAV buffer
void sendWavBuffer(const std::vector<uint8_t>& buffer) {
// Ensure we are connected to WiFi. If not, return.
if (WiFi.status() != WL_CONNECTED) {
Serial.println("WiFi is not connected!");
return;
}

const char* supabaseUrlEnv = "<SUPABASE URL>"; // Use your Supabase URL here
const char* authToken = "<ANON TOKEN>"; // Use your Auth Token here

std::string url = std::string(supabaseUrlEnv) + "/functions/v1/process-audio";

WiFiClientSecure client;
client.setInsecure(); // Disables SSL certificate verification

HTTPClient https;
if (https.begin(client, url.c_str())) { // HTTPS begin
https.addHeader("Authorization", "Bearer " + String(authToken));
https.addHeader("Content-Type", "audio/wav");

// Create a non-const copy of the data from the buffer
size_t bufferSize = buffer.size();
uint8_t* nonConstBuffer = new uint8_t[bufferSize];
memcpy(nonConstBuffer, buffer.data(), bufferSize);

// Use the non-const copy in the POST call
int httpResponseCode = https.POST(nonConstBuffer, bufferSize);

if (httpResponseCode > 0) {
// If server responds, print response
Serial.printf("HTTP Response code: %d\n", httpResponseCode);
String payload = https.getString();
Serial.println(payload);
}
else {
Serial.printf("Error on sending POST: %d\n", httpResponseCode);
}

// Clean up the non-const buffer copy after use
delete[] nonConstBuffer;

https.end(); // HTTPS end
}
else {
Serial.println("Error in HTTPS connection");
}


}

void setup() {
Serial.begin(115200);

// Connect to WiFi
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi..");
}
Serial.println("Connected to WiFi");

// Initialize vector with dummy data for testing
std::vector<uint8_t> dummyData(1024, 0); // Example buffer, replace with actual audio data
sendWavBuffer(dummyData); // Send the buffer
}

void loop() {
// Nothing here
}

27 changes: 27 additions & 0 deletions devices/esp32/testI2S.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include "I2S.h"

void setup() {
// Open serial communications and wait for port to open:
// A baud rate of 115200 is used instead of 9600 for a faster data rate
// on non-native USB ports
Serial.begin(115200);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}

// start I2S at 16 kHz with 16-bits per sample
I2S.setAllPins(-1, 42, 41, -1, -1);
if (!I2S.begin(PDM_MONO_MODE, 16000, 16)) {
Serial.println("Failed to initialize I2S!");
while (1); // do nothing
}
}

void loop() {
// read a sample
int sample = I2S.read();

if (sample && sample != -1 && sample != 1) {
Serial.println(sample);
}
}
21 changes: 0 additions & 21 deletions devices/raspipico/CMakeLists.txt

This file was deleted.

9 changes: 0 additions & 9 deletions devices/raspipico/main.c

This file was deleted.

10 changes: 9 additions & 1 deletion supabase/functions/process-audio/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,17 @@ const processAudio = async (req: Request) => {
try {
const filenameTimestamp = `adeus_wav_${Date.now()}.wav`;
const wavFile = await toFile(arrayBuffer, filenameTimestamp);

const { data, error } = await supabase.storage
.from("test")
.upload(filenameTimestamp, wavFile);

if (error) {
console.error("Error uploading file:", error);
}

const transcriptResponse = await openaiClient.audio.transcriptions.create({
file: await toFile(wavFile, filenameTimestamp),
file: wavFile,
model: "whisper-1",
prompt:
'Listen to the entire audio file, if no audio is detected then respond with "None" ', // These types of prompts dont work well with Whisper -- https://platform.openai.com/docs/guides/speech-to-text/prompting
Expand Down