From cdce59f7f95f0c13e997d73a5784d2a41bf0fc9e Mon Sep 17 00:00:00 2001 From: Kevin Ahrendt Date: Sun, 11 May 2025 00:27:50 -0500 Subject: [PATCH] [i2s_audio] Fix: Slot bit-width for ESP32 variant (#8738) --- .../components/i2s_audio/speaker/i2s_audio_speaker.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/esphome/components/i2s_audio/speaker/i2s_audio_speaker.cpp b/esphome/components/i2s_audio/speaker/i2s_audio_speaker.cpp index b287177016..d85409f1a8 100644 --- a/esphome/components/i2s_audio/speaker/i2s_audio_speaker.cpp +++ b/esphome/components/i2s_audio/speaker/i2s_audio_speaker.cpp @@ -629,7 +629,16 @@ esp_err_t I2SAudioSpeaker::start_i2s_driver_(audio::AudioStreamInfo &audio_strea std_slot_cfg = I2S_STD_MSB_SLOT_DEFAULT_CONFIG((i2s_data_bit_width_t) audio_stream_info.get_bits_per_sample(), slot_mode); } +#ifdef USE_ESP32_VARIANT_ESP32 + // There seems to be a bug on the ESP32 (non-variant) platform where setting the slot bit width higher then the bits + // per sample causes the audio to play too fast. Setting the ws_width to the configured slot bit width seems to + // make it play at the correct speed while sending more bits per slot. + if (this->slot_bit_width_ != I2S_SLOT_BIT_WIDTH_AUTO) { + std_slot_cfg.ws_width = static_cast(this->slot_bit_width_); + } +#else std_slot_cfg.slot_bit_width = this->slot_bit_width_; +#endif std_slot_cfg.slot_mask = slot_mask; pin_config.dout = this->dout_pin_;