librosa
是一个应用广泛的音频处理python库。
在 librosa
中有一个方法叫做 stft
,功能是求音频的短时傅里叶变换, librosa.stft
返回是一个矩阵
短时傅立叶变换(STFT),返回一个复数矩阵使得D(f,t)
- 当调用的形式是
np.abs( stft() )
, 代表的是取, 取出复数矩阵的实部,即频率的振幅。 - 当调用的形式是
np.angle( stft() )
, 代表的是取, 取出复数矩阵的虚部,即频率的相位。
This function returns a complex-valued matrix D such that
–np.abs(D[f, t])
is the magnitude of frequency binf
at framet
, and
–np.angle(D[f, t])
is the phase of frequency binf
at framet
.The integers
t
andf
can be converted to physical units by means
of the utility functionsframes_to_sample
andfft_frequencies
.
librosa.stft
函数
librosa.stft(y, n_fft=2048, hop_length=None, win_length=None, window='hann', center=True, pad_mode='reflect')
参数:
- y:音频时间序列
- n_fft:FFT窗口大小,n_fft=hop_length+overlapping
- hop_length:帧移,如果未指定,则默认win_length / 4。
- win_length:每一帧音频都由window()加窗。窗长win_length,然后用零填充以匹配N_FFT。默认win_length=n_fft。
- window:字符串,元组,数字,函数 shape =(n_fft, )
窗口(字符串、元组或数字)[En]
Window (string, tuple, or number)
窗函数,例如scipy.signal.hanning
长度为n_fft的向量或数组 - center:bool
如果为True,则填充信号y,以使帧 D [:, t]以y [t * hop_length]为中心。
如果为False,则D [:, t]从y [t * hop_length]开始 - dtype:D的复数值类型。默认值为64-bit complex复数
- pad_mode:如果center = True,则在信号的边缘使用填充模式。默认情况下,STFT使用reflection padding。
返回:
STFT矩阵,shape = (1+ n f f t 2 \frac{n_{fft}}{2}2 n ff t , n f r a m e s n_{frames}n f r am es )
- stft的输出帧数
音频经过短时傅里叶变换后,取其幅值即可得到音频的线性谱。
[En]
After the short-time Fourier transform of audio, the linear spectrum of audio can be obtained by taking the amplitude of audio.
对线性谱进行mel刻度的加权求和,可以得到语音识别和语音合成中常用的mel谱。
短时傅立叶变换的过程是先将音频分割成帧,然后再对每一帧进行单独变换。
[En]
The process of short-time Fourier transform is to divide the audio into frames first, and then transform each frame separately.
在应用stft方法求解短时傅里叶变换时,发现求出的特征帧的数目有点反常。
比如我有一个长度是400个点的音频,如果帧长是100,那么我自然而然的想到,最后应当得到4帧。
但事实并非如此,实际的帧数量是5帧。这真是太神奇了。
[En]
But this is not the case, the actual number of frames is 5 frames. That’s kind of magical.
分析了一下,原因如下。
为了方便讨论,假设帧长为200,帧移为100,fft size是200。
上图中是一条长度为430的音频,在经过stft后,输出5帧。
过程是这样的。
- 在音频的左右两侧padding,padding size是fft size的一半
- 现在音频长度变成了430 + 200 = 630
- 总帧数为(630 – 100) // 100
- 如上图示意,最后得到5帧
所以,librosa求stft的输出帧数,当音频长度在400
Original: https://blog.csdn.net/chumingqian/article/details/124843635
Author: mingqian_chu
Title: librosa 语音库(二)STFT 的实现
原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/527065/
转载文章受原作者版权保护。转载请注明原作者出处!