我正在使用一种简单的方法在python中使用FFT找出音符 涉及的步骤是:
但是在音符应该是A4 / 440hz的情况下,我得到的变化很大(2K Hz) 我的方法有什么根本性的错误吗?
更新:如何将我的audio.wav文件传递到此frequency estimator?
完整的python代码为here
window_size = 2000 # Size of window to be used for detecting silence
beta = 1 # Silence detection parameter
max_notes = 100 # Maximum number of notes in file, for efficiency
sampling_freq = 44100 # Sampling frequency of audio signal
threshold = 200
# traversing sound_square array with a fixed window_size
while(i<=len(sound_square)-window_size):
s = 0.0
j = 0
while(j<=window_size):
s = s + sound_square[i+j]
j = j + 1
# detecting the silence waves
if s < threshold:
if(i-k>window_size*4):
dft = np.array(dft) # applying fourier transform function
dft = np.fft.fft(sound[k:i])
dft = np.argsort(dft)
if(dft[0]>dft[-1] and dft[1]>dft[-1]):
i_max = dft[-1]
elif(dft[1]>dft[0] and dft[-1]>dft[0]):
i_max = dft[0]
else :
i_max = dft[1]
# claculating frequency
frequency.append((i_max*sampling_freq)/(i-k))
dft = []
k = i+1
i = i + window_size
答案 0 :(得分:0)
对此stackoverflow question的答案包括一些估计音高的替代方法的列表,这些方法可能会产生更好的结果。
答案 1 :(得分:0)
在librosa.piptrack中实现了音高跟踪 https://librosa.github.io/librosa/generated/librosa.core.piptrack.html#librosa.core.piptrack