Python中的音高检测

问题描述 投票:4回答:4

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

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

python signal-processing speech-recognition speech-to-text speech
4个回答
5
投票

您可以尝试以下方法。我相信你知道人声也有超过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))

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


3
投票

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

[1]:Strömbergsson,Sofia。 “今天最常用的F0估计方法,以及它们在清晰言语中评估男女间距的准确性。” INTERSPEECH。 2016.https://pdfs.semanticscholar.org/ff04/0316f44eab5c0497cec280bfb1fd0e7c0e85.pdf

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


2
投票

基本上有两类f0(音调)估计:时域(例如,具有自相关/互相关)和频域(例如,通过测量谐波之间的距离来识别基频,或者以最大值识别频谱中的频率)功率,如上面Sahil M的例子所示。多年来,我成功地使用了RAPT(鲁棒算法用于音高跟踪),这是REAPER的前身,也是David Talkin。您提到的广泛使用的Praat软件还包括类似RAPT的互相关算法选项。网上提供了描述和代码。这里有一个DEB安装档案:http://www.phon.ox.ac.uk/releases使用音调功能进行模式检测(上升,下降等)是一个单独的问题。 Sahil M上面提出的在俯仰功能中使用移动窗口的建议是一个很好的开始。


2
投票

2019年更新,现在有基于神经网络的非常精确的音高跟踪器。而且他们在开箱即用的Python中工作。校验

https://pypi.org/project/crepe/

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

https://github.com/google/REAPER

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

© www.soinside.com 2019 - 2024. All rights reserved.