Home > asr > asrPerfEval.m

asrPerfEval

PURPOSE ^

asrPerfEval: Performance evaluation of ASR

SYNOPSIS ^

function [recogRate, waveData, totalTime, aveTime]=asrPerfEval(waveData, rp, plotOpt, noiseLevel)

DESCRIPTION ^

 asrPerfEval: Performance evaluation of ASR
    Usage: [recogRate, waveData, totalTime, aveTime]=asrPerfEval(waveData, rp, plotOpt, noiseLevel)
        使用方式,請參考 D:\users\jang\application\asrPerfEval\goPerfEval.m

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [recogRate, waveData, totalTime, aveTime]=asrPerfEval(waveData, rp, plotOpt, noiseLevel)
0002 % asrPerfEval: Performance evaluation of ASR
0003 %    Usage: [recogRate, waveData, totalTime, aveTime]=asrPerfEval(waveData, rp, plotOpt, noiseLevel)
0004 %        使用方式,請參考 D:\users\jang\application\asrPerfEval\goPerfEval.m
0005 
0006 %    Roger Jang, 20070203
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 % ====== Do recognition
0024 %fprintf('Testing %g wave files:\n', length(waveData));
0025 for i=1:length(waveData)
0026 %    [waveData(i).computed, time(i)]=waveRecognize(waveData(i).path, appDir, epdOpt, micSpeech, plotOpt);
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     % Add noise if necessary
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 %    disp(dosCmd);
0069     tic;
0070     waveData(i).exeFail=0;
0071     [waveData(i).exeStatus, waveData(i).exeResult]=dos(dosCmd);
0072 %    waveData(i).exeResult
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     %    keyboard
0082     end
0083 
0084     % 記錄「電腦」兩字的平均分數 (for MSI recording only!)
0085 %    index1=find(strcmp({waveData(i).cm.word.text}, '電'));
0086 %    index2=find(strcmp({waveData(i).cm.word.text}, '腦'));
0087 %    score1=waveData(i).cm.word(index1(1)).score;
0088 %    score2=waveData(i).cm.word(index1(1)).score;
0089 %    waveData(i).buzzWordScore=(score1+score2)/2;
0090     
0091     if waveData(i).exeFail==0
0092         waveData(i).cm=cmRead('output\phone.cm');    % Get CM. Could be removed if time consuming
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}, '=');    % temp{1}='文字=人事音書漫寂寥'
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     %=================== Temp setting for byway!!!
0105 %    waveData(i).computed=strrep(waveData(i).computed, '.', '');
0106 %    waveData(i).computed=strrep(waveData(i).computed, ',', '');
0107 %    waveData(i).computed=strrep(waveData(i).computed, '?', '');
0108 %    waveData(i).computed=strrep(waveData(i).computed, '"', '');
0109 %    waveData(i).computed=strrep(waveData(i).computed, '!', '');
0110 %    waveData(i).computed=strrep(waveData(i).computed, '-', '');
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 %        fprintf('\t\t\tPress any key to continue...'); pause; fprintf('\n');
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 %    fprintf('\t\tError rate = %d/%d = %.2f%%\n', length(correct)-sum(correct), length(correct), errorRate*100);
0138 end

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