Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions main/application.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions main/application.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
18 changes: 18 additions & 0 deletions main/mcp_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,24 @@ 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 = properties["reason"].value<std::string>();
ESP_LOGI(TAG, "Wakeup MCP: reason=%s", reason.c_str());

auto display = Board::GetInstance().GetDisplay();
if (display) {
display->SetEmotion("happy");
}
auto& app = Application::GetInstance();
app.RemoteWakeup(reason);
return true;
}
);
}

void McpServer::AddTool(McpTool* tool) {
Expand Down