It is not the Arduino that is damaged it is the speaker itself that will be damaged, that is what makes it a crappy circuit. The speaker should be connected to the collector of the transistor through a large capacitor to keep the DC out of it.
D.C. in a speaker pushes out the cone in a fixed direction, this pushes the coil against the end stop and damages the coil. Also it limits the movement of the coil to the zero position with zero current to the end stop, the coil ( and so the cone ) never goes to the end of the travel. Passing the signal through a capacitor removes that DC component and allows the cone to move either side of the end point.
However any current for the coil has to pass through a resistor from the collector of the transistor to the supply voltage. This cause it to waste a lot of power, in fact 75% of the power is wasted, and more is wasted due to the fact that a capacitor acts like an AC resistor who’s resistance changes with with the inverse frequency. That is at DC the resistance is very very high and drops off as the frequency increases, but in effect it is still absorbing power making it even less efficient.
If you put an analogue signal through this amplifier it would be even worse, it only works at all because you are feeding it with a square wave, so the transistor is either on or off.so that amplifier is even more rubbish with signals other than a square wave.