I saw a post that joined two .wav files together, but I was wondering how can I join multiple .wav files using python? I am using python 3.6.0. If anyone has a way to do this please teach me. I saw that the other post ask for joining 2 .wav files and with that I used this code form the comments there:
import wave
infiles = ["sound_1.wav", "sound_2.wav"]
outfile = "sounds.wav"
data= []
for infile in infiles:
w = wave.open(infile, 'rb')
data.append( [w.getparams(), w.readframes(w.getnframes())] )
w.close()
output = wave.open(outfile, 'wb')
output.setparams(data[0][0])
output.writeframes(data[0][1])
output.writeframes(data[1][1])
output.close()
I want to read my .wav files from a path then join it as one. I was thinking that after I add the first 2 .wav files I would delete them and just keep joining and deleting until only one .wav file remains like this:
file:
sound1.wav
sound2.wav
sound3.wav
code:
sound1.wav + sound2.wav = sound4.wav
file:
sound3.wav
sound4.wav
code:
sound4.wav + sound3.wav = sound5.wav
file:
sound5.wav
I just don't know how to code this. I am new to coding with python and I am not that good with coding programming languages in general. Thanks in advances.
Use module like pydub
#!/usr/bin/env python
from pydub import AudioSegment
sound1 = AudioSegment.from_wav("filename01.wav")
sound2 = AudioSegment.from_wav("filename02.wav")
sound3 = AudioSegment.from_wav("filename03.wav")
combined_sounds = sound1 + sound2 + sound3
combined_sounds.export("joinedFile.wav", format="wav")
来源:https://stackoverflow.com/questions/52698558/how-to-join-multiple-wav-files-with-python