0001 function hmm = macroRead(macroFile)
0002
0003
0004
0005 if nargin<1, hmm=selfdemo; return; end
0006
0007 fid=fopen(macroFile);
0008 i = 0;
0009 flag4oneStreamPerState = 0;
0010 while ~feof(fid)
0011 i = i + 1;
0012 tmp = fgetl(fid);
0013 while isempty(findstr(tmp, '~h')),
0014 tmp = fgetl(fid);
0015
0016
0017 if findstr(tmp, '<STREAMINFO> 1'),
0018 streamInd = 1;
0019 flag4oneStreamPerState = 1;
0020 end
0021
0022 end
0023 [T, R] = strtok(tmp);
0024 hmm(i).pinyin = strrep(strrep(R, '"' , ''), ' ', '');
0025
0026
0027 tmp = fgetl(fid);
0028 while isempty(findstr(tmp, '<NUMSTATES>')),
0029 tmp = fgetl(fid);
0030 end
0031 [T, R] = strtok(tmp);
0032 hmm(i).numstates = str2num(R);
0033
0034
0035 tmp = fgetl(fid);
0036 while isempty(findstr(tmp, '<TRANSP>')),
0037 while isempty(findstr(tmp, '<STATE>')),
0038 tmp = fgetl(fid);
0039 end
0040 [T, R] = strtok(tmp);
0041 stateInd = str2num(R);
0042
0043
0044 while isempty(findstr(tmp, '<NUMMIXES>')),
0045 tmp = fgetl(fid);
0046 end
0047 [T, R] = strtok(tmp);
0048 hmm(i).state(stateInd).nummixes = eval(['[' R ']']);
0049
0050 while isempty(findstr(tmp, '<SWEIGHTS>')),
0051 tmp = fgetl(fid);
0052 end
0053
0054 [T, R] = strtok(tmp);
0055
0056
0057 hmm(i).state(stateInd).sweights = eval(['[' R ']']);
0058
0059 tmp = fgetl(fid);
0060 while isempty(findstr(tmp, '<STATE>'))&isempty(findstr(tmp, '<TRANSP>')),
0061
0062
0063
0064 if ~(flag4oneStreamPerState)
0065 while isempty(findstr(tmp, '<STREAM>')),
0066 tmp = fgetl(fid);
0067 end
0068 [T, R] = strtok(tmp);
0069 streamInd = str2num(R);
0070 end
0071
0072 tmp = fgetl(fid);
0073 while isempty(findstr(tmp, '<STREAM>')) & isempty(findstr(tmp, '<STATE>'))&isempty(findstr(tmp, '<TRANSP>')),
0074 while isempty(findstr(tmp, '<MIXTURE>')),
0075 tmp = fgetl(fid);
0076 end
0077 [T, R] = strtok(tmp);
0078 [T, R] = strtok(R);
0079 mixInd = str2num(T);
0080 hmm(i).state(stateInd).stream(streamInd).mix(mixInd).weight = str2double(R);
0081
0082 tmp = fgetl(fid);
0083 while isempty(findstr(tmp, '<MEAN>')),
0084 tmp = fgetl(fid);
0085 end
0086
0087
0088
0089 tmp = fgetl(fid);
0090 hmm(i).state(stateInd).stream(streamInd).mix(mixInd).mean = eval(['[' tmp ']']);
0091
0092
0093
0094
0095
0096
0097
0098
0099 tmp = fgetl(fid);
0100 while isempty(findstr(tmp, '<VARIANCE>')),
0101 tmp = fgetl(fid);
0102 end
0103
0104
0105
0106 tmp = fgetl(fid);
0107 hmm(i).state(stateInd).stream(streamInd).mix(mixInd).variance = eval(['[' tmp ']']);
0108
0109
0110
0111
0112
0113
0114
0115 tmp = fgetl(fid);
0116 while isempty(findstr(tmp, '<GCONST>')),
0117 tmp = fgetl(fid);
0118 end
0119 [T, R] = strtok(tmp);
0120 hmm(i).state(stateInd).stream(streamInd).mix(mixInd).gconst = str2double(R);
0121 tmp = fgetl(fid);
0122 end
0123 end
0124 end
0125 while isempty(findstr(tmp, '<TRANSP>')),
0126 tmp = fgetl(fid);
0127 end
0128 [T, R] = strtok(tmp);
0129 transpNum = str2num(R);
0130 tmp = fgetl(fid);
0131 for j=1:transpNum-1,
0132 tmp = strcat(tmp, ';', fgetl(fid));
0133 end
0134 hmm(i).transp = eval(['[' tmp ']']);
0135
0136 fgetl(fid);
0137 end
0138 fclose(fid);
0139
0140
0141 function hmm=selfdemo
0142 [parentDir, junk, junk, junk]=fileparts(which(mfilename));
0143 macroFile=[parentDir, '\exe\macro\taihua.mac'];
0144 macroFile='d:\users\jang\app\asr\macro\taihua.mac';
0145 fprintf('It will take about 15 seconds to load 526 acoustic models...\n');
0146 tic
0147 hmm=feval(mfilename, macroFile);
0148 fprintf('%g seconds!\n', toc);