简体   繁体   English

从* .wav文件中提取振幅列表以用于Python

[英]Extracting an amplitude list from *.wav file for use in Python

I'm having a little bit of programing and conversion trouble. 我在编程和转换方面有点麻烦。 I'm designing an AI to recognize notes played by instruments and need to extract the raw sound data from a wave file. 我正在设计一种AI,以识别乐器演奏的音符,并且需要从wave文件中提取原始声音数据。 My objective is to perform a FFT operation over chunks of time in the file for use by the AI. 我的目标是对文件中的大部分时间执行FFT操作,以供AI使用。 For this I need an amplitude list of the audio file, but I can't seem to find a conversion technique that will work. 为此,我需要音频文件的振幅列表,但似乎找不到能够起作用的转换技术。 The files start as MP3's and then I convert them to wav file, but I always end up with a compressed file that spits out gibberish when I try to read it. 这些文件以MP3开头,然后将它们转换为wav文件,但是我总是以压缩文件结尾,当我尝试读取该文件时会吐出乱码。 Does anyone know how I might convert the wav file to something that would be compatible with Python's wave module or even something that would directly convert the data into an amplitude list? 有谁知道我如何将wav文件转换为与Python的wave模块兼容的文件,甚至直接将数据转换为幅度列表的文件?

The default Python wave module isn't very thorough. 默认的Python wave模块不是很完整。 You might try the one included in scipy as an alternative. 您可以尝试使用scipy中包含的替代方法。

Check out: Reading *.wav files in Python 检出: 在Python中读取* .wav文件

If you're going to do any numerical heavy lifting with the audio, scipy might be your best option anyway. 如果您打算对音频进行任何数值繁重的操作,那么scipy可能是您的最佳选择。

I believe Python can read .dat files. 我相信Python可以读取.dat文件。 You can use SoX to turn mp3s or wavs or whatever into .dat files that are simply a text list of "time - Left amp - Right amp" 您可以使用SoX将mp3或wav或其他格式转换为.dat文件,这些文件只是“时间-左放大器-右放大器”的文本列表

The code is simply sox soundfile.mp3 soundfile.dat 代码就是sox soundfile.mp3 soundfile.dat

http://sox.sourceforge.net/ http://sox.sourceforge.net/

Sox is command line - I run it with Terminal on my mac, but anything that understands Bash or Linux commands should work depending on what cpu you're using. Sox是命令行-我在Mac上使用Terminal来运行它,但是任何了解Bash或Linux命令的东西都可以工作,具体取决于您所使用的cpu。

Hope that helps! 希望有帮助!

You might want to look at Pure Data too, it's got some nice FFT transforms built into an intuitive graphical programming language. 您可能也想看看Pure Data,它在直观的图形编程语言中内置了一些不错的FFT转换。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM