Home > asr > macroRead_b.m

macroRead_b

PURPOSE ^

macroRead: Read a macro file

SYNOPSIS ^

function hmm = macroRead(macroFile)

DESCRIPTION ^

 macroRead: Read a macro file
    Usage: hmm = macroRead(macroFile)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function hmm = macroRead(macroFile)
0002 % macroRead: Read a macro file
0003 %    Usage: hmm = macroRead(macroFile)
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                 %[T, R] = strtok(tmp);
0068                 %meanNum = str2num(R);
0069 
0070                 tmp = fgetl(fid);
0071                 hmm(i).state(stateInd).stream(streamInd).mix(mixInd).mean = eval(['[' tmp ']']);
0072                 
0073                 %[T, R] = strtok(tmp);
0074                 %hmm(i).state(stateInd).stream(streamInd).mix(mixInd).mean(1).value = str2double(T);
0075                 %for j=2:meanNum,
0076                 %    [T, R] = strtok(R);
0077                 %    hmm(i).state(stateInd).stream(streamInd).mix(mixInd).mean(j).value = str2double(T);
0078                 %end
0079 
0080                 tmp = fgetl(fid);
0081                 while isempty(findstr(tmp, '<VARIANCE>')),
0082                     tmp = fgetl(fid);
0083                 end
0084                 %[T, R] = strtok(tmp);
0085                 %varianceNum = str2num(R);
0086 
0087                 tmp = fgetl(fid);
0088                 hmm(i).state(stateInd).stream(streamInd).mix(mixInd).variance = eval(['[' tmp ']']);                
0089                 %[T, R] = strtok(tmp);
0090                 %hmm(i).state(stateInd).stream(streamInd).mix(mixInd).variance(1).value = str2double(T);
0091                 %for j=2:varianceNum,
0092                 %    [T, R] = strtok(R);
0093                 %    hmm(i).state(stateInd).stream(streamInd).mix(mixInd).variance(j).value = str2double(T);
0094                 %end
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 % ====== Self demo
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);

Generated on Tue 01-Jun-2010 09:50:19 by m2html © 2003