0001 function [recogRate, waveData, totalTime, aveTime]=asrPerfEval(waveData, rp, plotOpt, noiseLevel)
0002
0003
0004
0005
0006
0007
0008 if nargin<3, plotOpt=0; end
0009 if nargin<4, noiseLevel=0; end
0010
0011 if isempty(waveData)
0012 recogRate=0;
0013 totalTime=0;
0014 aveTime=0;
0015 return
0016 end
0017
0018 [parentDir, junk, junk, junk]=fileparts(which(mfilename));
0019 exeDir=[parentDir, '\exe'];
0020 currDir=pwd;
0021 executable=[exeDir, '\recog.exe'];
0022
0023
0024
0025 for i=1:length(waveData)
0026
0027 waveFile=waveData(i).path;
0028
0029 if rp.useWaveEnhancement
0030 fprintf('\t\t\tPerform speech enhancement...\n');
0031 newPath=[tempname, '.wav'];
0032 waveEnhancement(waveFile, newPath);
0033 waveData(i).origPath=waveData(i).path;
0034 waveData(i).path=newPath;
0035 waveFile=newPath;
0036 end
0037 if rp.useHighPassFilter
0038 fprintf('\t\t\tPerform high-pass filtering...\n');
0039 newPath=[tempname, '.wav'];
0040 cutOffFreq=100;
0041 filterOrder=3;
0042 waveHighPassFilter(waveFile, newPath, cutOffFreq, filterOrder);
0043 waveData(i).origPath=waveData(i).path;
0044 waveData(i).path=newPath;
0045 waveFile=newPath;
0046 end
0047 if rp.useLse4sinRemove
0048 fprintf('\t\t\tPerform LSE for 50Hz sinusoid removal...\n');
0049 newPath=[tempname, '.wav'];
0050 freq=50;
0051 waveSinusoidRemove(waveFile, newPath, freq);
0052 waveData(i).origPath=waveData(i).path;
0053 waveData(i).path=newPath;
0054 waveFile=newPath;
0055 end
0056
0057
0058 if noiseLevel>0
0059 [y, fs, nbits]=wavread(waveFile);
0060 y=y+noiseLevel*randn(size(y));
0061 newWaveFile=[tempname, '.wav'];
0062 wavwrite(y, fs, nbits, newWaveFile);
0063 waveFile=newWaveFile;
0064 end
0065 cd(exeDir);
0066 dosCmd=sprintf('%s "%s" "%s" "%s" %d "%s" "%s" "%s" "%s" %d', executable, rp.file, waveFile, rp.txtFile, rp.useEpd, rp.outputDir, rp.sylFile, rp.netFile, rp.wpaFile, rp.getPitch);
0067 waveData(i).dosCmd=dosCmd;
0068
0069 tic;
0070 waveData(i).exeFail=0;
0071 [waveData(i).exeStatus, waveData(i).exeResult]=dos(dosCmd);
0072
0073 waveData(i).time=toc;
0074 if isempty(findstr('Done!', waveData(i).exeResult))
0075 debug=1;
0076 fprintf('dosCmd=%s\n', dosCmd);
0077 fprintf('exeStatus=%d\n', waveData(i).exeStatus);
0078 fprintf('exeResult=%s\n', waveData(i).exeResult);
0079 fprintf('Something went wrong! You can copy the dosCmd and run it under DOS window within {asrToolbox}/exe directory to see the results for debugging.\n');
0080 waveData(i).exeFail=1;
0081
0082 end
0083
0084
0085
0086
0087
0088
0089
0090
0091 if waveData(i).exeFail==0
0092 waveData(i).cm=cmRead('output\phone.cm');
0093 waveData(i).score=waveData(i).cm.score;
0094 temp = textread('output/recogResult.txt', '%s', 'delimiter', '\n', 'whitespace', '', 'bufsize', 20000);
0095 items=split(temp{2}, '=');
0096 waveData(i).computed=items{2};
0097 else
0098 waveData(i).cm=[];
0099 waveData(i).score=nan;
0100 waveData(i).computed='';
0101 end
0102 cd(currDir);
0103
0104
0105
0106
0107
0108
0109
0110
0111
0112
0113 waveData(i).correct=strcmp(lower(waveData(i).text), lower(waveData(i).computed));
0114 if ~isempty(strfind(waveData(i).computed, '#'))
0115 waveData(i).correct=any(strcmp(waveData(i).text, split(waveData(i).computed, '#')));
0116 end
0117 if waveData(i).correct==1
0118 symbol='☆';
0119 else
0120 symbol='★';
0121 end
0122 if plotOpt
0123 fprintf('\t\t%g/%g: (%s) %s (%.2f seconds)\n', i, length(waveData), symbol, waveData(i).path, waveData(i).time);
0124 fprintf('\t\t\tdosCmd=%s\n', dosCmd);
0125
0126 end
0127 end
0128 totalTime=sum([waveData.time]);
0129 aveTime=totalTime/length(waveData);
0130 correct=[waveData.correct];
0131 recogRate=sum(correct)/length(correct);
0132 errorRate=1-recogRate;
0133 if plotOpt
0134 fprintf('\t\tTotal time = %.2f 秒\n', totalTime);
0135 fprintf('\t\tAverage time = %.2f 秒\n', aveTime);
0136 fprintf('\t\tRecognition rate = %d/%d = %.2f%%\n', sum(correct), length(correct), recogRate*100);
0137
0138 end