bool ln_ws_is_vad_server_enabled(void); /* 获取 VAD 服务器启用状态 */
bool ln_ws_is_vad_server_initialized(void); /* 获取 VAD 服务器初始化状态 */
bool ln_ws_is_vad_server_auth_success(void); /* 获取 VAD 服务器认证成功状态 */
+void ln_ws_set_vad_recognition_enabled(bool en); /* 仅控制是否响应 VAD 结果,不关闭 VAD 服务 */
/* ==================== HTTP文件下载接口(基于SPI传输) ==================== */
/**
static volatile bool g_vad_server_enabled = false;
static volatile bool g_vad_server_initialized = false;
static volatile bool g_vad_server_auth_success = false;
+/* VAD 识别开关:为 false 时不响应 VAD 回调(不开始/结束对话),VAD 服务不关闭 */
+static volatile bool g_vad_recognition_enabled = false;
/* 回调函数结构体 */
static ws_call_backs_t g_ws_callbacks = {0};
LN_WS_INFO("VAD server is disabled, ignoring callback (status=%d)\n", status);
return;
}
+ // 仅“不识别语音”:不关闭 VAD 服务,但不响应 VAD 结果,避免对话播放中被 VAD 打断
+ if (!g_vad_recognition_enabled) {
+ LN_WS_INFO("VAD recognition disabled, ignoring callback (status=%d)\n", status);
+ return;
+ }
if(g_audio_playback_active)
{
else
if (status==2)
{
+ // 仅当确实有活跃录音会话时才结束并关闭识别;无活跃会话时的 status=2 视为误报,不关闭识别
+ bool had_active_chat = g_audio_chat_ctx.is_active;
ln_ws_end_audio_chat();
- if(g_audio_chat_ctx.is_active)
+ if (had_active_chat)
+ {
+ if (g_audio_chat_ctx.is_active)
+ {
+ ln_ws_start_vad_cooldown();
+ }
+ g_vad_recognition_enabled = false;
+ LN_WS_INFO("VAD recognition disabled after recording end (status=2)\n");
+ }
+ else
{
- ln_ws_start_vad_cooldown();
+ LN_WS_DEBUG("VAD status=2 with no active chat, keep recognition enabled\n");
}
- // 开始VAD冷却计时
}
return g_vad_server_auth_success;
}
+/**
+ * @brief 设置 VAD 识别开关(不关闭 VAD 服务,仅控制是否响应 VAD 回调)
+ * @param en true=响应 VAD 开始/结束,false=不识别语音
+ * @note 录音结束后在回调内自动置 false;仅在“播放结束”或“按键进入聆听”时由应用置 true
+ */
+void ln_ws_set_vad_recognition_enabled(bool en)
+{
+ g_vad_recognition_enabled = en;
+ LN_WS_INFO("VAD recognition %s\n", en ? "enabled" : "disabled");
+}
+
/**
* @brief 执行 VAD 认证
* @return 0成功,-1失败