Read and write stereo .wav file with python + meta

2019-06-03 05:30发布

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] where j 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')

2条回答
ゆ 、 Hurt°
2楼-- · 2019-06-03 05:53

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]
查看更多
等我变得足够好
3楼-- · 2019-06-03 06:03
登录 后发表回答