Python中的音高检测

时间:2015-09-15 20:52:32

标签: python signal-processing speech-recognition speech-to-text speech

我正在研究的程序的概念是一个Python模块,它检测某些频率(人类语音频率80-300hz),并通过检查数据库显示句子的语调。我使用SciPy绘制声音文件的频率,但我无法设置任何特定频率以分析音高。我怎么能这样做?

更多信息:我希望能够在语音中设置定义的模式(例如Rising,Falling),程序会检测声音文件是否遵循特定模式。

4 个答案:

答案 0 :(得分:4)

您可以尝试以下方法。我确定你知道人声也有超过300赫兹的谐波。不过,您可以在音频文件中移动一个窗口,并尝试查看最大值(如下所示)或窗口中的一组频率的功率变化。下面的代码是为了给出直觉:

import scipy.fftpack as sf
import numpy as np
def maxFrequency(X, F_sample, Low_cutoff=80, High_cutoff= 300):
        """ Searching presence of frequencies on a real signal using FFT
        Inputs
        =======
        X: 1-D numpy array, the real time domain audio signal (single channel time series)
        Low_cutoff: float, frequency components below this frequency will not pass the filter (physical frequency in unit of Hz)
        High_cutoff: float, frequency components above this frequency will not pass the filter (physical frequency in unit of Hz)
        F_sample: float, the sampling frequency of the signal (physical frequency in unit of Hz)
        """        

        M = X.size # let M be the length of the time series
        Spectrum = sf.rfft(X, n=M) 
        [Low_cutoff, High_cutoff, F_sample] = map(float, [Low_cutoff, High_cutoff, F_sample])

        #Convert cutoff frequencies into points on spectrum
        [Low_point, High_point] = map(lambda F: F/F_sample * M, [Low_cutoff, High_cutoff])

        maximumFrequency = np.where(Spectrum == np.max(Spectrum[Low_point : High_point])) # Calculating which frequency has max power.

        return maximumFrequency

voiceVector = []
for window in fullAudio: # Run a window of appropriate length across the audio file
    voiceVector.append (maxFrequency( window, samplingRate))

现在根据语音的语调,最大功率频率可能会移位,您可以注册并映射到给定的语调。这可能不一定总是如此,你可能必须一起监视很多频率的变化,但这应该让你开始。

答案 1 :(得分:2)

基本上,f0(音调)估计分为两类:时域(例如,具有自相关/互相关)和频域(例如,通过测量谐波之间的距离来确定基频,或者在如上例中的Sahil M)所示。 多年来,我已经成功地使用了同样是REAPER的前身的RAPT(用于音高跟踪的鲁棒算法),也是David Talkin的作品。您提到的广泛使用的Praat软件还包括类似RAPT的互相关算法选项。描述和代码可在网上轻松获得。您可以在以下位置找到DEB安装归档文件:http://www.phon.ox.ac.uk/releases 使用音调功能进行模式检测(上升,下降等)是一个单独的问题。萨希尔·M(Sahil M)的上述建议是在音调函数上使用移动窗口,这是一个很好的开始。

答案 2 :(得分:2)

有许多不同的算法来估计音高,但是一项研究发现Praat的算法是最准确的[1]。最近,Parselmouth库使从Python [2]调用Praat函数变得更加容易。

[1]:索非亚的Strömbergsson。 “当今最常用的F0估计方法,以及它们在干净语音中估计男女音调的准确性。”演讲。 2016. https://pdfs.semanticscholar.org/ff04/0316f44eab5c0497cec280bfb1fd0e7c0e85.pdf

[2]:https://github.com/YannickJadoul/Parselmouth

答案 3 :(得分:1)

音高检测是一个复杂的问题,最新的Google软件包为这项非常重要的任务提供了高度智能的解决方案:

https://github.com/google/REAPER

如果要从Python访问它,可以将其包装在Python中。