I need to read multiple wav files into separate numpy arrays, then merge the numpy arrays into one and save it as a wav file.
How do I do that?
Here is a solution:
from scipy.io.wavfile import read, write
import numpy as np
fs, x = read('test1.wav')
f2, y = read('test2.wav')
#z = x + y # this is to "mix" the 2 sounds, probably not what you want
z = np.concatenate((x, y)) # this will add the sounds one after another
write('out.wav', fs, z)
When doing x + y, if the 2 arrays don't have the same length, you need to zero-pad the shortest array, so that they finally have to same length before summing them.
import glob for f in glob.glob('*.wav'):, it will loop on all sound files in the folder. Search SackOverflow questions about looping on files with Python for further help. Best of luck for your project! You can "accept" this answer with the tick mark if it helped ;)
wavdata docs.scipy.org/doc/scipy-0.14.0/reference/generated/…