📄 opentimit.m
字号:
function [Y, vargout]=opentimit(varargin)% function [Y, vargout]=opentimit(varargin)% get the file name and path using the file dialogpersistent lastpath;if ~nargin prevpath = pwd; if lastpath cd(lastpath); end [FileName,PathName]=uigetfile('*.wav','Open audio file'); if PathName lastpath = PathName; end cd(prevpath); if FileName==0 Y=0; return end fname=[PathName FileName];else fname=varargin{1};enddata = readnist(fname);y = data.s;fs = data.sample_rate;if size(y,2)==1 Y = signal(y,fs);else for i=1:size(y,2) Y{i} = signal(y(:,i),fs); endendif nargout > 1 vargout = data;end% ----------------------function data = readnist(file)%function data = readnist(file)% read TIMIT-wave files% we're using a lot of try-statements, since sometimes the formats vary and% I didn't care to make a lot of checks. Somebody should clean up this mess.% -Tom Bäckström 16.6.2005% strip endingif strcmp(upper(file(end-(3:-1:0))),'.WAV') file = file(1:end-4);endfid = fopen([file '.WAV']);try tline1 = fgetl(fid); if ~strcmp(tline1(1:4),'NIST') error('Not a NIST file'); end data.nist_version = tline1(6:end); tline2 = fgetl(fid); data.header_length = str2double(tline2); header = char(fread(fid,data.header_length - length(tline1) - length(tline2) - 2)'); [names, len, fieldval] = strread(header,'%s %s %s\n'); for k=1:size(fieldval,1) eval(['data.' names{k} '=''' fieldval{k} ''';']); end data.sample_count = str2double(data.sample_count); data.sample_rate = str2double(data.sample_rate); data.sample_max = str2double(data.sample_max); data.sample_min = str2double(data.sample_min); data.sample_n_bytes = str2double(data.sample_n_bytes); data.sample_byte_format = str2double(data.sample_byte_format); data.sample_sig_bits = str2double(data.sample_sig_bits); data.channel_count = str2double(data.channel_count); if data.sample_byte_format == 1 data.s = fread(fid,'int16'); else error('Unknown data format'); end endfclose(fid);fid = fopen([file '.TXT']);try textdata = char(fread(fid)'); ix = sscanf(textdata,'%d'); %data.text = fgetl(fid); k = 1; spaces = 0; while spaces < 2 && k < length(textdata) if textdata(k) == ' ' spaces = spaces + 1; end k = k+1; end data.text.start = ix(1); data.text.end = ix(2); data.text.str = textdata(k:end);endfclose(fid);fid = fopen([file '.PHN']);try phondata = char(fread(fid)'); [startix, endix, phon] = strread(phondata,'%s %s %s\n'); for k=1:length(phon) data.phone_list(k).start = str2double(startix{k}); data.phone_list(k).end = str2double(endix{k}); data.phone_list(k).phone = phon{k}; endendfclose(fid);fid = fopen([file '.WRD']);try worddata = char(fread(fid)'); [startix, endix, word] = strread(worddata,'%s %s %s\n'); for k=1:length(word) data.word_list(k).start = str2double(startix{k}); data.word_list(k).end = str2double(endix{k}); data.word_list(k).word = word{k}; endendfclose(fid);%------function d = str2double(str)ix = find(str == ' ');str(ix) = [];if str(1)=='-' strsign = -1; str(1) = [];elseif str(1)=='+' strsign = +1; str(1) = [];else strsign = 1;endstr = double(str)-double('0');d = 0;for k=1:length(str) d = 10*d + str(k);endd = strsign*d;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -