From f86637cf1cfd272597e72f42f9e15f36f4bae68e Mon Sep 17 00:00:00 2001 From: Xiaoxia Date: Fri, 8 Aug 2025 15:39:12 +0800 Subject: [PATCH] fix: codec unexpectedly closed by timer after open (#1046) Co-authored-by: Xiaoxia --- main/audio/audio_service.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/main/audio/audio_service.cc b/main/audio/audio_service.cc index aae61749..d64bac58 100644 --- a/main/audio/audio_service.cc +++ b/main/audio/audio_service.cc @@ -152,8 +152,9 @@ void AudioService::Stop() { bool AudioService::ReadAudioData(std::vector& data, int sample_rate, int samples) { if (!codec_->input_enabled()) { - codec_->EnableInput(true); + esp_timer_stop(audio_power_timer_); esp_timer_start_periodic(audio_power_timer_, AUDIO_POWER_CHECK_INTERVAL_MS * 1000); + codec_->EnableInput(true); } if (codec_->input_sample_rate() != sample_rate) { @@ -287,8 +288,9 @@ void AudioService::AudioOutputTask() { lock.unlock(); if (!codec_->output_enabled()) { - codec_->EnableOutput(true); + esp_timer_stop(audio_power_timer_); esp_timer_start_periodic(audio_power_timer_, AUDIO_POWER_CHECK_INTERVAL_MS * 1000); + codec_->EnableOutput(true); } codec_->OutputData(task->pcm);