tags:

views:

334

answers:

3

I am using python programming language,I want to join to wav file one at the end of other wav file? I have a Question in the forum which suggest how to merge two wav file i.e add the contents of one wav file at certain offset,but i want to join two wav file at the end of each other...

And also i had a prob playing the my own wav file,using winsound module..I was able to play the sound but using the time.sleep for certain time before playin any windows sound,disadvantage wit this is if i wanted to play a sound longer thn time.sleep(N),N sec also,the windows sound wil jst overlap after N sec play the winsound nd stop..

Can anyone help??please kindly suggest to how to solve these prob...

Thanks in advance

+1  A: 

You could use audiolab:

import audiolab, scipy
a, fs, enc = audiolab.wavread('file1.wav')
b, fs, enc = audiolab.wavread('file2.wav')
c = scipy.vstack((a,b))
audiolab.wavwrite(c, 'file3.wav', fs, enc)
Steve
do i need to install any package for using scipy...I am using a python2.6 can i get a compatible version for download if i have to..can u provide me the link please..i tried to frm scipy site itself bt faced sme prob..if ne there steps fot installation please suggest..Thank u for the answer..Do u know how to play the sound,i mentioned my prob wit playin,any measure fr that??
kaushik
Python 2.6 is fine, and the Numpy/Scipy website should also be fine. I might let others answer your questions and provide further suggestions. Although my answer does work, there are probably more elegant, direct solutions.
Steve
Ahh..thanks,ne ways my other prob about playin wav files are solved now..
kaushik
I tried installation of audiolab from scikits which is about a size of 1.4 mb and was succesfully installed,but when running ur code it says import error: no module named audiolab..i didnt install the 44mb scipy package is that the prob,do i need to instal that also or the audioalab download itself is incorrect
kaushik
I installed Scipy too but stil says import error..I am using window downloaded both and installed later..stil there prob what mmay b d reason..
kaushik
A: 

i use the SOX [1] library and then call it like

>>> import subprocess
>>> sound_output_path = /tmp
>>> sox_filenames = ['file.wav', 'file1.wav']
>>> subprocess.call(['sox'] + sox_filenames + ['%s/out.wav' % sound_output_path])

[1] http://sox.sourceforge.net/

+3  A: 

Python ships with the wave module that will do what you need. The example below works when the details of the files (mono or stereo, frame rates, etc) are the same:

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()
tom10