本文介绍了什么是阅读的WAV文件,最简单的方法使用Python [摘要]?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用Python访问的WAV文件,并写入它的形式,让我来分析它的内容(假设数组)。


  1. 听说AUDIOLAB的是针对(其转换numpy的阵列为WAV和正相反)合适的工具。

  2. 我已经安装了AUDIOLAB的,但我有一个问题,版本numpy的的(我不能,从numpy.testing导入仪)。我有1.1.1。 numpy的版本。

  3. 我已经安装上numpy的(1.4.0)的新版本。但后来我得到了一个新的错误:

    回溯(最近通话最后一个):
      文件test.py,7号线,在
        进口scikits.audiolab
      文件/usr/lib/python2.5/site-packages/scikits/audiolab/init.py25行,在
        从pysndfile进口formatinfo,sndfile
      文件/usr/lib/python2.5/site-packages/scikits/audiolab/pysndfile/init.py,1号线,在
        从_sndfile进口Sndfile,格式,available_file_formats,available_encodings
      文件numpy.pxd,30日线在scikits.audiolab.pysndfile._sndfile(scikits / AUDIOLAB的/ pysndfile / _sndfile.c:9632)
    ValueError错误:numpy.dtype并不似乎是正确的对象类型


  4. 我放弃了使用AUDIOLAB的,以为我可以用潮人包在一个WAV文件读取。我问了一个问题有关,但人们建议改用SciPy的。好吧,我决定把重点放在SciPy的(我有0.6.0。版本)。


  5. 但是,当我试图做到以下几点:

    从scipy.io进口wavfile结果
    X = wavfile.read('的/ usr /共享/声音/紫/ receive.wav')


我收到以下内容:

 回溯(最后最近一次调用):
  文件test3.py,4号线,上述<&模块GT;
    从scipy.io进口wavfile
  文件/usr/lib/python2.5/site-packages/scipy/io/__init__.py23行,上述<&模块GT;
    从numpy.testing进口NumpyTest
导入错误:无法导入名称NumpyTest


  1. 于是,我放弃了使用SciPy的。我可以使用刚刚波包?我并不需要太多。我只需要在人类可读的格式,比WAV文件的内容,我会想出做什么用的。


解决方案

你试过波模块?它有更少的依赖性:

 高清everyOther(V,偏移= 0):
   返回[V [I]为i的范围(偏差,LEN(V),2)]高清wavLoad(FNAME):
   WAV = wave.open(FNAME,R)
   (N沟道,sampwidth,帧率,nframes,则comptype,COMPNAME)= wav.getparams()
   帧= wav.readframes(将为nframes * N沟道)
   OUT = struct.unpack_from(%DH%*将为nframes N沟道,帧)   #2转换到channles数组numpy的
   如果N沟道== 2:
       左=阵列(列表(everyOther(满分,0)))
       右=阵列(列表(everyOther(出,1)))
   其他:
       左=阵列(出)
       右向左=

I want to use Python to access a wav-file and write its content in a form which allows me to analyze it (let's say arrays).

  1. I heard that "audiolab" is a suitable tool for that (it transforms numpy arrays into wav and vica versa).
  2. I have installed the "audiolab" but I had a problem with the version of numpy (I could not "from numpy.testing import Tester"). I had 1.1.1. version of numpy.
  3. I have installed a newer version on numpy (1.4.0). But then I got a new set of errors:

    Traceback (most recent call last): File "test.py", line 7, in import scikits.audiolab File "/usr/lib/python2.5/site-packages/scikits/audiolab/init.py", line 25, in from pysndfile import formatinfo, sndfile File "/usr/lib/python2.5/site-packages/scikits/audiolab/pysndfile/init.py", line 1, in from _sndfile import Sndfile, Format, available_file_formats, available_encodings File "numpy.pxd", line 30, in scikits.audiolab.pysndfile._sndfile (scikits/audiolab/pysndfile/_sndfile.c:9632)ValueError: numpy.dtype does not appear to be the correct type object

  4. I gave up to use audiolab and thought that I can use "wave" package to read in a wav-file. I asked a question about that but people recommended to use scipy instead. OK, I decided to focus on scipy (I have 0.6.0. version).

  5. But when I tried to do the following:

    from scipy.io import wavfile
    x = wavfile.read('/usr/share/sounds/purple/receive.wav')

I get the following:

Traceback (most recent call last):
  File "test3.py", line 4, in <module>
    from scipy.io import wavfile
  File "/usr/lib/python2.5/site-packages/scipy/io/__init__.py", line 23, in <module>
    from numpy.testing import NumpyTest
ImportError: cannot import name NumpyTest
  1. So, I gave up to use scipy. Can I use just wave package? I do not need much. I just need to have content of wav-file in human readable format and than I will figure out what to do with that.
解决方案

Have you tried the wave module? It has fewer dependencies:

http://docs.python.org/library/wave.html

def everyOther (v, offset=0):
   return [v[i] for i in range(offset, len(v), 2)]

def wavLoad (fname):
   wav = wave.open (fname, "r")
   (nchannels, sampwidth, framerate, nframes, comptype, compname) = wav.getparams ()
   frames = wav.readframes (nframes * nchannels)
   out = struct.unpack_from ("%dh" % nframes * nchannels, frames)

   # Convert 2 channles to numpy arrays
   if nchannels == 2:
       left = array (list (everyOther (out, 0)))
       right = array (list  (everyOther (out, 1)))
   else:
       left = array (out)
       right = left

这篇关于什么是阅读的WAV文件,最简单的方法使用Python [摘要]?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-21 05:26