ESP32, ESPHOME and MediaPlayer mostly not playing

can you plz share your pins setup. I am trying to do the same. But some streams are not playing

If just some streams are not play may due to the sample rate.
I’m facing the same issue as it will not play anything after idle for not sure how long.
Once restart it, it can play again.
Tring to add wifi power save mode to none. See if that helps.

I am curious. What kind of bitrate and samplerate are you able to achieve from an ESP32/wDAC? Is it able to play back 24/96 streams? Maybe I have been spending a bit more money on Raspberry Pis with HD-Audio hats (fully integrated in HA via Volumio). Can I can do the same with a $5 ESP32 + DAC. I cannot imagine the quality would be the same however. The Rpi has way more horsepower. Am I wrong?

Yes, the quality is very high. You relly don’t need alot horsepower to decode MP3. I use both use at least 160 kbps, without any issues.

I bet it didn’t help anything. at least it didnt for me. I am still stuck with this. Now using Wrover and enable PSRAM. Still same shit.

That was not the trick. Still the same.

I was more curious about its ability to decode 24/96 FLAC files. This is the format I use to record my huge vinyl LP collection. With a few exceptions, I stopped using mp3s years ago.

Greetings. I am also now realizing my first experiment with esp32, using this instruction My Local Voice Assistant Device With Wake Word In Home Assistant | Smart Home Circle.
I have repeated the circuitry in full accordance with his schematic. According to the principle - if everything works for him, why to be clever and change something. I don’t have anything related to tts yet (I have core version and it’s not so easy to install it all on it), but the functions of media player and beautiful colored lights work successfully. Of course, as always, with some peculiarities.
I also noticed a few times that my smart speaker would freeze up, but that wasn’t the main problem. I couldn’t run music or activate any dynamic program of blinking LEDs, as it caused crackling and interference in the sound. I tried to analyze settings, timings, power supply, to figure out what I was doing wrong. But it turned out to be a matter of circuitry, and I think it affects a lot of things in operation. I have the microphone and amplifier boards soldered with rather short wires, no more than 5 centimeters. But when I moved them and touched them with my hands, these sound distortions disappeared. I came to the point where I soldered an additional wire to the “ground” (minus power supply) and wrapped the signal wires with it, making something like a twisted pair or shielding.
The interference is gone!
What I’m getting at. I had a thought that unstable esp32 operation may be caused by the fact that this interference not only affects the sound, but also the processor itself, leading to failures. I think you should use as short wires as possible, possibly shielded, and generally do the mounting inside the device case taking into account the effects of electromagnetic fields, which will eventually improve wifi radio reception as well.
In the near future I am planning to build a second speaker (in a different cabinet, I use factory satellite speakers from an old home theater), and I will try to take into account the experience in the circuitry. I will try to write about the results, how much it will affect the stability of operation.

2 Likes

Interference is no joke. I banged my head for several days teying to rid my speaker of static and crackling too.
I have been trying to build a new smart speaker that uses esp32 with an amplifier and then also share the amplifier with one of those BT audio receiver’s. This way i could TTS or do announcements from HA but, anyone could pair to the speaker with their phone and use it to play music.

I can use either DAC or BT just fine but, when i put wire them both to the amp I get static and interference!!

Its an annoying problem.

I think a good result would be to use old ide or fdd cables, where each data wire alternates with ground. Or for example, how the cables from motherboard to monitor are arranged in laptops, where shielded twisted pair is used. I think any of us has some old and no longer needed computer hardware, tablets, TVs, etc., which can be used for homemade products. All this breadboard assembly on wires, which is used for arduino DIY, is suitable only for preliminary performance testing and can not be used in working devices. Sometimes this is a serious problem for computer and electronics manufacturers, when they have to change the shape of wires on the PCB to avoid interference and malfunction, and we used to not think about it.
Here, it’s good time to think how to make a good stable working device :slight_smile:

An important note. I have found that many radio stations from the media - radio browser cause esp-speaker to hang or reboot when trying to start a stream. This is because there are different streams mixed in there, but not all the speaker can play (e.g. aac). The same applies to local files, apparently not all mp3 bitrates are played correctly (high bitrate mp3 and flac). Some just won’t play, some will cause speaker to crash:

