task_cfg.create_queue_handle = CreateAIVoiceQueue; // 设置队列创建函数
task_cfg.attr.name = "AIVoiceThread";
- task_cfg.attr.priority = (osPriority_t)24; // 使用合适的优先级
+ task_cfg.attr.priority = (osPriority_t)28; // 使用合适的优先级
task_cfg.attr.stack_size = 0x2000; // 8KB栈空间
task_cfg.func = AIVoiceThread;
task_cfg.use_mem = USE_EXTEND_MEM;
// 写入音频数据到输出流
int32_t ret = AudioStreamOutStreamWrite(data, size);
- usleep(50*size);
+ usleep(40*size);
if (ret != 0) {
retry_count++;
// MEDIA_ERR_LOG("Failed to write audio data to output stream, ret=%d, retry %d/%d", ret, retry_count, MAX_RETRY_COUNT);
- usleep(1000*600);
+ usleep(1000*300);
goto AI_WRITE;
}
int32_t result = AI_WriteToFileCache(msg);
if (result == 0) {
MEDIA_DEBUG_LOG("Successfully wrote %u bytes to file cache", size);
+ free(dataCopy);
return 0;
} else {
MEDIA_ERR_LOG("Failed to write to file cache");
int32_t result = AI_WriteToFileCache(msg);
if (result == 0) {
MEDIA_INFO_LOG("Successfully wrote %u bytes to file cache to maintain order", size);
+ free(dataCopy);
return 0;
} else {
MEDIA_ERR_LOG("Failed to write to file cache for order maintenance");
snprintf(url, url_size, "%s?deviceToken=%s&deviceId=%s&reconnect=%u",
base, token, device_id, g_ws_reconnect_count);
- /* 构建头部信息 */
+ // /* 构建头部信息 */
snprintf(header_buf, header_size, "deviceId: %s\r\n", device_id);
+ // 110.42.224.129 8910
+ // snprintf(url, url_size, "%s","ws://110.42.224.129:8910");
+ // base, token, device_id, g_ws_reconnect_count);
}
/* 心跳处理回调函数 */
// ========== VAD 处理:在录音接口层推送 ==========
// 优势:1. 更上层更清晰 2. 天然只处理录音数据 3. finished即is_last
-#if ENABLE_VAD_SERVER
- if (g_vad_server_enabled && g_vad_server_initialized && vad_server_is_running()) {
- vad_audio_format_t format = VAD_AUDIO_FORMAT_MP3; // 默认 MP3
-
- if (audio_data && audio_size > 0) {
- errcode_t ret = vad_server_send_audio(format, audio_data, audio_size, finished);
- if (ret != ERRCODE_SUCC) {
- /* 静默失败,避免过多日志 */
- } else {
- LN_WS_DEBUG("VAD: Sent %u bytes (format=%d, is_last=%d)\n",
- audio_size, format, finished);
- }
- }
-
- // 如果是结束标志,打印日志
- if (finished) {
- LN_WS_INFO("VAD: Audio recording ended\n");
- }
- }
-#endif
+
// ================================================
// 检查连接状态
// ========== VAD 处理已移到 ln_ws_send_audio_data (录音接口层) ==========
// 更上层、更清晰、天然只处理录音数据
+ #if ENABLE_VAD_SERVER
+ if (g_vad_server_enabled && g_vad_server_initialized && vad_server_is_running()) {
+ vad_audio_format_t format = VAD_AUDIO_FORMAT_MP3; // 默认 MP3
+
+ if (data && size > 0) {
+ errcode_t ret = vad_server_send_audio(format, data, size, false);
+ if (ret != ERRCODE_SUCC) {
+ /* 静默失败,避免过多日志 */
+ } else {
+ LN_WS_DEBUG("VAD: Sent %u bytes (format=%d, is_last=%d)\n",
+ size, format, false);
+ }
+ }
+
+ // 如果是结束标志,打印日志
+ if (false) {
+ LN_WS_INFO("VAD: Audio recording ended\n");
+ }
+ }
+ #endif
+
// WebSocket 发送逻辑(如果需要同时发送到服务器)
if (g_audio_chat_ctx.is_active == true)
if (!raw_data || length == 0) {
return;
}
+
+ if(isBinary)
+ {
+ const size_t CHUNK_SIZE = 1024; // 1K 分块大小
+ if (length <= CHUNK_SIZE) {
+ // 数据小于等于1K,直接发送
+ LN_WS_DEBUG("Sending data directly (size: %d bytes)\n", length);
+ AI_SendAudioDataToQueue((uint8_t *)raw_data, length);
+ } else {
+ // 数据大于1K,分块发送
+ LN_WS_DEBUG("Data size %d bytes > %zu bytes, splitting into chunks\n", length, CHUNK_SIZE);
+
+ size_t remaining = length;
+ const uint8_t *current_pos = (uint8_t *)raw_data;
+ int chunk_count = 0;
+
+ while (remaining > 0) {
+ size_t current_chunk_size = (remaining > CHUNK_SIZE) ? CHUNK_SIZE : remaining;
+
+ LN_WS_DEBUG("Sending chunk %d: %zu bytes\n", ++chunk_count, current_chunk_size);
+ AI_SendAudioDataToQueue(current_pos, current_chunk_size);
+
+ current_pos += current_chunk_size;
+ remaining -= current_chunk_size;
+ }
+
+ LN_WS_DEBUG("All %d chunks sent successfully\n", chunk_count);
+ }
+ }
LN_WS_DEBUG("Incomplete message received: length=%zu, isBinary=%s\n",
length, isBinary ? "true" : "false");
#ifdef SUPPORT_CAT1_SERVICE
cat1_api_keep_wakeup(1);
cat1_api_wakeup_cat1(1);
- uapi_cat1_add_cat1_vote();
+
#endif
+ uapi_cat1_add_cat1_vote();
old_Start_AIVoice(AIVoiceDataCallback_ln,NULL,&audioParams_in,&audioParams_out,false);
#ifdef SUPPORT_CAT1_SERVICE
cat1_api_keep_wakeup(0);
cat1_api_wakeup_cat1(0);
- uapi_cat1_remove_cat1_vote();
#endif
+ uapi_cat1_remove_cat1_vote();
+
// 清除初始化标志位
g_audio_initialized = false;
if (ret == 0) {
LN_WS_DEBUG("VoiceChatInterrupt sent successfully\n");
- if (1) {
+ if (need_reconnect) {
// 如果检测到频繁数据接收,直接重连
LN_WS_INFO("Triggering reconnection due to frequent binary data reception\n");
if (ln_ws_reconnect() != 0) {