问题
What's the easiest way to read and write a stereo .wav file in Python ?
Should I use scipy.io.wavfile.read
?
Should I use a 2-dimension array (how ?) in order to have
x[n,j]
wherej
is the channel number?I also want to read/write metadatas stored in the wav file like the
markers
,MIDI root note
(Soundforge, as well as other sound editors, can read/write this specific .wav metadata called "MIDI root note")
Thank you
PS : I already know how to do with a mono file :
from scipy.io.wavfile import read
(fs, x) = read('test.wav')
回答1:
Here is an updated version of scipy.io.wavfile
that adds:
- 24 bit .wav files support for read/write,
- access to cue markers,
- cue marker labels,
- some other metadata like pitch (if defined), etc.
wavfile.py (enhanced)
Old (original) answer: a solution for only a part of the question (ie read stereo samples):
(fs, x) = read('stereo_small-file.wav')
print len(x.shape) # 1 if mono, 2 if stereo
# if stereo, x is a 2-dimensional array, so we can access both channels with :
print x[:,0]
print x[:,1]
回答2:
Take a look at Pythons' wave module
来源:https://stackoverflow.com/questions/19888278/read-and-write-stereo-wav-file-with-python-metadatas