I have been working on voice assistant with an ESP32. Got it working but I get static through the speaker, on startup, until I get the voice reply. After that the static/noise goes away. I have attached a schematic of the wiring.
So I think I fixed this by changing a few configurations and wiring.
Power the MAX98357A with 5V. Under-powering can cause distortion. It is best to power with an external power supply and not with the VCC of the ESP32. However, I’m powering mine via VCC and it is working fine now. This help to clear up the distortion while playing the wav.
Reduce the gain to 3db. This help to clear up the distortion while playing the wav. 3dB if a 100K resistor is connected between GAIN and Vin
This is the one that removed the startup noise. I’m not sure if I’m doing this 100% correctly but it is working well. There is a voltage on the pin that i’m using on startup (~1V) and after a wav has been sent it is 0V. I’m using an output configuration to set this low on boot.
Unfortunately your code did not solve my problem, unless there was more to it. Did you need to do anything on the HA side to make this work? I used your code exactly other than changing to the pin I was using. After I loaded the code, everything worked just fine. Then I pulled the plug on the ESP32 and powered back up. After it booted up, the horrible noise resumed until I got it to say something.
esphome:
name: office-va
friendly_name: Office VA
# Automation to perform every time the device boots
on_boot:
priority: 600
then:
- output.turn_off: set_low_speaker
I did add code at startup to turn it off but still no joy. However, I just solved the issue without even adding new code. The bottom line is that this issue depends on which ESP32 dev board you are using AND which pins you use for the amp i/o. I was thinking about using a tiny relay to disconnect the speaker on startup controlled by another pin which would then connect the speaker the first time speech was needed. While thinking about this I thought to check for voltage on another pin on startup and lo and behold I realized that there was none, unlike the pin I was using for the amp! So, I switched to another pin and updated the firmware speaker out pin to the new pin and voila! No noise on startup.
Thanks to @steriku for mentioning the voltage on startup that causes this.
So, if you are experiencing this, grab your voltage meter and find other gpio pins!
While most esp speaker schematics I’ve ever seen only had the i2s_in configuration. What is the point of this, what hardware are you using for this configuration?
Hey Elf,
in the i2s_audio you can declare which pins it should use for input audio, coming from mic, audio-jack or something liike that. the i2s_out tells which pins are used for outgoing audio in our case to the amplifier.
This worked for me. If you end up here like I did trying to follow @tpage’s award-winning Egg project, and get the static on startup, here is the code I used from @Steven_Heffernan applied to the script from here
Thanks for the leg up! I’m using your schematic and code with my own design. The egg looks super cool, but it’s a bit big for my tastes. Here is another option. The wiring is a little tight but works. Printables