我最终为此使用了Sound Viewer Tool,尽管是另一种语言(Python)和另一个类的项目。如果将以下内容添加到svt.py中:
def processWav(filename, channel):
"""
filename: path to a wav file
Channel: 1 for left, 2 for right
Returns centroids, frequencies, volumes
"""
#open file
audio_file = audiolab.sndfile(filename, 'read')
#should be length of audiofile in seconds * 60. will fix this later
import contextlib
import wave
with contextlib.closing(wave.open(filename, 'r')) as f:
frames = f.getnframes()
rate = f.getframerate()
duration = frames/float(rate)
duration *= 30 #30 data points for every second of audio yay
duration = int(duration) #can only return an integer number of frames so yeah
#print duration
#Not really samples per pixel but I'll let that slide
samples_per_pixel = audio_file.get_nframes()/float(duration)
#some rule says this frequency has to be half of the sample rate
nyquist_freq = (audio_file.get_samplerate()/2) + 0.0
#fft_size stays 4096
processor = AudioProcessor(audio_file, 2048, channel, numpy.hanning)
centroids = []
frequencies = []
volumes = []
for x in range(duration):
seek_point = int(x * samples_per_pixel)
next_seek_point = int((x + 1) * samples_per_pixel)
(spectral_centroid, db_spectrum) = processor.spectral_centroid(seek_point)
peaks = processor.peaks(seek_point, next_seek_point)
centroids.append(spectral_centroid)
frequencies.append(db_spectrum)
volumes.append(peaks)
#print "Centroids:" + str(centroids)
#print "Frequencies:" + str(frequencies)
#print "Volumes:" + str(volumes)
#convert volumes[] from peaks to actual volumes
for i in range(len(volumes)):
volumes[i] = abs(volumes[i][0]) + abs(volumes[i][1])
#round frequencies to save resources
for i in range(len(frequencies)):
for j in range(len(frequencies[i])):
frequencies[i][j] = round(frequencies[i][j], 4)
return centroids, frequencies, volumes
分析可以很容易地用wav文件完成。质心表示音乐的音色 - 频率的加权平均值,它们表示任何时间点的整体亮度。
第一个答案here对我理解FFT /信号处理/数字声音表示非常有帮助。