@@ -44,6 +44,14 @@ Application::Application() {
4444 event_group_ = xEventGroupCreate ();
4545 background_task_ = new BackgroundTask (4096 * 7 );
4646
47+ #if CONFIG_USE_DEVICE_AEC
48+ aec_mode_ = kAecOnDeviceSide ;
49+ #elif CONFIG_USE_SERVER_AEC
50+ aec_mode_ = kAecOnServerSide ;
51+ #else
52+ aec_mode_ = kAecOff ;
53+ #endif
54+
4755#if CONFIG_USE_AUDIO_PROCESSOR
4856 audio_processor_ = std::make_unique<AfeAudioProcessor>();
4957#else
@@ -285,7 +293,7 @@ void Application::ToggleChatState() {
285293 return ;
286294 }
287295
288- SetListeningMode (realtime_chat_enabled_ ? kListeningModeRealtime : kListeningModeAutoStop );
296+ SetListeningMode (aec_mode_ == kAecOff ? kListeningModeAutoStop : kListeningModeRealtime );
289297 });
290298 } else if (device_state_ == kDeviceStateSpeaking ) {
291299 Schedule ([this ]() {
@@ -358,8 +366,8 @@ void Application::Start() {
358366 auto codec = board.GetAudioCodec ();
359367 opus_decoder_ = std::make_unique<OpusDecoderWrapper>(codec->output_sample_rate (), 1 , OPUS_FRAME_DURATION_MS);
360368 opus_encoder_ = std::make_unique<OpusEncoderWrapper>(16000 , 1 , OPUS_FRAME_DURATION_MS);
361- if (realtime_chat_enabled_ ) {
362- ESP_LOGI (TAG, " Realtime chat enabled , setting opus encoder complexity to 0" );
369+ if (aec_mode_ != kAecOff ) {
370+ ESP_LOGI (TAG, " AEC mode: %d , setting opus encoder complexity to 0" , aec_mode_ );
363371 opus_encoder_->SetComplexity (0 );
364372 } else if (board.GetBoardType () == " ml307" ) {
365373 ESP_LOGI (TAG, " ML307 board detected, setting opus encoder complexity to 5" );
@@ -404,6 +412,11 @@ void Application::Start() {
404412 // Initialize the protocol
405413 display->SetStatus (Lang::Strings::LOADING_PROTOCOL);
406414
415+ // Add MCP common tools before initializing the protocol
416+ #if CONFIG_IOT_PROTOCOL_MCP
417+ McpServer::GetInstance ().AddCommonTools ();
418+ #endif
419+
407420 if (ota_.HasMqttConfig ()) {
408421 protocol_ = std::make_unique<MqttProtocol>();
409422 } else if (ota_.HasWebsocketConfig ()) {
@@ -608,7 +621,7 @@ void Application::Start() {
608621 // Set the chat state to wake word detected
609622 protocol_->SendWakeWordDetected (wake_word);
610623 ESP_LOGI (TAG, " Wake word detected: %s" , wake_word.c_str ());
611- SetListeningMode (realtime_chat_enabled_ ? kListeningModeRealtime : kListeningModeAutoStop );
624+ SetListeningMode (aec_mode_ == kAecOff ? kListeningModeAutoStop : kListeningModeRealtime );
612625 } else if (device_state_ == kDeviceStateSpeaking ) {
613626 AbortSpeaking (kAbortReasonWakeWordDetected );
614627 } else if (device_state_ == kDeviceStateActivating ) {
@@ -1002,3 +1015,30 @@ void Application::SendMcpMessage(const std::string& payload) {
10021015 }
10031016 });
10041017}
1018+
1019+ void Application::SetAecMode (AecMode mode) {
1020+ aec_mode_ = mode;
1021+ Schedule ([this ]() {
1022+ auto & board = Board::GetInstance ();
1023+ auto display = board.GetDisplay ();
1024+ switch (aec_mode_) {
1025+ case kAecOff :
1026+ audio_processor_->EnableDeviceAec (false );
1027+ display->ShowNotification (Lang::Strings::RTC_MODE_OFF);
1028+ break ;
1029+ case kAecOnServerSide :
1030+ audio_processor_->EnableDeviceAec (false );
1031+ display->ShowNotification (Lang::Strings::RTC_MODE_ON);
1032+ break ;
1033+ case kAecOnDeviceSide :
1034+ audio_processor_->EnableDeviceAec (true );
1035+ display->ShowNotification (Lang::Strings::RTC_MODE_ON);
1036+ break ;
1037+ }
1038+
1039+ // If the AEC mode is changed, close the audio channel
1040+ if (protocol_ && protocol_->IsAudioChannelOpened ()) {
1041+ protocol_->CloseAudioChannel ();
1042+ }
1043+ });
1044+ }
0 commit comments