function varargout = soundrecognize(varargin)
% SOUNDRECOGNIZE M-file for soundrecognize.fig
% SOUNDRECOGNIZE, by itself, creates a new SOUNDRECOGNIZE or raises the existing
% singleton*.
%
% H = SOUNDRECOGNIZE returns the handle to a new SOUNDRECOGNIZE or the handle to
% the existing singleton*.
%
% SOUNDRECOGNIZE('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in SOUNDRECOGNIZE.M with the given input arguments.
%
% SOUNDRECOGNIZE('Property','Value',...) creates a new SOUNDRECOGNIZE or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before soundrecognize_OpeningFunction gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to soundrecognize_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 soundrecognize
% Last Modified by GUIDE v2.5 23-Dec-2009 10:12:13
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @soundrecognize_OpeningFcn, ...
'gui_OutputFcn', @soundrecognize_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 soundrecognize is made visible.
function soundrecognize_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 soundrecognize (see VARARGIN)
% Choose default command line output for soundrecognize
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes soundrecognize wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = soundrecognize_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 pushbutton_sound_record.%%%输入声音,用于识别%%%%
function pushbutton_sound_record_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton_sound_record (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
FS=22050;
time=6;
global y9
y9=wavrecord(time*FS,FS,1);
axes(handles.axes1);
plot(y9),ylabel('Speach'),xlabel('t')
% wavwrite(y,FS,'a');
return;
% --- Executes on button press in pushbutton_train.%%%%输入声音训练%%%%%
function pushbutton_train_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton_train (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
samples=[];
global hmm
hmm=[];
FS=22050;
time=2;
y1=wavrecord(time*FS,FS,1);
axes(handles.axes2);
plot(y1),ylabel('Speach'),xlabel('t') ;
[rx1,rx2,amp,frameinc,rframe]=frameDetect1(y1,FS);
samples{1}=y1(rx1*frameinc:rx2*frameinc);
set(handles.edit1,'String','第一个声音已输入');
fprintf('Press any key to start %g seconds of recording...\n',time);
pause;
FS=22050;
time=2;
y2=wavrecord(time*FS,FS,1);
axes(handles.axes2);
plot(y2),ylabel('Speach'),xlabel('t') ;
[rx1,rx2,amp,frameinc,rframe]=frameDetect1(y2,FS);
samples{2}=y2(rx1*frameinc:rx2*frameinc);
set(handles.edit1,'String','第二个声音已输入');
fprintf('Press any key to start %g seconds of recording...\n',time);
pause;
FS=22050;
time=2;
y3=wavrecord(time*FS,FS,1);
axes(handles.axes2);
plot(y3),ylabel('Speach'),xlabel('t') ;
[rx1,rx2,amp,frameinc,rframe]=frameDetect1(y3,FS);
samples{3}=y3(rx1*frameinc:rx2*frameinc);
set(handles.edit1,'String','第三个声音已输入');
fprintf('Press any key to start %g seconds of recording...\n',time);
pause;
FS=22050;
time=2;
y4=wavrecord(time*FS,FS,1);
axes(handles.axes2);
plot(y4),ylabel('Speach'),xlabel('t') ;
[rx1,rx2,amp,frameinc,rframe]=frameDetect1(y4,FS);
samples{4}=y4(rx1*frameinc:rx2*frameinc);
set(handles.edit1,'String','第四个声音已输入');
fprintf('Press any key to start %g seconds of recording...\n',time);
pause;
FS=22050;
time=2;
y1=wavrecord(time*FS,FS,1);
axes(handles.axes2);
plot(y1),ylabel('Speach'),xlabel('t') ;
[rx1,rx2,amp,frameinc,rframe]=frameDetect1(y1,FS);
samples{5}=y1(rx1*frameinc:rx2*frameinc);
set(handles.edit1,'String','第五个声音已输入');
sample=[];
for i=1:length(samples)
sample(i).wave=(samples{i});
sample(i).data = mfcc(samples{i});
end
disp(length(samples));
hmm=train(sample,[3 3 3 3]); %%训练声音
return;
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 button press in pushbutton_recognize.%%%识别声音%%%%
function pushbutton_recognize_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton_recognize (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global hmm
global y9
FS=22050;
tx2=0;
%time=6;
% fname=sprintf('a.wav');
% y=wavread(fname);
% y=wavrecord(time*FS,FS,1);
y=y9;
%%归一化
count1=0;
count2=0;
count3=0;
FrameInc=round(FS*10/1000);
FrameLength=round(FS*20/1000);
y=double(y);
y=y-mean(y);
y=y/max(abs(y));
y3=y;
%%滤波
filter_Y=filter([1 -0.9375],1,y);
%分帧
%短时能量
frame=enframe(filter_Y,FrameLength,FrameInc);
Delta =0.01;%过零率监测域值
tmp1=enframe(y(1:length(y)-1),FrameLength,FrameInc);
tmp2=enframe(y(2:length(y)),FrameLength,FrameInc);
signs=(tmp1.*tmp2)<0;
diffs=abs((tmp1-tmp2))>Delta;
zcr=sum(signs.*diffs,2);
frametemp=enframe(y,FrameLength,FrameInc);
%%%%
while tx2<length(zcr)
secondframe=y3((tx2+1)*FrameInc:length(y3));
[tx1,tx22,tframe,amp,ttx1]=FrameDetect(secondframe,FS,tx2,frame,frametemp,zcr);
count1=count1+1;
if tframe==0
count1=count1-1;
ttx1=length(zcr)+1;
elseif tframe==2;
y1=y3((tx1+tx2)*FrameInc : (tx22+tx2)*FrameInc);
amp11=amp((tx1+tx2) : (tx22+tx2));
axes(handl
hmm声音识别---隐马尔科夫模型语音识别.rar
需积分: 5 65 浏览量
2023-12-04
20:09:02
上传
评论
收藏 162KB RAR 举报
温柔-的-女汉子
- 粉丝: 629
- 资源: 3933