feat(voice): migrate to push2talk and serialize websocket text sends

This commit is contained in:
admin
2026-03-01 01:21:18 +08:00
parent 9deeab738e
commit dd108e2658
19 changed files with 891 additions and 224 deletions

View File

@@ -8,6 +8,7 @@
#include "esp_opus_enc.h"
#include "esp_websocket_client.h"
#include "freertos/FreeRTOS.h"
#include "freertos/queue.h"
#include "freertos/semphr.h"
#include "freertos/task.h"
#include "domain.h"
@@ -21,7 +22,7 @@
#define VOICE_SAMPLE_BYTES 2
#define VOICE_STATUS_LOCK_TIMEOUT_MS 1000
#define VOICE_WS_SEND_TIMEOUT_MS 1000
#define VOICE_WS_SEND_TIMEOUT_MS 3000
#define VOICE_WS_TASK_STACK 24576
#define VOICE_UPLINK_TASK_STACK 32768
#define VOICE_HEARTBEAT_TASK_STACK 4096
@@ -31,15 +32,25 @@
#define VOICE_AUDIO_DRAIN_QUIET_MS 180
#define VOICE_AUDIO_DRAIN_WAIT_MS 2200
#define VOICE_AUDIO_DRAIN_WAIT_ON_STOP_MS 3500
#define VOICE_WS_TEXT_QUEUE_LEN 16
#define VOICE_WS_TEXT_QUEUE_RX_TIMEOUT_MS 100
typedef struct {
char *text;
int len;
} voice_ws_text_msg_t;
typedef struct {
SemaphoreHandle_t lock;
esp_websocket_client_handle_t ws;
QueueHandle_t ws_text_queue;
TaskHandle_t uplink_task;
TaskHandle_t heartbeat_task;
TaskHandle_t ws_text_task;
bool uplink_task_with_caps;
bool heartbeat_task_with_caps;
bool ws_text_task_with_caps;
void *opus_enc;
void *opus_dec;
@@ -63,7 +74,10 @@ typedef struct {
bool ws_connected;
bool started;
bool tap_active;
bool speech_active;
bool stop_requested;
bool ws_text_shutdown;
bool ws_text_busy;
bool ws_low_stack_warned;
bool response_first_sentence_checked;
@@ -129,6 +143,10 @@ void voice_websocket_event_handler(void *handler_args,
void *event_data);
void voice_interaction_ws_init_cjson_hooks(void);
esp_err_t voice_interaction_try_send_speech(char *err, size_t err_len);
void voice_uplink_task(void *arg);
void voice_heartbeat_task(void *arg);
void voice_ws_text_task(void *arg);
esp_err_t voice_interaction_mic_key_init(void);