WARNING speaker-1 @ 192.168.0.228: Connection error occurred: [Errno 104] Connection reset by peer
INFO Processing unexpected disconnect from ESPHome API for speaker-1 @ 192.168.0.228
WARNING Disconnected from API
INFO Successfully connected to speaker-1 @ 192.168.0.228 in 0.005s
INFO Successful handshake with speaker-1 @ 192.168.0.228 in 2.184s
[21:05:41][D][media_player:059]: 'esp_speaker' - Setting
[21:05:41][D][media_player:069]:   Volume: 0.48
[21:05:41][D][light:036]: 'Light' Setting:
[21:05:41][D][light:051]:   Brightness: 50%
[21:05:41][D][light:059]:   Red: 100%, Green: 0%, Blue: 100%
[21:09:57][I][ota:117]: Boot seems successful, resetting boot loop counter.
[21:09:57][D][esp32.preferences:114]: Saving 1 preferences to flash...
[21:09:57][D][esp32.preferences:143]: Saving 1 preferences to flash: 0 cached, 1 written, 0 failed

Now I’ve selected a few tested streams for myself, and the speaker has been working stably without hangs and crashes for the last two days, playing music and some tts during scripted events.
So it looks like the software part itself is working steady, except for the limitations of the capabilities of the esp32 board itself. It’s just something to keep in mind when working with it.

For newbies like me, or those who just haven’t looked into it, let me explain. HomeAssistant does not create an audio stream, it only passes the address of the stream from outside to the speaker, or creates a link to the media file to be played. The same applies to voice assistant messages and other tts events. They are rendering to an audio file, which is saving locally, and then a link to it is passing to the speaker and it plays it. If it can. We can only see the status, like “playing” or “idle”. Unfortunately this is all the available feedback on the status of the speaker at the moment.

I am having the same problem and tried with different pinout. Always the result is the same: starts working but after several minutes or seconds (random) stops working. Then I have to reset it to start working again.
I connected the osciloscope and this is the “i2s_dout_pin” pin when works:

image

and this is when fails (it is just like a square signal):

I am using UDA1334a and same result if is not connected. I think the problem is in the output of the ESP32 board. I am using a ESP32 WROOM devkit c 38 pin.

Му reply in another topic, there is a link to sound sample.

You should be just as good. :wink:

Definitely I think the problem is in the ESPHome firmware. I tried with a ESP32-WROVER and same result: work but it stops working after a couple of minutes. However, I have tried squeezelite-ESP32 and works really well in the WROVER. I can send a mp3 by a homeassistant script for the doorbell and more else:

  • Send Spotify streaming
  • Connect by bluetooth as a common speaker does and send the streaming.

The only thing I’m missing is a homeassistant switch that activates an output pin of the WROVER board

I found how to activate a pin and it is not needed to do it from Home Assistant. Going to NVS editor (enable the tab if it is not visible) and define set_GPIO as “33=amp”. This activates a relay that turns on the speaker. Now squeezelite-ESP32 is perfect for me!

1 Like

Until today very annoying, tts and online radio works only after a esp32 reset

Can you please let me know the GPIOs that you have used to connect esp32-wrover? I am trying to connect this with UDA1334A to use it as 3.5mm audio out but I am not getting it to work.

Hi,
I have one just connected on this way:

WROVER - UDA1334A
pin 25 - DIN
pin 26 - WSEL
pin 27 - BCLK

And configure in the squeezelite interface:

Remeber to reboot the device

Hope it helps.

Thanks for sharing the clear picture and GPIO connection details. I have figured out the hard way and made it but it is same as what you have posted.
I was getting distortions in the output.
After making the changes as shown below the sound is very much clear without any pops or noises. I am not sure it is same at your end or any other better options are there. Finally it is working great beyond my expectations and can enjoy the FLAC formatted songs.

I would like to share an update regarding the media player using I2S. I have created I2S player using esp32 devkit v1 (you can find the pin out details from here. along with UDA1334A DAC successfully. I have used the same pin out as shared by Domaray and referred to this thread with respect to esp32 devkit I2S yaml. It is working fine with the mentioned DAC.

Sharing my yaml for anyone interested to build with esp32devkit v1 and UDA1334A DAC.

esphome:
  name: esp32dvkitbamp
  friendly_name: esp32dvkitbamp

  platform: ESP32
  board: esp32dev

captive_portal:
web_server:
  port: 80

i2s_audio:
  - id: i2s_out
    i2s_lrclk_pin: GPIO26 #WSEL on 1334A
    i2s_bclk_pin: GPIO27 #BCLK on 1334A

media_player:
  - platform: i2s_audio
    name: ESPHome I2S Media Player
    dac_type: external
    i2s_audio_id: i2s_out
    i2s_dout_pin: GPIO25 #DIN on 1334A
    mode: stereo  

sensor:
  - platform: wifi_signal
    name: "WiFi Signal"
    update_interval: 5min

  - platform: uptime
    name: "Uptime"
    update_interval: 5min

  - platform: internal_temperature
    name: "Internal Temperature"    

text_sensor:
  - platform: wifi_info
    ip_address:
      name: IP Address
    ssid:
      name: SSID
    mac_address:
      name: MAC