From 7f59aff1576d46c954d31da3e5baa19cad44a05c Mon Sep 17 00:00:00 2001 From: Kevin Ahrendt Date: Sun, 11 May 2025 15:50:47 -0500 Subject: [PATCH] [voice_assistant] Bugfix: Properly detect states where mic is running (#8745) --- .../components/voice_assistant/voice_assistant.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/esphome/components/voice_assistant/voice_assistant.cpp b/esphome/components/voice_assistant/voice_assistant.cpp index d35717ef91..1aafea7d85 100644 --- a/esphome/components/voice_assistant/voice_assistant.cpp +++ b/esphome/components/voice_assistant/voice_assistant.cpp @@ -695,12 +695,12 @@ void VoiceAssistant::on_event(const api::VoiceAssistantEventResponse &msg) { } case api::enums::VOICE_ASSISTANT_RUN_END: { ESP_LOGD(TAG, "Assist Pipeline ended"); - if ((this->state_ == State::STARTING_PIPELINE) || (this->state_ == State::AWAITING_RESPONSE)) { - // Pipeline ended before starting microphone - // Or there wasn't a TTS start event ("nevermind") - this->set_state_(State::IDLE, State::IDLE); - } else if (this->state_ == State::STREAMING_MICROPHONE) { - this->ring_buffer_->reset(); + if ((this->state_ == State::START_PIPELINE) || (this->state_ == State::STARTING_PIPELINE) || + (this->state_ == State::STREAMING_MICROPHONE)) { + // Microphone is running, stop it + this->set_state_(State::STOP_MICROPHONE, State::IDLE); + } else if (this->state_ == State::AWAITING_RESPONSE) { + // No TTS start event ("nevermind") this->set_state_(State::IDLE, State::IDLE); } this->defer([this]() { this->end_trigger_->trigger(); });