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