mardi 10 février 2015

Displaying and editing sound in wave, python 2.7

I am trying to do the following using the module wave (and not another) in python 2.7:



  • display the spectrum of a wav file

  • add silences to a wav file at the beginning/end


Wave's documentation is rather shallow.


So far I have tried :



def display(filename):
file=wave.open(filename,'r')
freq=file._framerate
n=file._nframes
Y=file.readframes(n)
plt.close()
plt.plot(Y)
plt.show()
file.close()


but it would seem that file.readframes returns binary data, and I don't know how to use that.


For the part where I add silence, I have found some tutorials on how to create sound using wave, but I also need to replicate the old sound as follows :



def addSilence(filename,length);
fileR=wave.open(filename,'r')
fileW=wave.open('_'+filename,'w')

# add silence here to fileW

for i in fileR.readframes(fileR._nframes):
#copy frames from fileR to fileW

fileR.close()
fileW.close()


How should I do it ?


Aucun commentaire:

Enregistrer un commentaire