Home > asr > waveAssess4dir.m

waveAssess4dir

PURPOSE ^

waveAssess4dir: Wave Assessment for a directory of wave files(wadParam)

SYNOPSIS ^

function waveData=waveAssess4dir(wadParam)

DESCRIPTION ^

 waveAssess4dir: Wave Assessment for a directory of wave files(wadParam)
    Usage: waveData=waveAssess4dir(wadParam)

    For example:

        wadParam.language='english';            % Language
        wadParam.tcpFile='J:\error_wav\all.tcp';    % TCP file
        wadParam.waveDir='J:\error_wav';        % Directory for holding all the wave files
        wadParam.labDir='J:\error_wav\labDir';        % Output directory for holding the lab files. (A lab file will not be regenerated if it alreay exists.) 
        wadParam.fileExtName='wa1';            % Extension name for the wave files
        wadParam.errorLogFile='J:\error_wav\error.log';    % Error log file
        waveData=waveAssess4dir(wadParam);

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function waveData=waveAssess4dir(wadParam)
0002 % waveAssess4dir: Wave Assessment for a directory of wave files(wadParam)
0003 %    Usage: waveData=waveAssess4dir(wadParam)
0004 %
0005 %    For example:
0006 %
0007 %        wadParam.language='english';            % Language
0008 %        wadParam.tcpFile='J:\error_wav\all.tcp';    % TCP file
0009 %        wadParam.waveDir='J:\error_wav';        % Directory for holding all the wave files
0010 %        wadParam.labDir='J:\error_wav\labDir';        % Output directory for holding the lab files. (A lab file will not be regenerated if it alreay exists.)
0011 %        wadParam.fileExtName='wa1';            % Extension name for the wave files
0012 %        wadParam.errorLogFile='J:\error_wav\error.log';    % Error log file
0013 %        waveData=waveAssess4dir(wadParam);
0014 
0015 %    Roger Jang, 20090615
0016 
0017 language=wadParam.language;
0018 tcpFile=wadParam.tcpFile;
0019 waveDir=wadParam.waveDir;
0020 labDir=wadParam.labDir;
0021 fileExtName=wadParam.fileExtName;
0022 errorLogFile=wadParam.errorLogFile;
0023 
0024 if exist(labDir)~=7
0025     fprintf('You need to create the output directory "%s" first!\n', labDir);
0026     return;
0027 end
0028 
0029 [date, time]=getDateTime;
0030 fid=fopen(errorLogFile, 'a'); fprintf(fid, 'date=%s, time=%s\n', date, time); fclose(fid);
0031 
0032 fprintf('Reading %s\n', tcpFile);
0033 [textBaseName, text]=textread(tcpFile, '%s %s');
0034 
0035 fprintf('Find text for each wave file in %s\n', waveDir);
0036 waveData=recursiveFileList(waveDir, fileExtName);
0037 waveNum=length(waveData);
0038 for i=1:waveNum
0039     [parentDir, waveData(i).baseName, ext, junk]=fileparts(waveData(i).path);
0040     index=find(strcmp(lower(waveData(i).baseName), lower(textBaseName)));
0041     if length(index)==1
0042         waveData(i).text=text{index};
0043     else
0044         waveData(i).text='';
0045         fprintf('Warning: No unique mapping for %s (i=%d)\n', waveData(i).path, i);
0046     end
0047 end
0048 
0049 fprintf('Start forced alignment for each wave file in %s\n', waveDir);
0050 for i=1:waveNum
0051     waveFile=waveData(i).path;
0052     text=waveData(i).text;
0053     if isempty(text)    % text is empty, skip this file.
0054         continue;
0055     end
0056     if strcmp(language, 'english')
0057         text=strrep(text, '_', ' ');            % For English
0058         text=strrep(text, '%percent', 'percent');    % For WSJ
0059         text=strrep(text, '%ampersand', 'ampersand');    % For WSJ
0060         text=strrep(text, '.period', 'period');        % For WSJ
0061     end
0062     labFile=[labDir, '/', waveData(i).baseName, '.lab'];
0063     if exist(labFile)==2    % labFile already exists, skip this file.
0064         continue;
0065     end
0066     fprintf('%d/%d: waveFile=%s, text=%s, labFile=%s\n', i, waveNum, waveFile, text, labFile);
0067     [cmObj, dosCmd, time, exeStatus, exeResult]=waveAssess(waveFile, text, language);
0068     % Save the output label file
0069     if ~isempty(cmObj)
0070         cm2labFile(cmObj, labFile);
0071     else    % Record the error message
0072         lines=split(exeResult, 10);
0073         fid=fopen(errorLogFile, 'a'); fprintf(fid, '%s\t%s\n', waveData(i).baseName, lines{end}); fclose(fid);
0074     end
0075 end

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