-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathtest.m
37 lines (31 loc) · 1.03 KB
/
test.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
function test(testdir, n, code)
% Speaker Recognition: Testing Stage
%
% Input:
% testdir : string name of directory contains all test sound files
% n : number of test files in testdir
% code : codebooks of all trained speakers
%
% Note:
% Sound files in testdir is supposed to be:
% s1.wav, s2.wav, ..., sn.wav
%
% Example:
% >> test('C:\data\test\', 8, code);
for k=1:n % read test sound file of each speaker
file = sprintf('%ss%d.wav', testdir, k);
[s, fs] = wavread(file);
v = mfcc(s, fs); % Compute MFCC's
distmin = inf;
k1 = 0;
for l = 1:length(code) % each trained codebook, compute distortion
d = distance(v, code{l});
dist = sum(min(d,[],2)) / size(d,1);
if dist < distmin
distmin = dist;
k1 = l;
end
end
msg = sprintf('Speaker %d matches with speaker %d', k, k1);
disp(msg);
end