The ESP32S3 will restart if online music is played

I created two buttons for testing.
If button A3 is pressed, playback is normal, and the ESP32S3 will not restart.

a3 media_url: ‘http://192.168.1.1:8080/static/music.mp3

If you press button A4, the ESP32S3 will restart.
a4 media_url: ‘http://m10.music.126.net/20251106145338/61c9045ca5ef9d5d9177f15d5c162fd4/ymusic/48d9/4013/934e/cb8eb10c6141e33ab5e45033c10c10f2.mp3
(The music link worked when I tested it, but it’s probably inaccessible now.)

Does anyone know what happened?



esphome:
  name: a02
  friendly_name: a02
  platformio_options:
    board_build.flash_mode: dio

esp32:
  board: esp32-s3-devkitc-1
  variant: esp32s3
  flash_size: 16MB
  cpu_frequency: 240MHZ
  framework:
    type: esp-idf
    version: recommended
#    sdkconfig_options:
#      CONFIG_ESP32S3_DEFAULT_CPU_FREQ_240: "y"
#      CONFIG_ESP32S3_DATA_CACHE_64KB: "y"
#      CONFIG_ESP32S3_DATA_CACHE_LINE_64B: "y"
#      CONFIG_ESP32S3_INSTRUCTION_CACHE_32KB: "y"

#      CONFIG_BT_ALLOCATION_FROM_SPIRAM_FIRST: "y"
#      CONFIG_BT_BLE_DYNAMIC_ENV_MEMORY: "y"

#      CONFIG_MBEDTLS_EXTERNAL_MEM_ALLOC: "y"
#      CONFIG_MBEDTLS_SSL_PROTO_TLS1_3: "y"  # TLS1.3 support isn't enabled by default in IDF 5.1.5

logger:
#  level: DEBUG
#  level: VERBOSE
#  level: VERY_VERBOSE


psram:
  mode: octal
  speed: 80MHz

captive_portal:

http_request:

globals:
  - id: now_url
    type: std::string
    restore_value: no

debug:
  update_interval: 10s

sensor:
  - platform: uptime
    name: Uptime
    update_interval: 10s
    
  - platform: debug
    free:
      name: "Heap Free"
    block:
      name: "Heap Max Block"
    loop_time:
      name: "Loop Time"
    psram:
      name: "Free PSRAM"
    cpu_frequency:
      name: "CPU Frequency"


button:
  - platform: factory_reset
    id: factory_reset_btn
    name: Factory reset


  - platform: template
    name: a3
    on_press: 
      then:
        - media_player.play_media:
            id: echo_media_player
            media_url: 'http://192.168.1.1:8080/static/music.mp3'


  - platform: template
    name: a4
    on_press: 
      then:
        - media_player.play_media:
            id: echo_media_player
            media_url: 'http://m10.music.126.net/20251106145338/61c9045ca5ef9d5d9177f15d5c162fd4/ymusic/48d9/4013/934e/cb8eb10c6141e33ab5e45033c10c10f2.mp3'



i2s_audio:
  - id: i2s_audio_bus
    # i2s_output data pin is gpio7
    i2s_lrclk_pin:
      number: GPIO16
    i2s_bclk_pin:
      number: GPIO15

  - id: i2s_audio_mic
    # data line is GPIO6
    i2s_lrclk_pin:
      number: GPIO4
    i2s_bclk_pin:
      number: GPIO5

speaker:
  - platform: i2s_audio
    id: echo_speaker
    i2s_dout_pin: GPIO7
    i2s_audio_id: i2s_audio_bus
    dac_type: external
    sample_rate: 48000
    bits_per_sample: 32bit
    buffer_duration: 1000ms


  - platform: mixer
#    task_stack_in_psram: true
    id: mixer_speaker_id
    output_speaker: echo_speaker
    source_speakers:
      - id: announcement_spk_mixer_input
        buffer_duration: 1000ms
#        timeout: 500ms
#        bits_per_sample: 16
#        num_channels: 1
#        sample_rate: 48000

      - id: media_spk_mixer_input
        buffer_duration: 1000ms
#        timeout: 500ms
#        bits_per_sample: 16
#        num_channels: 1
#        sample_rate: 48000


  - platform: resampler
    id: media_spk_resampling_input
    output_speaker: media_spk_mixer_input
    buffer_duration: 1000ms
#    task_stack_in_psram: True
#    bits_per_sample: 16
#    num_channels: 1
#    sample_rate: 48000



  - platform: resampler
    id: announcement_spk_resampling_input
    output_speaker: announcement_spk_mixer_input
    buffer_duration: 1000ms
#    task_stack_in_psram: false
#    bits_per_sample: 16
#    num_channels: 1
#    sample_rate: 48000


media_player:
  - platform: speaker
    name: None
    id: echo_media_player
    announcement_pipeline:
      speaker: echo_speaker
