Slide 22
Slide 22 text
THIS’LL BE EASY
import wave
import audioop
sound1 = wave.open(“talking.wav”, “rb”)
sound2 = wave.open(“music.wav”, “rb”)
out_f = wave.open(“this_will_totally_work.WAV”, “wb”)
sound1_frames = sound1.getnframes()
sound2_frames = sound2.getnframes()
sound1_data = sound1.readframes(sound1_frames)
sound2_data = sound2.readframes(sound2_frames)
sound2_data_converted, _ = audioop.ratecv(
sound2_data,
sound2.getsampwidth(),
sound2.getnchannels(),
sound2.getframerate(),
sound1.getframerate(),
None
)
out_f.setparams(sound1.getparams())
out_f.setnframes(sound1_frames + sound2_frames)
out_f.writeframes(sound1_data)
out_f.writeframes(sound2_data_converted)
out_f.close()