Considering the following limited knowledge I have:
- Arduino boards analogWrite really is a PWM and can't output arbitrary voltages like 1.23V or 4.56V. Furthermore, most pins have a max frequency of 500-1000Hz
- Audio range well above 1000Hz
- ESP32 boards have DAC pins that allows outputting arbitrary voltages
- A speaker coil shouldn't be driven by a square wave as it causes too much stress
- A speaker coil shouldn't receive only positive current, otherwise it relies on the diaphragm physical structure to return to its neutral position, which would not return to its neutral position "at the right time", and also not having negative current you can't take advantage of the full speakers movement amplitude and so a weaker sound
- For motors, we switch the rotation direction by reversing current with an H-bridge
Not using any shield, I would play a song using an ESP32's DAC pin. I would "encode" 0V to represent -100% amplitude, 2.5V for 0% and 5V for +100%. However then I don't know how to shift that to ±5V (or ±2.5V) at the speaker's leads. I thought about an H-bridge, but I think it only works with PWM and won't work with arbitrary voltages between 0 to 5.
I would appreciate a schematic showing how I should hook the speaker's leads to the DAC pin, with whatever I would need between. To help me learn, I would like 2 versions, where one would have no amplifying circuit (I mean, I know a pin shouldn't output more than a few mA and that it's not gonna do much for a speaker), so I can at least see what's required to shift voltages in such way.