Skip to content

Commit a601a5c

Browse files
Wvirgil123Love4yzp78
authored
feat: sensecap watcher add inference (#1312)
* feat: Wake up when a person is detected * fix: Solve the problem of no sound when using WakeWordInvoke * fix: Solve the problem of triggering dialogue when the person has not left * feat(vision): 优化视觉检测逻辑并增加配置接口 本次提交旨在优化视觉检测功能,使其行为更自然、更智能,并为用户提供灵活的配置选项。 主要更新包括: 1. 引入了更精细的检测状态机: - IDLE: 空闲状态,等待检测目标。 - VALIDATING: 验证状态,在检测到目标后,持续一段时间(可配置)以确认其存在,防止误触发。 - COOLDOWN: 冷却状态,在一次成功交互后进入,避免过于频繁的打扰。 2. 新增了用于配置视觉检测的 MCP 工具: - self.vision.get_detection_config: 获取当前的检测参数(阈值、冷却间隔、验证时长、目标类型)。 - self.vision.set_detection_config: 允许用户动态修改这些参数,以适应不同场景。 3. 性能优化: - 增加了配置参数的内存缓存,避免了在检测循环中对 NVS 的频繁访问。 * feat: Inference using Model 4 * feat: default inference disable * feat: version cmd change to output json * fix: fix image display * Fix include directives for esp_check and esp_app_desc --------- Co-authored-by: Spencer <[email protected]> Co-authored-by: Xiaoxia <[email protected]>
1 parent ac03f80 commit a601a5c

File tree

4 files changed

+456
-23
lines changed

4 files changed

+456
-23
lines changed

main/application.cc

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -788,13 +788,35 @@ bool Application::UpgradeFirmware(Ota& ota, const std::string& url) {
788788
}
789789

790790
void Application::WakeWordInvoke(const std::string& wake_word) {
791+
if (!protocol_) {
792+
return;
793+
}
794+
791795
if (device_state_ == kDeviceStateIdle) {
792-
ToggleChatState();
793-
Schedule([this, wake_word]() {
794-
if (protocol_) {
795-
protocol_->SendWakeWordDetected(wake_word);
796+
audio_service_.EncodeWakeWord();
797+
798+
if (!protocol_->IsAudioChannelOpened()) {
799+
SetDeviceState(kDeviceStateConnecting);
800+
if (!protocol_->OpenAudioChannel()) {
801+
audio_service_.EnableWakeWordDetection(true);
802+
return;
796803
}
797-
});
804+
}
805+
806+
ESP_LOGI(TAG, "Wake word detected: %s", wake_word.c_str());
807+
#if CONFIG_USE_AFE_WAKE_WORD || CONFIG_USE_CUSTOM_WAKE_WORD
808+
// Encode and send the wake word data to the server
809+
while (auto packet = audio_service_.PopWakeWordPacket()) {
810+
protocol_->SendAudio(std::move(packet));
811+
}
812+
// Set the chat state to wake word detected
813+
protocol_->SendWakeWordDetected(wake_word);
814+
SetListeningMode(aec_mode_ == kAecOff ? kListeningModeAutoStop : kListeningModeRealtime);
815+
#else
816+
SetListeningMode(aec_mode_ == kAecOff ? kListeningModeAutoStop : kListeningModeRealtime);
817+
// Play the pop up sound to indicate the wake word is detected
818+
audio_service_.PlaySound(Lang::Sounds::OGG_POPUP);
819+
#endif
798820
} else if (device_state_ == kDeviceStateSpeaking) {
799821
Schedule([this]() {
800822
AbortSpeaking(kAbortReasonNone);

main/boards/sensecap-watcher/sensecap_watcher.cc

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include "lvgl_theme.h"
1313

1414
#include <esp_log.h>
15-
#include "esp_check.h"
15+
#include <esp_check.h>
1616
#include <esp_lcd_panel_io.h>
1717
#include <esp_lcd_panel_ops.h>
1818
#include <esp_lcd_spd2010.h>
@@ -28,6 +28,7 @@
2828
#include <esp_console.h>
2929
#include <esp_mac.h>
3030
#include <nvs_flash.h>
31+
#include <esp_app_desc.h>
3132

3233
#include "assets/lang_config.h"
3334

@@ -492,6 +493,47 @@ class SensecapWatcher : public WifiBoard {
492493
};
493494
ESP_ERROR_CHECK(esp_console_cmd_register(&cmd5));
494495

496+
const esp_console_cmd_t cmd6 = {
497+
.command = "version",
498+
.help = "Read version info",
499+
.hint = NULL,
500+
.func = NULL,
501+
.argtable = NULL,
502+
.func_w_context = [](void *context,int argc, char** argv) -> int {
503+
auto self = static_cast<SensecapWatcher*>(context);
504+
auto app_desc = esp_app_get_description();
505+
const char* region = "UNKNOWN";
506+
#if defined(CONFIG_LANGUAGE_ZH_CN)
507+
region = "CN";
508+
#elif defined(CONFIG_LANGUAGE_EN_US)
509+
region = "US";
510+
#elif defined(CONFIG_LANGUAGE_JA_JP)
511+
region = "JP";
512+
#elif defined(CONFIG_LANGUAGE_ES_ES)
513+
region = "ES";
514+
#elif defined(CONFIG_LANGUAGE_DE_DE)
515+
region = "DE";
516+
#elif defined(CONFIG_LANGUAGE_FR_FR)
517+
region = "FR";
518+
#elif defined(CONFIG_LANGUAGE_IT_IT)
519+
region = "IT";
520+
#elif defined(CONFIG_LANGUAGE_PT_PT)
521+
region = "PT";
522+
#elif defined(CONFIG_LANGUAGE_RU_RU)
523+
region = "RU";
524+
#elif defined(CONFIG_LANGUAGE_KO_KR)
525+
region = "KR";
526+
#endif
527+
printf("{\"type\":0,\"name\":\"VER?\",\"code\":0,\"data\":{\"software\":\"%s\",\"hardware\":\"watcher xiaozhi agent\",\"camera\":%d,\"region\":\"%s\"}}\n",
528+
app_desc->version,
529+
self->GetCamera() == nullptr ? 0 : 1,
530+
region);
531+
return 0;
532+
},
533+
.context =this
534+
};
535+
ESP_ERROR_CHECK(esp_console_cmd_register(&cmd6));
536+
495537
esp_console_dev_uart_config_t hw_config = ESP_CONSOLE_DEV_UART_CONFIG_DEFAULT();
496538
ESP_ERROR_CHECK(esp_console_new_repl_uart(&hw_config, &repl_config, &repl));
497539
ESP_ERROR_CHECK(esp_console_start_repl(repl));

0 commit comments

Comments
 (0)