function varargout = speackerrecon(varargin)
% SPEACKERRECON MATLAB code for speackerrecon.fig
% SPEACKERRECON, by itself, creates a new SPEACKERRECON or raises the existing
% singleton*.
%
% H = SPEACKERRECON returns the handle to a new SPEACKERRECON or the handle to
% the existing singleton*.
%
% SPEACKERRECON('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in SPEACKERRECON.M with the given input arguments.
%
% SPEACKERRECON('Property','Value',...) creates a new SPEACKERRECON or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before speackerrecon_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to speackerrecon_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 speackerrecon
% Last Modified by GUIDE v2.5 03-Jun-2018 09:17:45
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @speackerrecon_OpeningFcn, ...
'gui_OutputFcn', @speackerrecon_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 speackerrecon is made visible.
function speackerrecon_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 speackerrecon (see VARARGIN)
% Choose default command line output for speackerrecon
global sc Fs1 t1 myRecording4 t2 Nmn Nm name1 j ii name2 mode55 mode44
mode55=0;
mode44=0;
ii=1;
if isempty(get(handles.edit3,'string'))
name1=cell(10);
name2=cell(10);
else
name1=cell(1,str2double(get(handles.edit3,'string')));
name2=cell(1,str2double(get(handles.edit3,'string')));
end
j=1;
sc='';
set(handles.listbox1,'string',num2str(sc),'fontsize',10);
handles.output = hObject;
A='请设置需要进行说话人识别和训练的参数:';
B='设置完成请点击开始按钮进行语音识别模板库的录音:';
C='请注意以下几点:';
D='①可以自定义模板库:需要数量与设置的数量一致;';
E='②注意模板文件的录音间隔为3秒;';
F='③录取过程中如果出错需要全部重新录取,因此尽量不要出错;';
G='④自定义的文件需要保存在当前目录的设置的文件夹下面,比如:njh+数字.wav的形式。';
sc=[sc,A,10];
sc=[sc,B,10];
sc=[sc,C,10];
sc=[sc,D,10];
sc=[sc,E,10];
sc=[sc,F,10];
sc=[sc,G,10];
set(handles.listbox1,'string',num2str(sc),'fontsize',10,'fontname','KaiTi');
h = handles.figure1; %返回其句柄
newIcon = javax.swing.ImageIcon('iconcumt.jpg');
figFrame = get(h,'JavaFrame'); %取得Figure的JavaFrame。
figFrame.setFigureIcon(newIcon);
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes speackerrecon wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = speackerrecon_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 selection change in listbox1.
function listbox1_Callback(hObject, eventdata, handles)
% hObject handle to listbox1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns listbox1 contents as cell array
% contents{get(hObject,'Value')} returns selected item from listbox1
% --- Executes during object creation, after setting all properties.
function listbox1_CreateFcn(hObject, eventdata, handles)
% hObject handle to listbox1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: listbox controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit6_Callback(hObject, eventdata, handles)
% hObject handle to edit6 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit6 as text
% str2double(get(hObject,'String')) returns contents of edit6 as a double
% --- Executes during object creation, after setting all properties.
function edit6_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit6 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in pushbutton5.
function pushbutton5_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global sc Fs1 t1 myRecording4 t2 Nmn Nm name1 j ii name2
t2=str2double(get(handles.edit5,'string'));
Fs1=16000;
n=1;
recObj = audiorecorder(Fs1,16,n);
start='开始录取待识别语音';
set(handles.edit6,'string',num2str(start));
recordblocking(recObj, t2); %保存5秒
set(handles.edit6,'string','');
end1='结束录音';
set(handles.edit6,'string',num2str(end1));
myRecording4 = getaudiodata(recObj);
% --- Executes on button press in pushbutton6.
function pushbutton6_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton6 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global Nmn Nm sc name1 name2 mode55 mode44 myRecording4 ref
hh='正在计算模板的参数....';
sc=[sc,hh,10];
set(handles.listbox1,'string',num2str(sc),'fontsize',10,'fontname','KaiTi');
x=myRecording4;
axes(handles.axes1);
plot(myRecording4);
set(handles.text7,'string','待测说话人识别的信号');
%audiowrite('2.wav',myRecording4,8000);
%[x,fs8]=audioread('2.wav');
Nmn=str2double(get(handles.edit2,'string'));
Nm=str2double(get(handles.edit3,'string'));
M=Nmn;
N=Nm;
[x1,x2]=vad(x);
x=x(x1*80:x2*80,:);
m=mfcc(x);
test.mfcc=m;
di='正在进行模板匹配...';
sc=[sc,di,10];
set(handles.listbox1,'string',num2str(sc),'fontsize',10,'fontname','KaiTi');
dist=zeros(1,N);
for i=1:M
for j=1:N
dist(i,j)=dtw(test.mfcc,ref(j,i).mfcc);
end
end
dis='匹配距离为:';
%dg=num2str(dist);
bhj='正在计算模板匹配结果....';
sc=[sc,dis,10];
sc=[sc,bhj,10];
set(handles.listbox1,'string',num2str(sc),'fontsize',10,'fontname','KaiTi');
if mode44==1
for i=1:M
[d,j]=min(dist(i,:));
if d>=8000
fpri='测试模板中不存在匹配的人';
sc=[sc,fpri,10];
set(handles.listbox1,'string',num2str(sc),