Home > asr > waveCmPlot.m

waveCmPlot

PURPOSE ^

waveCmPlot: Generate wave segmentation plot from a wav file and the corresponding CM (confidence measure) file

SYNOPSIS ^

function waveCmPlot(waveFile, xmlFile, action)

DESCRIPTION ^

waveCmPlot: Generate wave segmentation plot from a wav file and the corresponding CM (confidence measure) file
    Usage: waveCmPlot(waveFile, xmlFile)

    After the plot is generated, you can click and drag to play a part of the wave file.

    For example:
        wavFile='what_would_you_like_to_know.wav';
        xmlFile='what_would_you_like_to_know.xml';
        waveCmPlot(wavFile, xmlFile);

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function waveCmPlot(waveFile, xmlFile, action)
0002 %waveCmPlot: Generate wave segmentation plot from a wav file and the corresponding CM (confidence measure) file
0003 %    Usage: waveCmPlot(waveFile, xmlFile)
0004 %
0005 %    After the plot is generated, you can click and drag to play a part of the wave file.
0006 %
0007 %    For example:
0008 %        wavFile='what_would_you_like_to_know.wav';
0009 %        xmlFile='what_would_you_like_to_know.xml';
0010 %        waveCmPlot(wavFile, xmlFile);
0011 
0012 %    Roger Jang, 20041211, 20100412
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;    % xmlFile is actually an CM data structure in memory.
0027         end
0028         if isempty(cmObj)
0029             return;
0030         end
0031         word=cmObj.word;
0032         cmWordBgPlot(cmObj, -1, 1);    % Plot background yellow patches
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         % Place the figure
0046     %    screenSize=get(0, 'screenSize');
0047     %    set(gcf, 'position', [1, 50, screenSize(3), screenSize(4)/2]);
0048 
0049         % ====== Record user data
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 % ====== Sub-functions
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 % ====== selfdemo
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, '_', '\_'));

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