I am trying to set up a universal speaker system using an ESP32 with I2S audio output, connected to the MAX98357 audio amplifier and an 8 Ohm, 1W speaker. I want to play any audio (like radio or music) via Home Assistant.
However, when I try to play audio, the configuration compiles successfully, but no sound is produced, even though the screen updates. The shared GPIO pin 46, which is used by both the screen and the audio, needs to be in the HIGH state for the audio to work, but I’m not sure what I might be missing. Any advice would be appreciated!
When I try to play audio in Radio Browser, this is what I see in the ESPHome logs.
[17:41:52.281][D][media_player:090]: Media URL: https://zvukipro.com/uploads/files/2021-07/1627104739_21071.mp3
[17:41:52.920][D][main:447]: Media playing!
[17:41:52.920][D][media_player:083]: 'Lilka Speaker' - Setting
[17:41:52.920][D][media_player:093]: Volume: 1.00
[17:41:52.920][D][main:447]: Media playing!
[17:41:52.920][D][media_player:083]: 'Lilka Speaker' - Setting
[17:41:52.920][D][media_player:093]: Volume: 1.00
[17:41:52.920][D][main:447]: Media playing!
[17:41:52.920][D][media_player:083]: 'Lilka Speaker' - Setting
[17:41:52.920][D][media_player:093]: Volume: 1.00
[17:41:52.920][D][main:447]: Media playing!
[17:41:52.920][D][media_player:083]: 'Lilka Speaker' - Setting
[17:41:52.920][D][media_player:093]: Volume: 1.00
[17:41:52.920][D][main:447]: Media playing!
INFO Processing unexpected disconnect from ESPHome API for lilka @ 192.168.31.229
WARNING Disconnected from API
INFO Successfully resolved lilka @ 192.168.31.229 in 0.002s
INFO Successfully connected to lilka @ 192.168.31.229 in 0.009s
INFO Successful handshake with lilka @ 192.168.31.229 in 0.062s
[17:42:00.719][I][lvgl:000]: lv_obj_update_layout: Layout update begin (in lv_obj_pos.c line #314)
[17:42:00.723][I][lvgl:000]: lv_obj_update_layout: Layout update begin (in lv_obj_pos.c line #314)
[17:42:05.719][I][lvgl:000]: lv_obj_update_layout: Layout update begin (in lv_obj_pos.c line #314)
I’m not 100% sure if this is the last working version (I’m currently rebuilding the station), but I think with these settings I was able to output radio and sound files from the media folder via the ESP.
esp32:
board: esp32dev
framework:
type: esp-idf
version: recommended
.
.
.
i2s_audio:
- id: i2s_out
i2s_lrclk_pin: GPIO22 #LRC an MAX98357A
i2s_bclk_pin: GPIO23 #BCL an MAX98357A
.
.
.
speaker:
- platform: i2s_audio
id: marvin_speaker
dac_type: external
i2s_audio_id: i2s_out
i2s_dout_pin: GPIO18
channel: mono
sample_rate: 16000 #Defaults to 16000
bits_per_sample: 16bit #One of 8bit, 16bit, 24bit, or 32bit. Defaults to 16bit.
media_player:
- platform: speaker
name: "Marvin Media Player"
id: marvin_media_player
buffer_size: 10000 #Must be between 4000 and 4000000. Defaults to 100000
codec_support_enabled: true # set to flase to save and specify format to save recources
announcement_pipeline:
speaker: marvin_speaker
# format: MP3 # One of FLAC, MP3, WAV, or NONE.
num_channels: 1
[19:19:07.982][D][speaker_media_player:406]: State changed to ANNOUNCING
[19:19:07.988][D][speaker_media_player.pipeline:114]: Reading FLAC file type
[19:19:07.995][D][ring_buffer:034][ann_read]: Created ring buffer with size 10000
[19:19:08.688][I][lvgl:000]: lv_obj_update_layout: Layout update begin (in lv_obj_pos.c line #314)
[19:19:09.378][D][sensor:131]: 'Battery Level': Sending state 83.60835 % with 0 decimals of accuracy
[19:19:12.293][D][sensor:131]: 'Battery Voltage': Sending state 4.00463 V with 2 decimals of accuracy
[19:19:13.272][D][speaker_media_player.pipeline:124]: Decoded audio has 1 channels, 16000 Hz sample rate, and 16 bits per sample
[19:19:13.279][D][i2s_audio.speaker:102]: Starting
[19:19:13.284][D][i2s_audio.speaker:111]: Stopping
[19:19:13.298][D][i2s_audio.speaker:116]: Stopped
[19:19:13.298][E][i2s_audio.speaker:130]: Not enough memory
[19:19:13.326][D][i2s_audio.speaker:102]: Starting
[19:19:13.333][D][i2s_audio.speaker:111]: Stopping
[19:19:13.347][D][i2s_audio.speaker:116]: Stopped
[19:19:13.348][E][i2s_audio.speaker:130]: Not enough memory
[19:19:13.626][E][i2s_audio.speaker:158]: Task failed to start, retrying in 1 second
[19:19:13.626][I][lvgl:000]: lv_obj_update_layout: Layout update begin (in lv_obj_pos.c line #314)
[19:19:14.391][E][component:342]: i2s_audio.speaker cleared Error flag
[19:19:14.412][D][i2s_audio.speaker:102]: Starting
[19:19:14.417][D][i2s_audio.speaker:111]: Stopping
[19:19:14.435][D][i2s_audio.speaker:116]: Stopped
[19:19:14.439][E][i2s_audio.speaker:130]: Not enough memory
[19:19:14.466][D][esp-idf:000]: E (167297) i2s_common: i2s_alloc_dma_desc(509): allocate DMA buffer failed
[19:19:23.939][D][esp-idf:000]: E (167305) i2s_std: i2s_std_set_slot(111): allocate memory for dma descriptor failed
[19:19:24.719][E][component:342]: i2s_audio.speaker cleared Error flag
[19:19:24.736][E][i2s_audio.speaker:158]: Task failed to start, retrying in 1 second
[19:19:24.809][E][component:314]: i2s_audio.speaker set Error flag: unspecified
[19:19:25.752][E][component:342]: i2s_audio.speaker cleared Error flag
[19:19:25.768][E][i2s_audio.speaker:158]: Task failed to start, retrying in 1 second
[19:19:25.778][E][component:314]: i2s_audio.speaker set Error flag: unspecified
[19:19:26.785][E][component:342]: i2s_audio.speaker cleared Error flag
[19:19:26.804][E][i2s_audio.speaker:158]: Task failed to start, retrying in 1 second
[19:19:26.810][E][component:314]: i2s_audio.speaker set Error flag: unspecified
Have you set the buffer_size:? The default setting is so large that it usually doesn’t work. Radio streaming works with a smaller buffer. For sound files, they mustn’t be too large (i.e., smaller than the buffer size).
What ESP32-S3 board do you have? How much flash memory and PSRAM does it have?
4 SPI buses (2 of which are user-accessible)
2 I2S buses
2 I2C buses
3 UART buses
Could it be due to the use of LVGL and several codecs simultaneously?
i2s_audio:
- id: i2s_out
i2s_lrclk_pin: GPIO1 #LRC an MAX98357A
i2s_bclk_pin: GPIO42 #BCL an MAX98357A
speaker:
- platform: i2s_audio
id: lilka_speaker
dac_type: external
i2s_audio_id: i2s_out
i2s_dout_pin: GPIO2
channel: mono
sample_rate: 16000 #Defaults to 16000
bits_per_sample: 16bit #One of 8bit, 16bit, 24bit, or 32bit. Defaults to 16bit.
media_player:
- platform: speaker
name: "Lilka Media Player"
id: lilka_media_player
buffer_size: 10000 #Must be between 4000 and 4000000. Defaults to 100000
codec_support_enabled: true # set to flase to save and specify format to save recources
announcement_pipeline:
speaker: lilka_speaker
# format: MP3 # One of FLAC, MP3, WAV, or NONE.
num_channels: 1