gotest.m
资源名称:speech.rar [点击查看]
上传用户:ay_070428
上传日期:2014-12-04
资源大小:11427k
文件大小:2k
源码类别:
语音合成与识别
开发平台:
Matlab
- % Test wave files under testWave
- dtwFunction = 'dtwmex0';
- dtwFunction = 'dtwmex1n';
- testWave = dir('testWave/*.wav');
- %testWave = testWave(1:10);
- waveNum = length(testWave);
- if ~exist('waveData'),
- fprintf('Loading waveData.mat...n');
- load waveData.mat
- fprintf('Eliminate template file not by Roger...n');
- % Compare "roger" to "roger"
- index = findcell({waveData.speaker}, '1Roger');
- waveData = waveData(index);
- end
- allAnswer = {waveData.answer};
- fprintf('Compare %g wave files against %g template wave files...n', waveNum, length(waveData));
- for i=1:waveNum,
- waveFile = ['testWave/', testWave(i).name];
- [y, fs] = wavreadc(waveFile);
- testWave(i).mfcc = wave2mfccmex(y);
- distance = zeros(length(waveData), 1);
- for j=1:length(waveData),
- % distance(j) = feval(dtwFunction, testWave(i).mfcc, waveData(j).feature, 2, 1);
- distance(j) = feval(dtwFunction, testWave(i).mfcc, waveData(j).feature, 1, 1, 2);
- end
- [minDist, index] = sort(distance);
- testWave(i).predicted = waveData(index(1)).answer;
- testWave(i).closeSpeaker = waveData(index(1)).speaker;
- testWave(i).minDist = minDist(1);
- correctAnswer = upper(testWave(i).name);
- correctAnswer = correctAnswer(1:end-4);
- rankedAnswer = allAnswer(index);
- for j=1:length(waveData),
- if strcmp(upper(rankedAnswer{j}), correctAnswer),
- testWave(i).rank = j;
- break;
- end
- end
- fprintf('%g/%g ==> %s --> %s by %s (minDist=%g, rank=%g)n', i, waveNum, ...
- testWave(i).name, testWave(i).predicted, testWave(i).closeSpeaker, testWave(i).minDist, testWave(i).rank);
- pause(0.1);
- end
- fprintf('Recognition rate = %gn', sum([testWave.rank]==1)/length(testWave)*100);
- figure; plothist([testWave.rank]);
- figure; plotpie([testWave.rank], ['dtwFunction=',dtwFunction]);
- save testWave testWave