简体   繁体   English

音乐分析和可视化

[英]Music Analysis and Visualization

I'm interested in programming a music visualizer in Python. 我对用Python编写音乐可视化程序感兴趣。

The first problem is how to get the information from the music? 第一个问题是如何从音乐中获取信息? Like volume, frequency, rpm, etc. And from where? 如音量,频率,rpm等。从何而来? From the soundcard or the actual music file? 来自声卡还是实际的音乐文件?

My guess is from the soundcard, but how do I access the soundcard and the wanted information? 我的猜测来自声卡,但是如何访问声卡和所需信息? Preferably in a platform-independed way(Linux is a must). 最好以与平台无关的方式(必须使用Linux)。 I already read a bit about fourier transformation, but I'm not sure if that's the best way to go. 我已经读过一些有关傅立叶变换的信息,但是我不确定这是否是最好的方法。

I thought about using OpenGL for the visualization, but I'm still open for suggestions. 我考虑过使用OpenGL进行可视化,但是我仍然愿意征求建议。

I've already looked at those wikipages, but didn't find an answer yet: http://wiki.python.org/moin/Audio/ 我已经查看了这些Wiki页面,但尚未找到答案: http : //wiki.python.org/moin/Audio/
http://wiki.python.org/moin/PythonInMusic http://wiki.python.org/moin/PythonInMusic

If you are looking for a cross-platform audio library I strongly suggest to use FMOD which just rocks. 如果您正在寻找一个跨平台的音频库,我强烈建议您使用FMOD ,它会摇摆不定 There is also a wrapper to use it in python available (though I've never used it). 还有一个包装器可以在python中使用它(尽管我从未使用过)。
It will provide features like getting the spectrum out-of-the-box. 它将提供开箱即用的频谱等功能。
If you want to analyze audio file, my algorithme de choix is the beat spectrum . 如果要分析音频文件,我的算法拍谱 It computes a similarity matrix by comparing each short sample of the music with every others. 它通过比较每个音乐的简短样本来计算相似度矩阵。 Once the similarity matrix is computed it is possible to get average similarity between every samples pairs {S(T);S(T+1)} for each time interval T: this is the beat spectrum. 一旦计算出相似度矩阵,就有可能获得每个时间间隔T的每个样本对{S(T); S(T + 1)}之间的平均相似度:这是拍谱。
It allows to get the BPM of your audio sequence, but can do much more like identifying different parts of the music, locate transitions between similar samples. 它可以获取音频序列的BPM,但可以做更多的工作,例如识别音乐的不同部分,定位相似样本之间的过渡。 I do not know what you mean exactly by "visualizing audio", but I think this algorithm should provide you with enough information to start synchronizing image to the audio (if that's what you want to do). 我不知道“可视化音频”到底是什么意思,但是我认为该算法应为您提供足够的信息,以开始将图像与音频同步(如果您要这样做)。

Another tool for this is librosa . 另一个工具是librosa It offers Beat tracking to get bpm, in addition to default operations. 除默认操作外,它还提供节拍跟踪以获取bpm。 According to the tutorial, for beat tracking: 根据教程,用于节拍跟踪:

import librosa
audio_path = librosa.util.example_audio_file()
# or uncomment the line below and point it at your favorite song:
# audio_path = '/path/to/your/favorite/song.mp3'
y, sr = librosa.load(audio_path)
y_percussive = librosa.effects.hpss(y)
tempo, beats = librosa.beat.beat_track(y=y_percussive, sr=sr)

As @dionyziz also said , the 正如@dionyziz所说

beats will be in frames. 节拍将在帧中。 You can convert them to actual time using 您可以使用将它们转换为实际时间

 librosa.frames_to_time(beats) 

I have not tried this. 我还没有尝试过。

No longer a good answer since Echo Nest API is no longer available . 由于Echo Nest API不再可用,因此不再是一个好的答案 Leaving for historical reasons only 仅出于历史原因离开

Consider the Echo Nest API which works perfectly with Python and will return information about beats per minute (probably what you want instead of RPM), average amplitude, even "dancibility" for any audio file. 考虑一下与Python完美配合的Echo Nest API,它将返回有关每分钟节拍(可能是您想要的而不是RPM),平均振幅甚至任何音频文件的“可扩展性”的信息。 You need an API key, but besides that it's free and works well. 您需要一个API密钥,但是除此之外,它是免费的并且运行良好。

It also has code for manipulating music as well, via their Echo Nest Remix package. 它还具有通过其Echo Nest Remix程序包处理音乐的代码。 Here's their example code: 这是他们的示例代码:

"""Reverse a song by playing its beats 
   forward starting from the end of the song"""
import echonest.audio as audio   

# Easy around wrapper mp3 decoding and Echo Nest analysis
audio_file = audio.LocalAudioFile("NeverGonnaTellIt.mp3")

# You can manipulate the beats in a song as a native python list
beats = audio_file.analysis.beats
beats.reverse()


# And render the list as a new audio file!
audio.getpieces(audio_file, beats).encode("NeverGonnaTellItBackwardsByBeat.mp3")

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

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