A loudspeaker is a coil which sits near a magnet. Varying the current through it causes it to move in the magnetic field. To put the "loud" in loudspeaker, the coil is attached to a cone to move more air.
A motor consists of a set of coils near a magnet. They get pulsed at full power to cause them to move, with the length of time that the power is applied during each pulse varying according to the speed demanded. This causes the air near them to move in sympathy with the pulses of power, which is pretty much the definition of sound. Fortunately, they are not connected to a cone. The frequency used is right in the middle of the human hearing range, so we hear it whistle. Some motors are better at converting the pulses to sound than others. As electronics advance, higher frequencies can be used, which most people cannot hear. This might account for occasional strange behaviour by passing dogs when a boat is running.