forked from natashad/SpeechRecognition
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmyRun.m
77 lines (53 loc) · 1.39 KB
/
myRun.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
dir_test = '/u/cs401/speechdata/Testing';
fn_output = 'speechrecog.txt';
fn_HMM = 'savedHMM.mat';
DMFCC = dir([dir_test, filesep, '*.mfcc']);
DPHN = dir([dir_test, filesep, '*.phn']);
fID = fopen(fn_output, 'w');
D = 14;
total = 0;
correct = 0;
wrong = 0;
load(fn_HMM);
for f=1:length(DPHN)
fn_prefix = DPHN(f).name;
fn_prefix = fn_prefix(1:end-3);
fn_mfcc = [dir_test, filesep, fn_prefix, 'mfcc'];
[starts, ends, phns] = textread([dir_test, filesep, DPHN(f).name],'%d %d %s', 'delimiter', '\n');
X = load(fn_mfcc);
X = X';
X = X(1:D, :);
for p=1:length(phns)
start = max(starts(p)/128+1,1);
end1 = min((ends(p)/128) + 1, length(X));
phn = char(phns(p));
if strcmp(phn, 'h#')
phn = 'sil';
end
hmm_fields = fieldnames(HMM);
max_p = {};
max_p.phn = '';
max_p.val = -Inf;
for h=1:length(hmm_fields)
hmm_p = char(hmm_fields{h});
val = loglikHMM(HMM.(hmm_p), X(:, start:end1));
if val > max_p.val
max_p.phn = hmm_p;
max_p.val = val;
end
end
if strcmp(max_p.phn, phn)
res = ['Correct Result: ', phn];
correct = correct + 1;
else
res = ['Wrong. Expected: ', phn, ' computed: ', max_p.phn];
wrong = wrong + 1;
end
total = total + 1;
fprintf(fID, '%s\n', res);
end
end
acc = (correct*100)/total
accuracy = ['accuracy is: ', int2str(correct), '/', int2str(total), ' = ', int2str(acc)];
fprintf(fID, '%s\n', accuracy);
fclose(fID);