From bf527b033147abe29184ee6a0e78e22f4f8c005d Mon Sep 17 00:00:00 2001 From: Kevin Ahrendt Date: Wed, 30 Apr 2025 19:45:33 -0500 Subject: [PATCH] [microphone] Bugfix: protect against starting mic if already started (#8656) --- esphome/components/microphone/microphone_source.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/esphome/components/microphone/microphone_source.cpp b/esphome/components/microphone/microphone_source.cpp index dcd3b31622..35e8d5dd4d 100644 --- a/esphome/components/microphone/microphone_source.cpp +++ b/esphome/components/microphone/microphone_source.cpp @@ -14,12 +14,16 @@ void MicrophoneSource::add_data_callback(std::functionenabled_ = true; - this->mic_->start(); + if (!this->enabled_) { + this->enabled_ = true; + this->mic_->start(); + } } void MicrophoneSource::stop() { - this->enabled_ = false; - this->mic_->stop(); + if (this->enabled_) { + this->enabled_ = false; + this->mic_->stop(); + } } std::vector MicrophoneSource::process_audio_(const std::vector &data) {