From bb66c07d708a1ce6005d26307c57458f2ef83328 Mon Sep 17 00:00:00 2001 From: 1cccux <1486990539@qq.com> Date: Thu, 25 Sep 2025 17:00:51 +0800 Subject: [PATCH 1/2] =?UTF-8?q?update:=20=E5=A2=9E=E5=8A=A0=E8=BF=9C?= =?UTF-8?q?=E7=A8=8B=E5=94=A4=E9=86=92MCP?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main/mcp_server.cc | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/main/mcp_server.cc b/main/mcp_server.cc index 949e5d291..72270586a 100644 --- a/main/mcp_server.cc +++ b/main/mcp_server.cc @@ -300,6 +300,32 @@ void McpServer::AddUserOnlyTools() { return true; }); } + + AddUserOnlyTool("self.wakeup", "Wake up module with parameters", + PropertyList({ + Property("reason", kPropertyTypeString, "Reason for waking up"), + }), + [this](const PropertyList& properties) -> ReturnValue { + std::string reason = "你好小智"; + try { + reason = properties["reason"].value(); + } + catch (...) { + } + ESP_LOGI(TAG, "Wakeup MCP: reason=%s", reason.c_str()); + auto& app = Application::GetInstance(); + auto display = Board::GetInstance().GetDisplay(); + if (display) { + display->SetEmotion("happy"); + } + if (reason.empty()) { + app.WakeWordInvoke("你好小智"); + } else { + app.WakeWordInvoke(reason); + } + return true; + } +); } void McpServer::AddTool(McpTool* tool) { From f7c8908194f4e80be9dddecaf4e76fbdb8a2c8c9 Mon Sep 17 00:00:00 2001 From: 1cccux <1486990539@qq.com> Date: Sun, 28 Sep 2025 17:56:06 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=B2=A1=E6=9C=89?= =?UTF-8?q?=E5=A3=B0=E9=9F=B3=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main/application.cc | 38 ++++++++++++++++++++++++++++++++++++++ main/application.h | 1 + main/mcp_server.cc | 16 ++++------------ 3 files changed, 43 insertions(+), 12 deletions(-) diff --git a/main/application.cc b/main/application.cc index 2cb3db0b8..06016752a 100644 --- a/main/application.cc +++ b/main/application.cc @@ -612,6 +612,44 @@ void Application::MainEventLoop() { } } +void Application::RemoteWakeup(const std::string& reason){ + if (!protocol_) { + return; + } + + if (device_state_ == kDeviceStateIdle) { + audio_service_.EncodeWakeWord(); + + if (!protocol_->IsAudioChannelOpened()) { + SetDeviceState(kDeviceStateConnecting); + if (!protocol_->OpenAudioChannel()) { + audio_service_.EnableWakeWordDetection(true); + return; + } + } + + std::string wake_word = reason; +#if CONFIG_USE_AFE_WAKE_WORD || CONFIG_USE_CUSTOM_WAKE_WORD + // Encode and send the wake word data to the server + while (auto packet = audio_service_.PopWakeWordPacket()) { + protocol_->SendAudio(std::move(packet)); + } + // Set the chat state to wake word detected + protocol_->SendWakeWordDetected(wake_word); + SetListeningMode(aec_mode_ == kAecOff ? kListeningModeAutoStop : kListeningModeRealtime); +#else + SetListeningMode(aec_mode_ == kAecOff ? kListeningModeAutoStop : kListeningModeRealtime); + // Play the pop up sound to indicate the wake word is detected + audio_service_.PlaySound(Lang::Sounds::OGG_POPUP); +#endif + } else if (device_state_ == kDeviceStateSpeaking) { + AbortSpeaking(kAbortReasonWakeWordDetected); + } else if (device_state_ == kDeviceStateActivating) { + SetDeviceState(kDeviceStateIdle); + } + +} + void Application::OnWakeWordDetected() { if (!protocol_) { return; diff --git a/main/application.h b/main/application.h index bff4e9e9c..cf57d91cd 100644 --- a/main/application.h +++ b/main/application.h @@ -63,6 +63,7 @@ class Application { AecMode GetAecMode() const { return aec_mode_; } void PlaySound(const std::string_view& sound); AudioService& GetAudioService() { return audio_service_; } + void RemoteWakeup(const std::string& reason); private: Application(); diff --git a/main/mcp_server.cc b/main/mcp_server.cc index 72270586a..70f71a6ce 100644 --- a/main/mcp_server.cc +++ b/main/mcp_server.cc @@ -306,23 +306,15 @@ void McpServer::AddUserOnlyTools() { Property("reason", kPropertyTypeString, "Reason for waking up"), }), [this](const PropertyList& properties) -> ReturnValue { - std::string reason = "你好小智"; - try { - reason = properties["reason"].value(); - } - catch (...) { - } + std::string reason = properties["reason"].value(); ESP_LOGI(TAG, "Wakeup MCP: reason=%s", reason.c_str()); - auto& app = Application::GetInstance(); + auto display = Board::GetInstance().GetDisplay(); if (display) { display->SetEmotion("happy"); } - if (reason.empty()) { - app.WakeWordInvoke("你好小智"); - } else { - app.WakeWordInvoke(reason); - } + auto& app = Application::GetInstance(); + app.RemoteWakeup(reason); return true; } );