没有合适的资源?快使用搜索试试~ 我知道了~
首页对python中Librosa的mfcc步骤详解
1.对语音数据归一化 如16000hz的数据,会将每个点/32768 2.计算窗函数:(*注意librosa中不进行预处理) 3.进行数据扩展填充,他进行的是镜像填充(”reflect”) 如原数据为 12345 -》 填充为4的,左右各填充4 即:5432123454321 即:5432-12345-4321 4.分帧 5.加窗:对每一帧进行加窗, 6.进行fft傅里叶变换 librosa中fft计算,可以使用.net中的System.Numerics MathNet.Numerics.IntegralTransforms.Fourier.Forward(FFT_frame, Fourier
资源详情
资源评论
资源推荐

对对python中中Librosa的的mfcc步骤详解步骤详解
1.对语音数据归一化对语音数据归一化
如16000hz的数据,会将每个点/32768
2.计算窗函数:(计算窗函数:(*注意注意librosa中不进行预处理)中不进行预处理)
3.进行数据扩展填充,他进行的是镜像填充(进行数据扩展填充,他进行的是镜像填充(”reflect”)
如原数据为 12345 -》 填充为4的,左右各填充4 即:5432123454321 即:5432-12345-4321
4.分帧分帧
5.加窗:对每一帧进行加窗,加窗:对每一帧进行加窗,
6.进行进行fft傅里叶变换傅里叶变换
librosa中fft计算,可以使用.net中的System.Numerics
MathNet.Numerics.IntegralTransforms.Fourier.Forward(FFT_frame, FourierOptions.Matlab) 计算,结果相同
7.mel计算(每一帧取计算(每一帧取20个特征点)个特征点)
Imports System.Numerics
Imports MathNet.Numerics
Imports MathNet.Numerics.IntegralTransforms
Module mfcc_module
Public Class Librosa
End Class
Dim pi As Double = 3.1415926535897931
Public Function spectrum(fft_data(,) As Complex) As Double(,)
Dim new_data(fft_data.GetLength(0) - 1, fft_data.GetLength(1) - 1) As Double
For n = 0 To fft_data.GetLength(0) - 1
' Debug.Print("////////////////////////spectrum//////////////////")
' Debug.Print("////////////////////////spectrum//////////////////")
For i = 0 To fft_data.GetLength(1) - 1
new_data(n, i) = fft_data(n, i).MagnitudeSquared
' Debug.Write(new_data(n, i) & " ")
Next
Next
Return new_data
End Function
Public Function FFT(data As Double(,)) As Complex(,)
Dim result(data.GetLength(0) - 1, 1024) As Complex
'2049 加了一个 数组类型 0 开始
Dim FFT_frame As Complex() = New Complex(data.GetLength(1) - 1) {}
For n = 0 To data.GetLength(0) - 1
For i As Integer = 0 To data.GetLength(1) - 1
FFT_frame(i) = data(n, i)
Next
MathNet.Numerics.IntegralTransforms.Fourier.Forward(FFT_frame, FourierOptions.Matlab)
For k = 0 To 1024
result(n, k) = FFT_frame(k)
Next
'Debug.Print("fft **************")
'For Each mem In FFT_frame
' Debug.Print(mem.ToString & " ")

'Next
Next n
Return result
End Function
Public Function _mfcc(dct_ As Double(,), power_to_db_ As Double(,)) As Double(,)
'dct 20,128
'power_to_db 5,128
'result = 20,5
Dim result(dct_.GetLength(0) - 1, power_to_db_.GetLength(1) - 1) As Double
Dim r1, r2 As Double
For n = 0 To dct_.GetLength(0) - 1 '20
For i = 0 To power_to_db_.GetLength(1) - 1 '5
r2 = 0
For k = 0 To dct_.GetLength(1) - 1 '128
r1 = dct_(n, k) * power_to_db_(k, i)
r2 = r2 + r1
Next
result(n, i) = r2
Next
Next
Return result
End Function
Public Function Dct(n_filters As Integer, n_input As Integer) As Double(,)
Dim t1 As Double = 2 * n_input
Dim samples(n_input - 1) As Double
Dim basis(n_filters - 1, n_input - 1) As Double
Dim n As Integer = 1
For i = 0 To n_input - 1
samples(i) = n * pi / (2 * n_input)
n = n + 2
Next i
For i = 0 To n_input - 1
basis(0, i) = 1 / Math.Sqrt(n_input)
Next
For n = 1 To n_filters - 1
For i = 0 To n_input - 1
basis(n, i) = Math.Cos(n * samples(i)) * Math.Sqrt(2 / n_input)
Next
Next
Return basis
End Function
'1e-10 = 0.0000000001
Public Function power_to_db(S As Double(,), Optional ref As Double = 1, Optional admin As Double = 0.0000000001,
Optional top_db As Double = 80) As Double(,)
Dim result(S.GetLength(0) - 1, S.GetLength(1) - 1) As Double
Dim log_spec As Double
For n = 0 To S.GetLength(0) - 1
For i = 0 To S.GetLength(1) - 1
log_spec = 10 * Math.Log10(Math.Max(admin, S(n, i)))
result(n, i) = log_spec - 10 * Math.Log10(Math.Max(admin, ref))
Next
Next

'If top_db <> 0 Then
' For n = 0 To S.GetLength(0) - 1
' For i = 0 To S.GetLength(1) - 1
' 'result(n, i) = Math.Max(result(n, i), result(n, i) - top_db)
' Next
' Next
'End If
Return result
End Function
Public Function melspectrogram(mel_basis(,) As Double, s(,) As Double) As Double(,)
'mel_basis 128,1025
's 5 ,1025 -> 1025,5
' result 128,5
Dim result(mel_basis.GetLength(0) - 3, s.GetLength(0) - 1) As Double
Dim r1, r2 As Double
For n = 0 To mel_basis.GetLength(0) - 3
For i = 0 To s.GetLength(0) - 1
For k = 0 To mel_basis.GetLength(1) - 1
r1 = mel_basis(n, k) * s(i, k)
r2 = r2 + r1
Next
result(n, i) = r2
r2 = 0
Next
Next
Return result
End Function
Public Function normal(mel_f As Double(), weights(,) As Double) As Double(,)
Dim enorm(mel_f.Length - 2) As Double
' Debug.Print("*************normal//////////////")
' Debug.Print("*************normal//////////////")
For i = 0 To mel_f.Length - 3
enorm(i) = 2 / (mel_f(2 + i) - mel_f(i))
Next
For i = 0 To weights.GetLength(1) - 1
For n = 0 To weights.GetLength(0) - 2
weights(n, i) = weights(n, i) * enorm(n)
Next
Next
Return weights
End Function
Public Function weight(a As Double(,), fdiff As Double()) As Double(,)
Dim lower, upper As Double
Dim data(a.GetLength(0) - 1, a.GetLength(1) - 1) As Double
For n = 0 To a.GetLength(0) - 3
For i = 0 To a.GetLength(1) - 1
lower = -(a(n, i) / fdiff(n))
upper = a(n + 2, i) / fdiff(n + 1)
data(n, i) = Math.Max(0, Math.Min(lower, upper))
Next
Next
Return data
End Function
Public Function ramps(A As Double(), B As Double()) As Double(,)
Dim data(A.Length - 1, B.Length - 1) As Double
剩余10页未读,继续阅读




















weixin_38702047
- 粉丝: 3
- 资源: 968
上传资源 快速赚钱
我的内容管理 收起
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助

会员权益专享
安全验证
文档复制为VIP权益,开通VIP直接复制

评论0