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?
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.