【语音识别】基于matlab GUI BP神经网络0到10数字语音识别【含Matlab源码 672期】
一、BP神经网络语音识别简介
1 对语音的WAV文件和LAB文件进行处理,产生十个文件,每个文件对应于一个数字,存贮着该数字的波形文件。(shujuzhengli.m)
2 分别利用上面十个文件训练出十个HMM模板,具体方法是:首先将语音的波形文件分帧,以128个点为一帧,帧为64,每一帧通过mfcc.m计算出13个系数,随着波形的长度不同,一个语音文件可以计算得到13N个系数,截取1315的矩阵(mfcc系数)用作训练数据。一般一个HMM模板用20组mfcc系数训练,得到初始状态分布、状态转移矩阵、高斯正态分布的均值和方差以及混合矩阵,这就是该语音的特征,存贮下来,识别的时候使用。(trainmfcc.m)
3 识别过程
识别的前面部分与训练相似,都是要计算得到mfcc系数,不同在于,识别时,将计算得到的mfcc 参数分别代入训练得到的HMM模板求出概率,比较出最大概率者,则该模板对应的数字就是识别的数字。(shibiesb.m)
4 用大量语音文件做测试,结果正确率为90 以上。
二、部分源代码
clc
clear
k = 11;
data_matrix=[];%保存训练数据
data_matrix2=[];%保存测试数据
%载入训练数据,并提取特征
T_train=[];
T_test=[];
for i=0:9
for j=10:50
s = sprintf('09517/%i%i.wav',i,j);%把格式化的数据写入某个字符串中
[s1 fs1] = audioread(s);%读取
v = mfcc(s1, fs1);%提取特征参数
a= vqlbg(v, k); %量化
data_matrix=[data_matrix,a(:)];
T_train=[T_train,i+1];
end
end
%载入测试数据,并提取特征
for i=0:9
for j=51:99
s = sprintf('09517/%i%i.wav',i,j);
[s1 fs1] = audioread(s);
v = mfcc(s1, fs1);
a= vqlbg(v, k);
data_matrix2=[data_matrix2,a(:)];
T_test=[T_test,i+1];
end
end
%样本的标签
% P_train=mapminmax(data_matrix,0,1)';%归一
[P_train,settings] = mapminmax(data_matrix,0,1);
[P_test]=mapminmax(data_matrix2,'aply',settings);%归一
Tn_train=BP(T_train');
Tn_test=BP(T_test');
P_train=P_train;
P_test=P_test;
net=newff(minmax(P_train),[200,10],{'tansig' 'tansig'} ,'traingda');%建立一个神经网络框架
net.trainParam.show=500;
%训练网络
net.trainParam.lr=0.5;
net.trainParam.epochs=25000; %训练次数取5000
net.trainParam.goal=0.01; %误差门限取0.001
net=train(net,P_train,Tn_train); %训练神经网络
YY=sim(net,P_train);
[maxi,ypred]=max(YY);
maxi=maxi';
ypred=ypred';
CC=ypred-T_train';
n=length(find(CC==0));
Accuracytrain=n/size(P_train,2)%算识别的标签和真实的标签不一样的个数,从而计算出正确率
YY=sim(net,P_test);
[maxi,ypred]=max(YY);
maxi=maxi';
ypred=ypred';
CC=ypred-T_test';
n=length(find(CC==0));
Accuracytest=n/size(P_test,2)
function varargout = yuyinshibie(varargin)
% YUYINSHIBIE M-file for yuyinshibie.fig
% YUYINSHIBIE, by itself, creates a new YUYINSHIBIE or raises the existing
% singleton*.
%
% H = YUYINSHIBIE returns the handle to a new YUYINSHIBIE or the handle to
% the existing singleton*.
%
% YUYINSHIBIE('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in YUYINSHIBIE.M with the given input arguments.
%
% YUYINSHIBIE('Property','Value',...) creates a new YUYINSHIBIE or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before yuyinshibie_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to yuyinshibie_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help yuyinshibie
% Last Modified by GUIDE v2.5 08-Aug-2017 22:59:02
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @yuyinshibie_OpeningFcn, ...
'gui_OutputFcn', @yuyinshibie_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before yuyinshibie is made visible.
function yuyinshibie_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to yuyinshibie (see VARARGIN)
% Choose default command line output for yuyinshibie
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes yuyinshibie wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = yuyinshibie_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
global str;
global s1;
global fs1;
[filename,pathname]=...
uigetfile({'*.wav';'*.bmp';'*.gif'},'choose');
str=[pathname filename];
[s1 fs1] = wavread(str);%读取
% a=imread(str);
% 同学在这里写上进度条的代码 等待对话框
h=waitbar(0,'Pleast waiting, reading...');
axes(handles.axes1);
plot(s1)
waitbar(1,h,'finish');
pause(0.05);
delete(h);
function [x1,x2,FrameInc,amp,zcr] = vad(x)
%幅度归一化到[-1,1]
x = double(x);
x = x / max(abs(x));
%常数设置
FrameLen = 240;
FrameInc = 80;
amp1 = 10;
amp2 = 2;
zcr1 = 10;
zcr2 = 5;
maxsilence = 8; % 6*10ms = 30ms
minlen = 15; % 15*10ms = 150ms
status = 0;
count = 0;
silence = 0;
%计算过零率
tmp1 = enframe(x(1:end-1), FrameLen, FrameInc);
tmp2 = enframe(x(2:end) , FrameLen, FrameInc);
signs = (tmp1.*tmp2)<0;
diffs = (tmp1 -tmp2)>0.02;
zcr = sum(signs.*diffs, 2);
%计算短时能量
amp = sum(abs(enframe(filter([1 -0.9375], 1, x), FrameLen, FrameInc)), 2);
%调整能量门限
amp1 = min(amp1, max(amp)/4);
amp2 = min(amp2, max(amp)/8);
%开始端点检测
x1 = 0;
x2 = 0;
for n=1:length(zcr)
goto = 0;
switch status
case {0,1} % 0 = 静音, 1 = 可能开始
if amp(n) > amp1 % 确信进入语音段
x1 = max(n-count-1,1);
status = 2;
silence = 0;
count = count + 1;
elseif amp(n) > amp2 | ... % 可能处于语音段
zcr(n) > zcr2
status = 1;
count = count + 1;
else % 静音状态
status = 0;
count = 0;
end
case 2, % 2 = 语音段
if amp(n) > amp2 | ... % 保持在语音段
zcr(n) > zcr2
count = count + 1;
else % 语音将结束
silence = silence+1;
if silence < maxsilence % 静音还不够长,尚未结束
count = count + 1;
elseif count < minlen % 语音长度太短,认为是噪声
status = 0;
silence = 0;
count = 0;
else % 语音结束
status = 3;
end
end
case 3,
break;
end
end
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
- 100
- 101
- 102
- 103
- 104
- 105
- 106
- 107
- 108
- 109
- 110
- 111
- 112
- 113
- 114
- 115
- 116
- 117
- 118
- 119
- 120
- 121
- 122
- 123
- 124
- 125
- 126
- 127
- 128
- 129
- 130
- 131
- 132
- 133
- 134
- 135
- 136
- 137
- 138
- 139
- 140
- 141
- 142
- 143
- 144
- 145
- 146
- 147
- 148
- 149
- 150
- 151
- 152
- 153
- 154
- 155
- 156
- 157
- 158
- 159
- 160
- 161
- 162
- 163
- 164
- 165
- 166
- 167
- 168
- 169
- 170
- 171
- 172
- 173
- 174
- 175
- 176
- 177
- 178
- 179
- 180
- 181
- 182
- 183
- 184
- 185
- 186
- 187
- 188
- 189
- 190
- 191
- 192
- 193
- 194
- 195
- 196
- 197
- 198
- 199
- 200
- 201
- 202
- 203
- 204
- 205
- 206
- 207
- 208
- 209
- 210
- 211
- 212
- 213
- 214
- 215
- 216
- 217
- 218
- 219
- 220
- 221
- 222
- 223
- 224
- 225
- 226
- 227
- 228
- 229
- 230
三、运行结果
四、matlab版本及参考文献
1 matlab版本
2014a
2 参考文献
[1]韩纪庆,张磊,郑铁然.语音信号处理(第3版)[M].清华大学出版社,2019.
[2]柳若边.深度学习:语音识别技术实践[M].清华大学出版社,2019.
文章来源: qq912100926.blog.csdn.net,作者:海神之光,版权归原作者所有,如需转载,请联系作者。
原文链接:qq912100926.blog.csdn.net/article/details/115387717
- 点赞
- 收藏
- 关注作者
评论(0)