Home > asr > labRead.m

labRead

PURPOSE ^

labRead: Read the LAB file generated from Viterbi forced alignment or from human labeling

SYNOPSIS ^

function word=labRead(labFile, deleteSil)

DESCRIPTION ^

 labRead: Read the LAB file generated from Viterbi forced alignment or from human labeling
    Usage: word=labRead(labFile, deleteSil)

    For example:
        wavFile='但使龍城飛將在.wav';
        labFile='但使龍城飛將在.lab';
        deleteSil=1;
        word=labRead(labFile, deleteSil);
        [y, fs, nbits]=wavread(wavFile);
        for i=1:length(word)
            index=ceil(word(i).time/10000000*fs);    % Time unit is 100 ns (= 1/10000000 sec)
            fprintf('Hit return to play "%s"...\n', word(i).name); pause
            sound(y(index(1):index(2)), fs);
        end

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function word=labRead(labFile, deleteSil)
0002 % labRead: Read the LAB file generated from Viterbi forced alignment or from human labeling
0003 %    Usage: word=labRead(labFile, deleteSil)
0004 %
0005 %    For example:
0006 %        wavFile='但使龍城飛將在.wav';
0007 %        labFile='但使龍城飛將在.lab';
0008 %        deleteSil=1;
0009 %        word=labRead(labFile, deleteSil);
0010 %        [y, fs, nbits]=wavread(wavFile);
0011 %        for i=1:length(word)
0012 %            index=ceil(word(i).time/10000000*fs);    % Time unit is 100 ns (= 1/10000000 sec)
0013 %            fprintf('Hit return to play "%s"...\n', word(i).name); pause
0014 %            sound(y(index(1):index(2)), fs);
0015 %        end
0016 
0017 %    Roger Jang, 20070117
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');    % 1900000 2700000 d+a -1537.86 dan
0027     if ~isempty(wordName)    % Found a new word
0028         wordIndex=wordIndex+1;
0029         word(wordIndex).name=wordName{1};
0030         phoneIndex=1;
0031     end
0032     word(wordIndex).phone(phoneIndex).name=phoneName{1};        % A new phone
0033     word(wordIndex).phone(phoneIndex).time=[sTime; eTime];
0034     word(wordIndex).phone(phoneIndex).logProb=logProb;
0035     phoneIndex=phoneIndex+1;
0036 end
0037 
0038 % Record the duration of each word
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 % Get rid of 'sil' and 'sp' (for English)
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 % Get rid of 'sil+*' (for Chinese that uses CGU pinyin)
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    % 刪除這個 phone
0060                 word(i).time(1)=word(i).phone(2).time(1);    % 修正 word 的時間
0061                 word(i).phone(1)=[];
0062             else    % 只有一個 phone,紀錄 index,準備砍 word
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);    % Time unit is 100 ns (= 1/10000000 sec)
0079     fprintf('Hit return to play "%s"...\n', word(i).name); pause
0080     sound(y(index(1):index(2)), fs);
0081 end

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