0001 function waveCmPlot(waveFile, xmlFile, action)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 persistent wave fs time word selectedBound selectedRegionH uniquePhoneTime axisLimit
0015
0016 if nargin<1, selfdemo; return; end
0017 if nargin<3, action='start'; end
0018
0019 switch(action)
0020 case 'start'
0021 [wave, fs, nbits]=wavread(waveFile);
0022 if isstr(xmlFile)
0023 output=asraOutputXmlRead(xmlFile);
0024 cmObj=output.confidenceMeasure;
0025 else
0026 cmObj=xmlFile;
0027 end
0028 if isempty(cmObj)
0029 return;
0030 end
0031 word=cmObj.word;
0032 cmWordBgPlot(cmObj, -1, 1);
0033 selectedRegionH=line([0 0], [0 0], 'color', 'k', 'erase', 'xor', 'lineWidth', 4, 'clipping', 'off');
0034
0035 time=(1:length(wave))/fs;
0036 line(time, wave);
0037 axis([min(time), max(time), -1, 1]); box on
0038 axisLimit=axis;
0039
0040 allPhone=cat(2, word.phone);
0041 allPhoneTime=cat(1, allPhone.interval);
0042 uniquePhoneTime=[0; unique(allPhoneTime); max(time)];
0043 selectedBound=[inf -inf];
0044
0045
0046
0047
0048
0049
0050 set(gcf, 'WindowButtonDownFcn', sprintf('%s([], [], %s)', mfilename, '''down'''));
0051 case 'down'
0052
0053 set(gcf, 'WindowButtonMotionFcn', sprintf('%s([], [], %s)', mfilename, '''move'''));
0054
0055 set(gcf, 'WindowButtonUpFcn', sprintf('%s([], [], %s)', mfilename, '''up'''));
0056
0057 feval(mfilename, [], [], 'move');
0058 case 'move'
0059 currPt=get(gca, 'CurrentPoint'); xPos=currPt(1,1); yPos=currPt(1,2);
0060 if insideAxisLimit(axisLimit, [xPos, yPos])
0061 index=findInRange(uniquePhoneTime, xPos);
0062 time1=uniquePhoneTime(index); time2=uniquePhoneTime(index+1);
0063 if time1<selectedBound(1), selectedBound=[time1, selectedBound(2)]; end
0064 if time2>selectedBound(2), selectedBound=[selectedBound(1), time2]; end
0065 yRange=get(gca, 'ylim');
0066 set(selectedRegionH, 'xdata', selectedBound([1, 2, 2, 1, 1]), 'ydata', [yRange(1), yRange(1), yRange(2), yRange(2), yRange(1)]);
0067 end
0068 case 'up'
0069
0070 set(gcf, 'WindowButtonMotionFcn', '');
0071
0072 set(gcf, 'WindowButtonUpFcn', '');
0073 currPt=get(gca, 'CurrentPoint'); xPos=currPt(1,1); yPos=currPt(1,2);
0074 if insideAxisLimit(axisLimit, [xPos, yPos])
0075 index=find((selectedBound(1)<=time) & (time<=selectedBound(2)));
0076 wavplay(wave(index), fs, 'sync');
0077 end
0078 selectedBound=[inf -inf];
0079 end
0080
0081
0082 function output=insideAxisLimit(axisLimit, currPos)
0083 output=0;
0084 if axisLimit(1)<=currPos(1) & currPos(1)<=axisLimit(2) & axisLimit(3)<=currPos(2) & currPos(2)<axisLimit(4)
0085 output=1;
0086 end
0087
0088
0089 function selfdemo
0090 wavFile='what_would_you_like_to_know.wav';
0091 xmlFile='what_would_you_like_to_know.xml';
0092 feval(mfilename, wavFile, xmlFile);
0093 xlabel(strrep(wavFile, '_', '\_'));