How to get the contents of the wav file into array so as to cut the required segment and convert it back to wav format using python?
How to get the contents of the wav file into array so as to cut the required segment and convert it back to wav format using python?? My prob is similar to "ROMANs" prob,i hav seen earlier in the post at this site..
Basically,i want to combine parts of different wav file into one wav file?? if there is ne other apporach thn takin the contents into an array and cuting part and combining and again converting bac? please suggest...
edited:
I prefer unpacking the contents of the wave file into an array and editing by cutting the required segment of sound from the wav file,as i am working on speech processing,and guess this way would be easy to enchance the quality of sound later...
can ne one suggest a w开发者_C百科ay for this?? Plz help..
Thanks in advance.
There are a few libraries you can use for handling media files in general, eg. pymedia. However if all you need is support for simple WAVs, you could probably just use the built-in wave module.
import wave
win= wave.open('sample.wav', 'rb')
wout= wave.open('segment.wav', 'wb')
t0, t1= 1.0, 2.0 # cut audio between one and two seconds
s0, s1= int(t0*win.getframerate()), int(t1*win.getframerate())
win.readframes(s0) # discard
frames= win.readframes(s1-s0)
wout.setparams(win.getparams())
wout.writeframes(frames)
win.close()
wout.close()
精彩评论