主程序:Recognize.m
% 每次读入1个待识别的mp3语音文件,提取mfcc特征系数,
% 用dtw算法计算与参考模板作匹配,
% 可识别出:说话者、所说的水果名称,所说的语种。
clear ;close ; clc;
load ref_coef_1.mat;
load ref_coef_2.mat;
load ref_coef_3.mat;
load ref_coef_4.mat;
load ref_coef_5.mat;
load data.mat;
N =8;
fprintf(' \n' );
% 读入待测试语音:
while 1
i = input('请选择待测试语音文件的编号 1~40: (输入0 则退出) ') ;
if i == 0
return;
end
while (i<1 | i>40 )
i = input('请选择待测试语音文件的编号 1~40: ') ;
end
f_in = ['.\test_voice\' num2str(i) '.mp3'];
[x,fs]=audioread(f_in);
x = x -mean(x);
x = x/max(abs(x));
x = cut(x);
sound(x,fs);
% 提取待测试语音的特征参数:
test.feature = mfcc(x,fs) ;
% 匹配 -----------------
for j = 1: N
dist(1,j) = dtw(test.feature, ref_1(j).feature);
end
for j = 1: N
dist(2,j) = dtw(test.feature, ref_2(j).feature);
end
for j = 1: N
dist(3,j) = dtw(test.feature, ref_3(j).feature);
end
for j = 1: N
dist(4,j) = dtw(test.feature, ref_4(j).feature);
end
for j = 1: N
dist(5,j) = dtw(test.feature, ref_5(j).feature);
end
[x y]=find(dist==min(min(dist)));
switch (x)
case 1
trainer = '晓辰 '; language = '国语';
case 2
trainer = '晓晓 '; language = '国语';
case 3
trainer = '云皓 '; language = '国语';
case 4
trainer = '晓佳 '; language = '粤语';
case 5
trainer = '云龙 '; language = '粤语';
end
fprintf('所说水果名称是:%s\n', char(fruit(y)));
fprintf('说话者是:%s', trainer);
fprintf(',语言是%s\n',language);
fprintf(' \n' );
end
%--------------------------------------
运行截图:
其它函数及语音数据在压缩包中:
fruit_recognize.zip
(395.99 KB, 下载次数: 26)
|