#      sample_rate: 48000
#      format: WAV
#    codec_support_enabled: false
#    buffer_size: 2000000
    volume_min: 0.4
    volume_max: 0.8
#    task_stack_in_psram: True
    media_pipeline:
      speaker: media_spk_resampling_input
#      format: MP3
#      num_channels: 1
#      sample_rate: 48000


This is information from esphome.

[12:44:46.113][D][button:023]: 'a3' Pressed.
[12:44:46.113][D][media_player:083]: 'a02' - Setting
[12:44:46.115][D][media_player:090]:   Media URL: http://m801.music.126.net/20251106210840/993351aebcc226409ab8f9ae77c69311/jdymusic/obj/wo3DlMOGwrbDjj7DisKw/19529190250/c6df/fd20/58d2/75e9bdd3f516bf7609f8884ba3108aae.mp3
[12:44:46.118][D][media_player:096]:  Announcement: no
[12:44:46.123][D][speaker_media_player:406]: State changed to PLAYING
[12:44:46.287][D][speaker_media_player.pipeline:114]: Reading MP3 file type
[12:44:46.302][D][ring_buffer:034][med_read]: Created ring buffer with size 1000000
[12:44:46.367][D][speaker_media_player.pipeline:124]: Decoded audio has 2 channels, 44100 Hz sample rate, and 16 bits per sample
[12:44:46.383][D][ring_buffer:034]: Created ring buffer with size 192000
[12:44:46.395][D][resampler_speaker:064]: Starting resampler task
[12:44:46.405][D][resampler_speaker:085]: Started resampler task
[12:44:46.411][D][ring_buffer:034][sample]: Created ring buffer with size 176400
[12:44:46.419][D][speaker_mixer:316]: Starting speaker mixer
[12:44:46.428][D][speaker_mixer:324]: Started speaker mixer
[12:44:46.448][D][ring_buffer:034][speaker_task]: Created ring buffer with size 96000
[12:44:46.448][D][i2s_audio.speaker:102]: Starting
[12:44:46.448][D][i2s_audio.speaker:106]: Started

Just a few remarks
Do you use an ESP32-S3 WROOM N16R8 ?
According the psram: section you do.

Also you use a lot of buffers. That takes up a lot of RAM.
Remove a few of them since not all are needed and try to make the remaining one) smaller like 500ms the see if that works

I have only a buffer at speaker:

speaker:
  - platform: i2s_audio
    id: speaker_id
    i2s_audio_id: i2s_out
    dac_type: external
    i2s_dout_pin:   
      number: GPIO8 #DIN Pin of the MAX98357A Audio Amplifier
    sample_rate: 48000
    buffer_duration: 600ms #90ms

  - platform: mixer
    id: mixer_speaker_id
    output_speaker: speaker_id
    source_speakers:
      - id: announcement_spk_mixer_input
      - id: media_spk_mixer_input

  - platform: resampler
    id: media_spk_resampling_input
    output_speaker: media_spk_mixer_input
  - platform: resampler
    id: announcement_spk_resampling_input
    output_speaker: announcement_spk_mixer_input


media_player:
  - platform: speaker
    name: None
    id: speaker_media_player_id
    media_pipeline:
        speaker: media_spk_resampling_input
        num_channels: 1
    announcement_pipeline:
        speaker: announcement_spk_resampling_input
        num_channels: 1

To get that extra bit of memory you need these switches

    sdkconfig_options:
      CONFIG_ESP32S3_DATA_CACHE_64KB: "y"
      CONFIG_ESP32S3_DATA_CACHE_LINE_64B: "y"
      CONFIG_ESP32S3_INSTRUCTION_CACHE_32KB: "y"

      CONFIG_SPIRAM_RODATA: "y"
      CONFIG_SPIRAM_FETCH_INSTRUCTIONS: "y"

      CONFIG_BT_ALLOCATION_FROM_SPIRAM_FIRST: "y"
      CONFIG_BT_BLE_DYNAMIC_ENV_MEMORY: "y"

      CONFIG_MBEDTLS_EXTERNAL_MEM_ALLOC: "y"
      CONFIG_MBEDTLS_SSL_PROTO_TLS1_3: "y" 
1 Like

This works much better, but it still restarts.

Calling action: media_player.play_media in home-assistant makes it run very stably.

My initial idea was to allow ESPHome to play music even without home-assistant.

It seems this idea is a bit too much of a burden for ESP32.

Have you read the docs for tips? The bit about WiFi may be worth reading.

I use esps for media a lot without issues.

Are you sending music to ESPHOME using Home Assistant? This method works stably in my code. I’m trying to push the playback address of a music server directly to ESPHOME for playback, so it doesn’t go through Home Assistant, but I didn’t expect the results to be so poor.

Well, my whole house audio system uses only one esp32-s3 in esphome and it stream internet radio the whole day so it is possible.