附录1:录音函数:audiorecorder.m
% 运行平台:Windows 8.1 64bit MATLAB R2014a
% 录音2秒钟
clear all;clc;close all;
fs = 16000; %²ÉÑùƵÂÊ
recorder = audiorecorder;
disp('Start speaking.')
recordblocking(recorder, 2);
disp('End of Recording.');
% 回放录音数据
play(recorder);
% 获取录音数据
xx = getaudiodata(recorder,'int16');
%绘制录音数据波形
plot(xx);
A6:“录音”按键回调函数
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) fs = 16000;
recorder = audiorecorder;
disp('Start speaking.')
recordblocking(recorder, 2);
disp('End of Recording.');
% 回放录音数据
% play(recorder);
% 获取录音数据
k = getaudiodata(recorder,'int16');
plot(handles.axes1,k);
load mfcc.mat;
[StartPoint,EndPoint]=vad(k,fs);
cc=mfcc(k);
cc=cc(StartPoint-2:EndPoint-2,:);
test.StartPoint=StartPoint;
test.EndPoint=EndPoint;
test.mfcc=cc;
dist = zeros(1,20);
for j=1:20
dist(j) = dtw(test.mfcc, ref(j).mfcc);
end
[d,j] = min(dist);
if (j>=1 && j<=5)
str = ('识别结果为:前进');
end
if (j>= 6 && j<=10)
str = ('识别结果为:停止');
end
if (j>=11 && j<=15)
str = ('识别结果为:左转');
end
if (j>=16 && j<=20)
str = ('识别结果为:右转');
end
set(handles.text3,'string',str);。