''' @author: vialard ''' import scipy.io.wavfile as module import wave,struct import numpy as np def Write(file_in,file_out,u): ifile = wave.open(file_in) ofile = wave.open(file_out, "w") (nchannels, sampwidth, framerate, nframes, comptype, compname) = ifile.getparams() print ifile.getparams() ofile.setparams((1, 1, framerate, 0, comptype, compname)) sampwidth = ifile.getsampwidth() fmts = (None, "=B", "=h", None, "=l") fmt = fmts[sampwidth] print fmt dcs = (None, 128, 0, None, 0) dc = dcs[sampwidth] signal = [struct.pack(fmt,x) for x in u] value_str = ''.join(signal) ofile.writeframes(value_str) ofile.close() def Rescale(u): u=u.astype(float) U = (u-np.min(u))/(np.max(u)-np.min(u))*255 return [int(np.ceil(2*y)/2.0) for y in U] def RescaleAndSave(file_in,file_out,u): U = Rescale(u) Write(file_in,file_out,U) if __name__=="__main__": #s1='micro1_1.wav' #s2='micro1_2.wav' s1='file_2.wav' s2='file_1.wav' length,signal = module.read(s1) length2,signal2 = module.read(s2) new_signal = 0.2*signal + 0.5*signal2 RescaleAndSave(s1,'new_signal.wav',new_signal)