开发者

Music Analysis and Visualization

开发者 https://www.devze.com 2023-03-13 07:29 出处:网络
I\'m interested in programming a music visualizer in Python. The first problem is how to get the information from the music? Like volume, frequency, rpm, etc.

I'm interested in programming a music visualizer in Python.

The first problem is how to get the information from the music? Like volume, frequency, rpm, etc. And from where? 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). I already read a bit about fourier transformation, but I'm not sure if that's the best way to go.

I thought abou开发者_如何学Pythont using OpenGL for the visualization, but I'm still open for suggestions.

I've already looked at those wikipages, but didn't find an answer yet: http://wiki.python.org/moin/Audio/

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. There is also a wrapper to use it in python available (though I've never used it).
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.
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. 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. It offers Beat tracking to get bpm, in addition to default operations. 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

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. 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. You need an API key, but besides that it's free and works well.

It also has code for manipulating music as well, via their Echo Nest Remix package. 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")
0

精彩评论

暂无评论...
验证码 换一张
取 消