demoDTW.m
资源名称:speech.rar [点击查看]
上传用户:ay_070428
上传日期:2014-12-04
资源大小:11427k
文件大小:1k
源码类别:
语音合成与识别
开发平台:
Matlab
- fprintf('This test script shows the DTW path between reference and test inputs.n');
- close all
- fs = 8000;
- duration = 3;
- fprintf('Hit return to start %g-sec reference recording...', duration);
- pause;
- fprintf('Start recording ...');
- y2 = wavrecord(duration*fs, fs, 'uint8');
- y2 = (double(y2)-128)/128;
- wavwrite(y2, fs, 8, 'reference.wav');
- fprintf('Finish recording.n');
- mfcc2 = wave2mfccmex(y2);
- frameNum2 = size(mfcc2, 2);
- while(1)
- fprintf('Hit return to start %g-sec test recording...', duration);
- pause;
- fprintf('Start recording ...');
- y1 = wavrecord(duration*fs, fs, 'uint8');
- y1 = (double(y1)-128)/128;
- wavwrite(y1, fs, 8, 'test.wav');
- fprintf('Finish recording.n');
- mfcc1 = wave2mfccmex(y1);
- frameNum1 = size(mfcc1, 2);
- clf;
- % Vertical yellow grid line
- for i = 1:frameNum1,
- line([i, i], [1, frameNum2], 'color', 'y');
- end
- % Horizontal yellow grid line
- for j = 1:frameNum2,
- line([1, frameNum1], [j, j], 'color', 'y');
- end
- % ====== Solution obtained by DTW
- [minDist, DTWpath] = dtwmex1n(mfcc1, mfcc2);
- fprintf('DTW distance = %gn', minDist);
- for i = 1:size(DTWpath,2)-1,
- line([DTWpath(1,i), DTWpath(1,i+1)], [DTWpath(2,i), DTWpath(2,i+1)], 'color', 'r', 'marker', '.');
- end
- title('DTW path (red)');
- xlabel('Test input');
- ylabel('Reference input');
- axis image
- box on
- end