forked from lawrennd/datasets
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhtkLoadMmf.m
96 lines (92 loc) · 2.69 KB
/
htkLoadMmf.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
function [meanValCell, varValCell] = htkLoadMmf(phoneList, fileName)
% HTKLOADMMF File for loading synthesis data from HTK files.
% FORMAT
% DESC loads the means and variances for the phone model from the
% relevant HTK file.
% ARG phoneList : cell array containing the names of the phone you want to load in.
% ARG fileName : the name of the HTK file from which you are loading.
% RETURN meanValCell : the mean values from the file.
% RETURN varValCell : the standard deviation values from the file.
%
% COPYRIGHT : Neil D. Lawrence, 2009
% DATASETS
inState = false;
inMean = false;
inVar = false;
inHmm = false;
inStream = false;
rightPhone = false;
meanValCell = {};
varValCell = {};
fid = fopen(fileName);
if fid == -1
error(['No such file name ' fileName])
end
readLine = fgets(fid);
counter = 0;
data = [];
while readLine ~= -1
readLine = fgets(fid);
counter = counter + 1;
if strcmp(readLine(1:min(end,10)), '<BEGINHMM>')
inHmm = true;
continue
elseif strcmp(readLine(1:min(end,8)), '<ENDHMM>')
inHmm = false;
continue
elseif strcmp(readLine(1:min(end,2)), '~h')
splits = stringSplit(readLine, ' ');
phone = splits{2}(2:end-2);
match = strcmp(phoneList, phone);
if any(match)
i = min(find(match));
meanValCell{i, 1} = [];
meanValCell{i, 2} = [];
meanValCell{i, 3} = [];
varValCell{i, 1} = [];
varValCell{i, 2} = [];
varValCell{i, 3} = [];
rightPhone = true;
else
rightPhone = false;
end
end
if rightPhone &&inHmm
if strcmp(readLine(1:min(end,7)), '<STATE>')
inState = true;
continue
end
if inState && strcmp(readLine(1:min(end,10)), '<STREAM> 1')
inStream = true;
continue
end
if inStream && strcmp(readLine(1:min(end,6)), '<MEAN>')
inMean = true;
continue
end
if inStream && strcmp(readLine(1:min(end,10)),'<VARIANCE>')
inVar = true;
continue
end
if inMean
allVals = sscanf(readLine, '%f');
meanValCell{i, 1} = [meanValCell{i, 1} allVals(1:25)'];
meanValCell{i, 2} = [meanValCell{i, 2} allVals(26:50)'];
meanValCell{i, 3} = [meanValCell{i, 3} allVals(51:75)'];
inMean = false;
continue
end
if inVar
allVals = sscanf(readLine, '%f');
varValCell{i, 1} = [varValCell{i, 1} allVals(1:25)'];
varValCell{i, 2} = [varValCell{i, 2} allVals(26:50)'];
varValCell{i, 3} = [varValCell{i, 3} allVals(51:75)'];
inVar = false;
inState = false;
inStream = false;
continue
end
end
end
fclose(fid);
end