基于VQ矢量量化的说话人识别(应用于门禁识别)

1.功能演示

1.添加说话人
2.删除说话人
3.识别说话人,如果是系统内人员,显示开锁,如果是系统外人员,则不予开锁
算法准确率96%以上。

在这里插入图片描述
录制不全,只能显示30s ~_~!

2.核心matlab代码

部分核心代码

function varargout = User_Desktop(varargin)
% USER_DESKTOP MATLAB code for User_Desktop.fig
%      USER_DESKTOP, by itself, creates a new USER_DESKTOP or raises the existing
%      singleton*.
%
%      H = USER_DESKTOP returns the handle to a new USER_DESKTOP or the handle to
%      the existing singleton*.
%
%      USER_DESKTOP('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in USER_DESKTOP.M with the given input arguments.
%
%      USER_DESKTOP('Property','Value',...) creates a new USER_DESKTOP or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before User_Desktop_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to User_Desktop_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 User_Desktop

% Last Modified by GUIDE v2.5 29-May-2021 18:10:12

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @User_Desktop_OpeningFcn, ...
                   'gui_OutputFcn',  @User_Desktop_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 User_Desktop is made visible.相当于初始化
function User_Desktop_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 User_Desktop (see VARARGIN)


% Choose default command line output for User_Desktop
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes User_Desktop wait for user response (see UIRESUME)
% uiwait(handles.figure1);
axes(handles.pic2);        %在axes3中绘制
x = imread('./state/关锁1.jpeg');
imshow(x);





% --- Outputs from this function are returned to the command line.
function varargout = User_Desktop_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;



function edit1_Callback(hObject, eventdata, handles)
% hObject    handle to edit1 (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 edit1 as text
%        str2double(get(hObject,'String')) returns contents of edit1 as a double


% --- Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit1 (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 selection change in listbox2.
function listbox2_Callback(hObject, eventdata, handles)
% hObject    handle to listbox2 (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 listbox2 contents as cell array
%        contents{get(hObject,'Value')} returns selected item from listbox2


% --- Executes during object creation, after setting all properties.
function listbox2_CreateFcn(hObject, eventdata, handles)
% hObject    handle to listbox2 (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


% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)reate
%输出状态
set(handles.result,'String','当前正在生成VQ码表,请耐心等待  ~~~');%将strh的值传递给静态文本
pause(0.5)

new_create_vq_books
%显示结果
set(handles.result,'String','VQ码表生成完毕,请 选择语音文件并点击测试  ~~~');%将strh的值传递给静态文本




% --- Executes on button press in btn_test.
function btn_test_Callback(hObject, eventdata, handles)
% hObject    handle to btn_test (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global filename
s=filename
[val,pos,mel]=new_vq_speaker_test;
threshold_value=60;     %阈值,主要是区别系统内还是系统外人员,如果超过阈值,则判别为系统外人员
                        %此处在使用过程中可进行调整
hhh=val/size(mel,2)
%判断是否是系统内人员
if val/size(mel,2)>=threshold_value
    set(handles.result_name,'String','');%将strh的值传递给静态文本
    set(handles.result,'String','该用户还未录入系统,尚无开锁权限!');%将strh的值传递给静态文本
    axes(handles.pic2);        %在axes3中绘制
    x = imread('./state/关锁1.jpeg');
    imshow(x);
else
    %拆分字符串,获取语音文件对应的说话人
    names=strsplit(s,'\');
    name=strsplit(char(names(length(names))),'_');
    name=char(name(1));
    name=strsplit(name,'ID');
    label=char(name(2));
    label=str2num(label);
    %
    if(label==pos)
        %检测结果正确
        set(handles.result_name,'String',pos);%将strh的值传递给静态文本
        set(handles.result,'String','识别正确,开锁~~~');%将strh的值传递给静态文本
        axes(handles.pic2);        %在axes3中绘制
        x = imread('./state/开锁1.jpeg');
        imshow(x);
    else
        %检测结果错误
        fprintf('%d',threshold_value)
        set(handles.result,'String','识别错误,不予开锁  ~~~');%将strh的值传递给静态文本
        axes(handles.pic2);        %在axes3中绘制
        x = imread('./state/关锁1.jpeg');
        imshow(x);
    end    
end




% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
%删除train中的某个说话人某个文件
global filename
delete(filename)
%删除 test内的该说话人的所有文件

names=strsplit(filename,'train\');
ID=strsplit(char(names(2)),'.wav');
ID=char(ID(1));

%并将对应的test文件复制到test文件夹内
test_dir='./data/test/';
find_test_filename=[test_dir,ID,'_*.wav'];
hhh=dir(find_test_filename);
namePositiveCell={hhh.name};%读取指定文件夹下的所有符合格式要求的文件名元胞
for i=1:length(namePositiveCell)
    test_name=[test_dir,char(namePositiveCell{i})];
    delete(test_name)
end

set(handles.result,'String',['删除说话人:', ID ,'   并删除对应测试文件!  ~~~']);%将strh的值传递给静态文本



% --- Executes on button press in btn_clear_text.
function btn_clear_text_Callback(hObject, eventdata, handles)
% hObject    handle to btn_clear_text (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)



% --- Executes on button press in btn_clear_pic.
function btn_clear_pic_Callback(hObject, eventdata, handles)
% hObject    handle to btn_clear_pic (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)



function train_path_Callback(hObject, eventdata, handles)
% hObject    handle to train_path (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 train_path as text
%        str2double(get(hObject,'String')) returns contents of train_path as a double


% --- Executes during object creation, after setting all properties.
function train_path_CreateFcn(hObject, eventdata, handles)
% hObject    handle to train_path (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





function test_path_Callback(hObject, eventdata, handles)
% hObject    handle to test_path (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 test_path as text
%        str2double(get(hObject,'String')) returns contents of test_path as a double


% --- Executes during object creation, after setting all properties.
function test_path_CreateFcn(hObject, eventdata, handles)
% hObject    handle to test_path (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 btn_play.
function btn_play_Callback(hObject, eventdata, handles)
% hObject    handle to btn_play (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
%获取文本框内的文件名称
name=get(handles.wav_name,'string');

%获取全局变量
global filename
global Y
global FS

%读取音频文件
[Y,FS]=audioread(filename);
times=1:length(Y);
times=times/FS;

%绘制语音波形图
axes(handles.pic1);        %在axes2中绘制
plot(Y)
title('信号时域波形图')
xlabel('采样值')
ylabel('振幅')
axis([0 length(Y) .8*min(Y) 1.2*max(Y)])

%播放音频文件
sound(Y,FS)


% --- Executes on button press in btn_pause.
function btn_pause_Callback(hObject, eventdata, handles)
% hObject    handle to btn_pause (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
clear sound


% --- Executes on button press in btn_read_wav.
function btn_read_wav_Callback(hObject, eventdata, handles)
% hObject    handle to btn_read_wav (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global filename;
[Fnameh,Pnameh]=uigetfile('./data/all_data/train/*.wav');%Fnameh显示的文件名称,Pnameh显示的文件路径
filename=[Pnameh,Fnameh];%存储文件的路径及名称
%拆分字符串,获取语音文件对应的说话人
names=strsplit(filename,'data\');

if ~isempty(strfind(filename,'all_data'))
    set(handles.wav_name,'String',names(3));%将strh的值传递给静态文本
else
    set(handles.wav_name,'String',names(2));%将strh的值传递给静态文本
end   






function wav_name_Callback(hObject, eventdata, handles)
% hObject    handle to wav_name (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 wav_name as text
%        str2double(get(hObject,'String')) returns contents of wav_name as a double


% --- Executes during object creation, after setting all properties.
function wav_name_CreateFcn(hObject, eventdata, handles)
% hObject    handle to wav_name (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



function result_name_Callback(hObject, eventdata, handles)
% hObject    handle to result_name (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 result_name as text
%        str2double(get(hObject,'String')) returns contents of result_name as a double


% --- Executes during object creation, after setting all properties.
function result_name_CreateFcn(hObject, eventdata, handles)
% hObject    handle to result_name (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



function result_Callback(hObject, eventdata, handles)
% hObject    handle to result (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 result as text
%        str2double(get(hObject,'String')) returns contents of result as a double


% --- Executes during object creation, after setting all properties.
function result_CreateFcn(hObject, eventdata, handles)
% hObject    handle to result (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 pushbutton11.
function pushbutton11_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton11 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

%复制文件至train文件夹内
global filename
myDestination =('./data/train');
copyfile(filename,myDestination)
names=strsplit(filename,'train\');
ID=strsplit(char(names(2)),'.wav');
ID=char(ID(1));

%并将对应的test文件复制到test文件夹内
test_dir='./data/all_data/test/';
test_des_dir='./data/test/';
find_test_filename=[test_dir,ID,'_*.wav'];
hhh=dir(find_test_filename);
namePositiveCell={hhh.name};%读取指定文件夹下的所有符合格式要求的文件名元胞
for i=1:length(namePositiveCell)
    test_name=[test_dir,char(namePositiveCell{i})];
    copyfile(test_name,test_des_dir)
end

set(handles.result,'String',['添加说话人:', ID ,'   并添加对应测试文件!  ~~~']);%将strh的值传递给静态文本

3.2021年12月2日更新(开源matlab源码)

3.1 资源获取

matlab源码获取地址:CSDN资源下载

3.2 如何使用

使用matlab打开项目,在命令行输入 命令

guide

然后在弹出的框里边,选择打开 User_Desktop.fig文件,如果没有的话,可以点击 浏览… 按钮,找到该文件打开即可
在这里插入图片描述
打开文件后,点击运行按钮
在这里插入图片描述
即可出现操作界面:
在这里插入图片描述

3.3 算法流程图及介绍

基于VQ矢量量化的说话人识别流程及算法原理(我的另一篇博客)

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 10
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 10
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

王延凯的博客

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值