diff --git a/CMakeLists.txt b/CMakeLists.txt index efe6e354..aa8e55b4 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,7 +4,7 @@ # CMakeLists in this exact order for cmake to work correctly cmake_minimum_required(VERSION 3.16) -set(PROJECT_VER "1.3.1") +set(PROJECT_VER "1.4.0") # Add this line to disable the specific warning add_compile_options(-Wno-missing-field-initializers) diff --git a/main/application.cc b/main/application.cc index 755f6698..01b9cc56 100644 --- a/main/application.cc +++ b/main/application.cc @@ -236,18 +236,18 @@ void Application::PlaySound(const std::string_view& sound) { } void Application::ToggleChatState() { - Schedule([this]() { - if (device_state_ == kDeviceStateActivating) { - SetDeviceState(kDeviceStateIdle); - return; - } + if (device_state_ == kDeviceStateActivating) { + SetDeviceState(kDeviceStateIdle); + return; + } - if (!protocol_) { - ESP_LOGE(TAG, "Protocol not initialized"); - return; - } + if (!protocol_) { + ESP_LOGE(TAG, "Protocol not initialized"); + return; + } - if (device_state_ == kDeviceStateIdle) { + if (device_state_ == kDeviceStateIdle) { + Schedule([this]() { SetDeviceState(kDeviceStateConnecting); if (!protocol_->OpenAudioChannel()) { return; @@ -256,28 +256,32 @@ void Application::ToggleChatState() { keep_listening_ = true; protocol_->SendStartListening(kListeningModeAutoStop); SetDeviceState(kDeviceStateListening); - } else if (device_state_ == kDeviceStateSpeaking) { + }); + } else if (device_state_ == kDeviceStateSpeaking) { + Schedule([this]() { AbortSpeaking(kAbortReasonNone); - } else if (device_state_ == kDeviceStateListening) { + }); + } else if (device_state_ == kDeviceStateListening) { + Schedule([this]() { protocol_->CloseAudioChannel(); - } - }); + }); + } } void Application::StartListening() { - Schedule([this]() { - if (device_state_ == kDeviceStateActivating) { - SetDeviceState(kDeviceStateIdle); - return; - } + if (device_state_ == kDeviceStateActivating) { + SetDeviceState(kDeviceStateIdle); + return; + } - if (!protocol_) { - ESP_LOGE(TAG, "Protocol not initialized"); - return; - } - - keep_listening_ = false; - if (device_state_ == kDeviceStateIdle) { + if (!protocol_) { + ESP_LOGE(TAG, "Protocol not initialized"); + return; + } + + keep_listening_ = false; + if (device_state_ == kDeviceStateIdle) { + Schedule([this]() { if (!protocol_->IsAudioChannelOpened()) { SetDeviceState(kDeviceStateConnecting); if (!protocol_->OpenAudioChannel()) { @@ -286,23 +290,25 @@ void Application::StartListening() { } protocol_->SendStartListening(kListeningModeManualStop); SetDeviceState(kDeviceStateListening); - } else if (device_state_ == kDeviceStateSpeaking) { + }); + } else if (device_state_ == kDeviceStateSpeaking) { + Schedule([this]() { AbortSpeaking(kAbortReasonNone); protocol_->SendStartListening(kListeningModeManualStop); // FIXME: Wait for the speaker to empty the buffer vTaskDelay(pdMS_TO_TICKS(120)); SetDeviceState(kDeviceStateListening); - } - }); + }); + } } void Application::StopListening() { - Schedule([this]() { - if (device_state_ == kDeviceStateListening) { + if (device_state_ == kDeviceStateListening) { + Schedule([this]() { protocol_->SendStopListening(); SetDeviceState(kDeviceStateIdle); - } - }); + }); + } } void Application::Start() { @@ -794,10 +800,14 @@ void Application::WakeWordInvoke(const std::string& wake_word) { } }); } else if (device_state_ == kDeviceStateSpeaking) { - AbortSpeaking(kAbortReasonNone); + Schedule([this]() { + AbortSpeaking(kAbortReasonNone); + }); } else if (device_state_ == kDeviceStateListening) { - if (protocol_) { - protocol_->CloseAudioChannel(); - } + Schedule([this]() { + if (protocol_) { + protocol_->CloseAudioChannel(); + } + }); } }