mic_data_zong[0]=0;
memcpy(mic_data_zong+1,mac,6);//1-6是设备唯一id
for(int i=0;i<read_len1;i++){
mic_data_zong[addon_sound_buf_len+i]=to_VAD_1_pre_audio_data[index1+i] ;
}
size_t total_len = read_len1 + addon_sound_buf_len;
//不要用esp_websocket_client_send_bin直接发送前导音频,会卡,导致mic声音卡顿,要用环形队列:
BaseType_t send_ret =xRingbufferSend(buf_handle, mic_data_zong,
total_len, pdMS_TO_TICKS(2000));
if (send_ret != pdTRUE) {
ESP_LOGE(TAG, "Preamble send001 failed! total_len=%d", total_len);
}
/*
// 直接通过 WebSocket 发送
if (client != nullptr && esp_websocket_client_is_connected(client)) {
if (xSemaphoreTake(ws_mutex, pdMS_TO_TICKS(max_send_wait_time_ms)) == pdTRUE) {
esp_err_t err = esp_websocket_client_send_bin(client,
(const char *)mic_data_zong,
(int)total_len,
portMAX_DELAY);
if (err<0 ) {
ESP_LOGE(TAG, "Preamble send failed: %s", esp_err_to_name(err));//提示是失败,其实发成功了
} else {
ESP_LOGI(TAG, "Preamble sent successfully, len=%d", total_len);
}
xSemaphoreGive(ws_mutex);
} else {
ESP_LOGE(TAG, "Could not take ws_mutex for preamble");
}
} else {
ESP_LOGE(TAG, "WebSocket not connected, preamble dropped");
}
*/
/*
BaseType_t send_ret = xRingbufferSend(buf_handle, mic_data_zong,
pre_len + addon_sound_buf_len, pdMS_TO_TICKS(2000));
ESP_LOGE(TAG, "[DEBUG] SENDING PREAMBLE!!!,pre_len=%d", pre_len);
if (send_ret != pdTRUE) {
ESP_LOGE(TAG, "Preamble send001 failed! pre_len=%d", pre_len);
}
*/