fix: improve field diagnostics and mirror logs to USB CDC

This commit is contained in:
chenjintao
2026-10-20 14:46:08 +08:00
parent 8bff1f569e
commit 07094d4a4e
20 changed files with 1036 additions and 200 deletions
@@ -2,7 +2,9 @@
#include <string.h>
#include <librws.h>
#include "cJSON.h"
#include "app_inc.h"
#include "app_inc.h"
#include "net_diag.h"
#include "net_diag_voice.h"
#include "ql_rtos.h"
#include "ql_application.h"
#include "ql_audio.h"
@@ -27,6 +29,7 @@
// 在文件顶部添加状态变量
static uint8_t speech_detect_peak = 0;
static uint8_t speech_detect_count = 0; // 连续语音帧计数器
#define SPEECH_DETECT_THRESHOLD 20 // 连续检测到语音的阈值
#define PLAYBACK_VAD_GUARD_MS 800 // 屏蔽播放结束后的尾音和音频通路切换噪声
@@ -209,16 +212,19 @@ int vad_audio_start(void) {
vad_audio_init();
frame_count = 0;
speech_frame_count = 0;
speech_frame_count = 0;
speech_detect_peak = 0;
printf("Audio recording started with FVAD");
printf("Audio recording started with FVAD\r\n");
return 0;
}
// 停止录音
int vad_audio_stop(void) {
printf("Audio recording stopped, frames: %d, speech: %d",
net_diag_voice_mark(0, VOICE_RECORD_STOP);
net_diag_vad_stats(frame_count, speech_frame_count, speech_detect_peak);
printf("Audio recording stopped, frames: %d, speech: %d\r\n",
frame_count, speech_frame_count);
vad_audio_deinit();
@@ -416,7 +422,7 @@ void vad_audio_process(void) {
}
if (current_vad == VAD_STATE_ACTIVE) {
speech_detect_count++;
printf("Speech frame count: %d\r\n", speech_detect_count);
if (speech_detect_count > speech_detect_peak) speech_detect_peak = speech_detect_count;
// 连续达到阈值才确认检测到声音
if (speech_detect_count >= SPEECH_DETECT_THRESHOLD) {
@@ -447,12 +453,13 @@ void vad_audio_process(void) {
vad_preroll_count = 0;
}
set_state(STATE_RECORDING_ACTIVE);
printf("First speech confirmed by FVAD (continuous %d frames)", SPEECH_DETECT_THRESHOLD);
net_diag_voice_mark(0, VOICE_SPEECH);
printf("First speech confirmed by FVAD (continuous %d frames)\r\n", SPEECH_DETECT_THRESHOLD);
}
} else {
// 出现静音帧,计数器清零
if (speech_detect_count > 0) {
printf("Speech interrupted, reset count\r\n");
/* Per-frame chatter replaced by the final peak statistic. */
speech_detect_count = 0;
}