Read and write stereo .wav file with python + metadatas

橙三吉。 提交于 2020-01-03 02:22:13

问题


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')

回答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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!