Skip to content
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
10 changes: 10 additions & 0 deletions firmware-arduino/src/Audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ StreamCopy pitchCopier(volumePitch, queue);
AudioInfo info(SAMPLE_RATE, CHANNELS, BITS_PER_SAMPLE);
volatile bool i2sOutputFlushScheduled = false;

volatile bool talkInterruptScheduled = false;

unsigned long getSpeakingDuration() {
if (deviceState == SPEAKING && speakingStartTime > 0) {
return millis() - speakingStartTime;
Expand Down Expand Up @@ -239,6 +241,14 @@ void micTask(void *parameter) {
// Use smaller chunk size to avoid blocking too long
micToWsCopier.copyBytes(MIC_COPY_SIZE);

if ( talkInterruptScheduled == true ) {
talkInterruptScheduled = false;
const char* msg = "{\"type\": \"instruction\", \"msg\": \"INTERRUPT\", \"audio_end_ms\": 1000}";
xSemaphoreTake(wsMutex, portMAX_DELAY);
webSocket.sendTXT(msg, strlen(msg));
xSemaphoreGive(wsMutex);
}

// Yield more frequently
vTaskDelay(1);
} else {
Expand Down
2 changes: 2 additions & 0 deletions firmware-arduino/src/Audio.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ extern I2SStream i2sInput;
extern StreamCopy micToWsCopier;
extern volatile bool i2sInputFlushScheduled;

extern volatile bool talkInterruptScheduled;

// WEBSOCKET
void webSocketEvent(WStype_t type, uint8_t *payload, size_t length);
void websocketSetup(String server_domain, int port, String path);
Expand Down
10 changes: 9 additions & 1 deletion firmware-arduino/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,14 @@ static void onButtonDoubleClickCb(void *button_handle, void *usr_data)
enterSleep();
}

static void onButtonSingleClickCb(void *button_handle, void *usr_data)
{
Serial.println("Button single click");
// scheduleListeningRestart = true;
// scheduledTime = millis();
talkInterruptScheduled = true;
}

void getAuthTokenFromNVS()
{
preferences.begin("auth", false);
Expand Down Expand Up @@ -197,7 +205,7 @@ void setup()
Button *btn = new Button(BUTTON_PIN, false);
btn->attachLongPressUpEventCb(&onButtonLongPressUpEventCb, NULL);
btn->attachDoubleClickEventCb(&onButtonDoubleClickCb, NULL);
btn->detachSingleClickEvent();
btn->attachSingleClickEventCb(&onButtonSingleClickCb, NULL);
#endif

// Pin audio tasks to Core 1 (application core)
Expand Down
5 changes: 5 additions & 0 deletions server-deno/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,11 @@ wss.on("connection", async (ws: WSWebSocket, payload: IPayload) => {
console.log("interrupt detected", message);
const audioEndMs = message.audio_end_ms;

client.realtime.send("response.cancel", {
type: "response.cancel",
event_id: RealtimeUtils.generateId("evt_")
});

client.realtime.send("conversation.item.truncate", {
event_id: RealtimeUtils.generateId("evt_"), // Generate unique ID
type: "conversation.item.truncate",
Expand Down