So while the audio cable is transmitting electricity into the headphones, it's just wrapped around a magnet instead of having other electric components.
This is a good graphic on them: https://animagraffs.com/loudspeaker/
A microphone is just the reverse: vibrations in the air move the cone and its attached magnet, which induces electrical current in the wire.