There's been multiple related methods, and now newer digital methods, but the short answer is for analog sound the waveforms were printed on a strip alongside the images. A light shining through that hits a photo sensitive diode, the intensity of the light will vary with the waveform. The diode changes the light signal back into an electronic signal, that varies the same as the audio waveform printed on the film, which then goes to the speakers and is turned into sound.