主程序:Recognize.m
% 每次讀入1個待識別的mp3語音文件,提取mfcc特征系數(shù),
% 用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);
% 提取待測試語音的特征參數(shù):
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
%--------------------------------------
運行截圖:
其它函數(shù)及語音數(shù)據(jù)在壓縮包中:
fruit_recognize.zip
(395.99 KB, 下載次數(shù): 26)
2023-10-7 22:39 上傳
點擊文件名下載附件
|