📄 timit.m
字号:
%TIMIT interface ver 1.00 (1/1/08)
%Made by Kobi Nistel for SIPL.
%Thanks to
%Yevgeni Litvin.
%Odedd Fridman.
%Exemples:
% db = timitdb; - loads form defalut path.
% db2 = timitdb('c:\path'); load from a path.
function [this default_path] = timit(init_dir)
%checks the location of the timitdb directory
data_file_path = which('@timit/timit'); %to be fixed
data_file_path = data_file_path(1:end-7); %to be fixed
%TIMIT path form file: 'default_path.txt'
if (nargin<1)
default_path = textread([data_file_path ,'\default_path.txt'],'%s');
init_dir = default_path{1};
for ii=2:length(default_path)
init_dir = [init_dir ,' ',default_path{ii}];
end
end
persistent cachedDataBase;
this = databaseclass;
this.path = init_dir; %sets global path
this.kind = 1; %sets DB as sentence
this.name = 'timit'; %to do:from a file
%checks for exisitence of 'tmdb.mat'
if( ~exist([data_file_path 'tmdb.mat'], 'file'))
this = makedb(init_dir,this);
save([data_file_path 'tmdb'],'this');
cachedDataBase = this;
else
fprintf('Loading %s...\n',this.name);
if isempty(cachedDataBase)
load([data_file_path 'tmdb']);
cachedDataBase = this;
else
this = cachedDataBase;
end
end
fprintf('Enteries: %d\n',this.entriesNumber);
end
function this = makedb(init_dir,this)
fprintf('Generating database file...\n');
for train_testC=1:2 %USAGE: Test / Run
switch train_testC
case 1, train_test = 'train';
case 2, train_test = 'test';
end
for dialectC=1:8 % Dialects
switch dialectC
case 1, dialect = 'dr1';
case 2, dialect = 'dr2';
case 3, dialect = 'dr3';
case 4, dialect = 'dr4';
case 5, dialect = 'dr5';
case 6, dialect = 'dr6';
case 7, dialect = 'dr7';
case 8, dialect = 'dr8';
end
speaker_dirs = dir([init_dir,'\',train_test,'\',dialect,'\*.']); %speakers
for sex_speakerC = 1:length(speaker_dirs)
if( strcmpi(speaker_dirs(sex_speakerC).name(1) , 'F') )
sex = 'F';
else
sex = 'M';
end
speaker = speaker_dirs(sex_speakerC).name(2:end); %Cutting the F/M
direct=[init_dir,'\',train_test,'\',dialect,'\',speaker_dirs(sex_speakerC).name];
files=dir([direct,'\*.wav']);
for sentenceC = 1:length(files)
%read on sentence data:
this.enteries(end+1).ID = length(this.enteries); %couses an empty cell in db(1)!!
this.enteries(end).sentence = files(sentenceC).name(1:end-4); %no exonetion
this.enteries(end).usage = train_test;
this.enteries(end).dialect = dialect;
this.enteries(end).sex = sex;
this.enteries(end).speaker = speaker;
%read in sentence data:
%words:
[b,e,name]=textread([direct ,'\',this.enteries(end).sentence ,'.WRD'],'%n %n %s');
%a "silence" word thet all not word assieted phonems
%can point to.
name{end+1}='h#';
b(end+1) = 1;
e(end+1) = 1;
for temp=1:length(name), name{temp} = [name{temp},' ']; end
%b = b+1; %the Timit readings starts from zero
%e = e+1; %the Timit readings starts from zero
this.enteries(end).word.name = char (name);
this.enteries(end).word.b = b;
this.enteries(end).word.e = e;
this.enteries(end).word.flag = ones(length(b),1,'int8');
%phonems:
[b,e,name]=textread([direct ,'\',this.enteries(end).sentence ,'.PHN'],'%n %n %s');
for temp=1:length(name), name{temp} = [name{temp},' ']; end
%b = b +1; %the Timit readings starts from zero
%e = e +1; %the Timit readings starts from zero
this.enteries(end).phoneme.name = char (name);
this.enteries(end).phoneme.b = b;
this.enteries(end).phoneme.e = e;
this.enteries(end).phoneme.flag = ones(length(b),1,'int8');
this.enteries(end).phoneme.from = length(this.enteries(end).word.flag)*ones(length(b),1,'int8');
for pho_in=1:length(b)
for jj=1:length(this.enteries(end).word.b)
if(this.enteries(end).phoneme.b(pho_in)>=this.enteries(end).word.b(jj)-1)...
&&(this.enteries(end).phoneme.e(pho_in)<=this.enteries(end).word.e(jj)+1)
this.enteries(end).phoneme.from(pho_in)=jj;
continue;
end
end
end
end
end
end
end
this.enteries = this.enteries(2:end);%becouse the first entery is empty
this.entriesNumber = length(this.enteries);
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -