本文介绍了导入声音文件到Python作为numpy的阵列(替代AUDIOLAB)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用进口在过去的声音文件,和它的工作相当不错。但是:

I've been using Audiolab to import sound files in the past, and it worked quite well. However:


  • 它不支持某些格式,如MP3,因为基础libsndfile 之下,作者是绕不解决它

  • It doesn't support some formats, like mp3, because the underlying libsndfile refuses to support them
  • It doesn't work in Python 2.6 under Windows, and the author is not around to fix it

-

In [2]: from scikits import audiolab
--------------------------------------------------------------------

ImportError                               Traceback (most recent call last)

C:\Python26\Scripts\<ipython console> in <module>()

C:\Python26\lib\site-packages\scikits\audiolab\__init__.py in <module>()
     23 __version__ = _version
     24
---> 25 from pysndfile import formatinfo, sndfile
     26 from pysndfile import supported_format, supported_endianness, \
     27                       supported_encoding, PyaudioException, \

C:\Python26\lib\site-packages\scikits\audiolab\pysndfile\__init__.py in <module>()
----> 1 from _sndfile import Sndfile, Format, available_file_formats, available_encodings
      2 from compat import formatinfo, sndfile, PyaudioException, PyaudioIOError
      3 from compat import supported_format, supported_endianness, supported_encoding

ImportError: DLL load failed: The specified module could not be found.``

所以我想要么:


  • 弄明白为何它不是在2.6的工作(有毛病_sndfile.pyd?),也许找到一个方法来扩展它不支持的格式工作

  • 找到了AUDIOLAB的完整的替代

推荐答案

AUDIOLAB的为我工作在Ubuntu 9.04与Python 2.6.2,所以它可能是一个Windows的问题。在你的链接到论坛上,笔者还认为,这是一个Windows错误。

Audiolab is working for me on Ubuntu 9.04 with Python 2.6.2, so it might be a Windows problem. In your link to the forum, the author also suggests that it is a Windows error.

在过去,这个选项很适合我,太:

In the past, this option has worked for me, too:

from scipy.io import wavfile
fs, data = wavfile.read(filename)

只是要注意,数据可能已 INT 数据类型,所以它不是在[1,1缩放)。例如,如果数据 INT16 ,你必须把数据 2 ** 15 来内部扩展[-1,1)。

Just beware that data may have int data type, so it is not scaled within [-1,1). For example, if data is int16, you must divide data by 2**15 to scale within [-1,1).

这篇关于导入声音文件到Python作为numpy的阵列(替代AUDIOLAB)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 13:42