Home > asr > getWaveData.m

getWaveData

PURPOSE ^

GETWAVE Get wave files for given speaker

SYNOPSIS ^

function waveData = getWaveData(speaker, waveDir)

DESCRIPTION ^

 GETWAVE Get wave files for given speaker
    Usage: waveData = getWaveData(speaker, waveDir)
        speaker: intended speaker ({'roger', 'bob'} for two sigers; 'all' for all speaker)
        waveDir: wave directory
        waveData: collected wave information

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function waveData = getWaveData(speaker, waveDir)
0002 % GETWAVE Get wave files for given speaker
0003 %    Usage: waveData = getWaveData(speaker, waveDir)
0004 %        speaker: intended speaker ({'roger', 'bob'} for two sigers; 'all' for all speaker)
0005 %        waveDir: wave directory
0006 %        waveData: collected wave information
0007 
0008 if nargin<1, speaker={'張智星'}; end
0009 if nargin<2, waveDir = 'D:\dataset\asr_hmm\唐詩'; end
0010 
0011 if strcmp(speaker{1}, 'all'),
0012     speaker=dir(waveDir);
0013     if isempty(speaker), waveData=[]; return; end
0014     speaker(1:2)=[];
0015     speaker(~[speaker.isdir])=[];
0016     speaker={speaker.name};
0017 end
0018 
0019 waveData=[];
0020 for i=1:length(speaker),
0021     fprintf('Reading data from %s... ', speaker{i});
0022     thisWaveData=getSpeakerWaveData(speaker{i}, waveDir);
0023     if length(thisWaveData)==0,
0024         thisWaveData=[];
0025     end
0026     fprintf('%d wave files.\n', length(thisWaveData));
0027     waveData=[waveData; thisWaveData];
0028 end
0029 
0030 % ======= Definitions for subfunctions
0031 function waveData = getSpeakerWaveData(speaker, waveDir)
0032 % GETWAVE Get wave files for a given speaker
0033 %    Usage:
0034 %    waveData = getwave(speaker, fromMiddle, waveDir)
0035 %        speaker: intended speaker
0036 %        waveDir: wave directory
0037 %        waveData: collected wave information
0038 
0039 if nargin<1, speaker='張智星'; end
0040 if nargin<2, waveDir = 'd:\dataset\cbmr\哼唱的歌\'; end
0041 
0042 if strcmp(waveDir(end), '/') | strcmp(waveDir(end), '\'),
0043     waveDir = waveDir(1:end-1);
0044 end
0045 
0046 fileSpec = [waveDir, '\', speaker, '\*.wav'];
0047 waveData = dir(fileSpec);
0048 
0049 for i=1:length(waveData),
0050     % Put various info into fields
0051 %    try,
0052         waveData(i).speaker=speaker;
0053         waveData(i).path=[waveDir, '\', speaker, '\', waveData(i).name];
0054         waveData(i).text = waveData(i).name(1:end-4);
0055         index=find(waveData(i).text=='%');    % Find the position of %
0056         if ~isempty(index)
0057             waveData(i).text=waveData(i).text(1:index(1)-1);    % Get rid of things after %
0058         end
0059         index=find(waveData(i).text=='_');    % Find the position of _
0060         if ~isempty(index)
0061             waveData(i).text=waveData(i).text(1:index(1)-1);    % Get rid of things after _
0062         end
0063         while (waveData(i).text(end)=='#')                % 若歌名重複,會加上「#」字號
0064             waveData(i).text=waveData(i).text(1:end-1);
0065         end
0066     %    while any(strcmp(waveData(i).text(end), {'1', '2', '3', '4', '5', '6', '7', '8', '9', '0'}))    % 砍掉尾巴的數字
0067     %        waveData(i).text=waveData(i).text(1:end-1);
0068     %    end
0069         answerFile=[waveDir, '\', speaker, '\answer.txt'];
0070         if exist(answerFile)==2
0071             waveData(i).text=getAnswer(waveData(i).name, answerFile);
0072         end
0073         waveData(i).errorMsg = '';
0074 %    catch,
0075 %        fprintf(' ===> Error in parsing %s!\n', waveData(i).name);
0076 %        waveData(i).text = '';
0077 %        waveData(i).errorMsg = 'File name parsing error';
0078 %    end
0079 end
0080 
0081 
0082 % ====== 從 answerFile 抓出每一個 wave 檔案所對應到的文字
0083 function text=getAnswer(waveFileName, answerFile)
0084 [fileName, answerText]=textread(answerFile, '%s\t%s');
0085 index=findcellstr(fileName, waveFileName(1:end-4));
0086 text=answerText{index};

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