Voicemail works by monitoring the electromagnetic waves used to carry phone signals. If you’re busy, or your phone is off, the message is stored in a ‘mailbox’, essentially another line to which calls are diverted after a certain time. This mailbox records the exact nature of the electromagnetic wave that was sent, including the differences in volume and frequency in the human voice.
These impulses are then encoded into ASCII, a binary system that renders them into 0s and 1s. Once this is done, the phone is capable of playing it back as a stream of binary data, which includes the frequency and volume of the voice that left the message. When you hit playback, the resonating elements of the phone, including the speaker itself, use that stream of binary code to re-create the voice call for you to listen to.