0001 function word=labRead(labFile, deleteSil)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019 if nargin<1, selfdemo; return; end
0020 if nargin<2, deleteSil=0; end
0021
0022 content = textread(labFile, '%s', 'delimiter', '\n', 'whitespace', '');
0023 wordIndex=0;
0024 for i=1:length(content)
0025 line=content{i};
0026 [sTime, eTime, phoneName, logProb, wordName]=strread(line, '%d%d%s%f%s');
0027 if ~isempty(wordName)
0028 wordIndex=wordIndex+1;
0029 word(wordIndex).name=wordName{1};
0030 phoneIndex=1;
0031 end
0032 word(wordIndex).phone(phoneIndex).name=phoneName{1};
0033 word(wordIndex).phone(phoneIndex).time=[sTime; eTime];
0034 word(wordIndex).phone(phoneIndex).logProb=logProb;
0035 phoneIndex=phoneIndex+1;
0036 end
0037
0038
0039 for i=1:length(word)
0040 word(i).time=[word(i).phone(1).time(1); word(i).phone(end).time(2)];
0041 end
0042
0043
0044 if deleteSil
0045 silIndex=[];
0046 for i=1:length(word)
0047 if strcmp(word(i).name, 'sil') | strcmp(word(i).name, 'sp')
0048 silIndex=[silIndex, i];
0049 end
0050 end
0051 word(silIndex)=[];
0052 end
0053
0054 if deleteSil
0055 deleteIndex=[];
0056 for i=1:length(word);
0057 nameLen=length(word(i).phone(1).name);
0058 if strcmp(word(i).phone(1).name(1:min(nameLen,4)), 'sil+')
0059 if length(word(i).phone)>1
0060 word(i).time(1)=word(i).phone(2).time(1);
0061 word(i).phone(1)=[];
0062 else
0063 deleteIndex=[deleteIndex, i];
0064 end
0065 end
0066 end
0067 word(deleteIndex)=[];
0068 end
0069
0070
0071 function selfdemo
0072 wavFile='但使龍城飛將在.wav';
0073 labFile='但使龍城飛將在.lab';
0074 deleteSil=1;
0075 word=labRead(labFile, deleteSil);
0076 [y, fs, nbits]=wavread(wavFile);
0077 for i=1:length(word)
0078 index=ceil(word(i).time/10000000*fs);
0079 fprintf('Hit return to play "%s"...\n', word(i).name); pause
0080 sound(y(index(1):index(2)), fs);
0081 end