timit常用来做语音识别及说话人识别,毕竟开源的语音库太少了,格式:16k 16bit pcm编码 完整应该是6300段语音
timit是SPHERE格式的,用的时候需要转换下格式
http://www.360doc.com/content/17/0718/09/45512753_672245873.shtml
这个是直接替换原始的文件,后面修改下,改成在新的目录生成,免得还要重新整理一遍
1、find_wav.m 查找wav文件
function [ wav_files ] = find_wav( path )
%FIND_WAV, find all wav file recursively
wav_files = [];
if(isdir(path) == 0)
return;
end
path_files = dir(path);
fileNum = length(path_files);
for k= 3:fileNum
file = [path,'\', path_files(k).name];
if (path_files(k).isdir == 1)
ret = find_wav(file);
if(isempty(ret) ~= 1)
if(isempty(wav_files))
wav_files = char(ret);
else
wav_files = char(wav_files, ret);
end
end
elseif strfind(path_files(k).name, '.WAV')
if(isempty(wav_files))
wav_files = char(file);
else
wav_files = char(wav_files, file);
end
end
end
end
注意:这个程序在运行第二次时会将新生成的文件也处理,可以重新设置存储的路径,不过貌似直接设置不行,要先创建文件夹才行
%SPHERE 文件转换为wav文件
%clear all;
fs = 16000;
files = find_wav('F:\TIMIT\TRAIN');
%SPHERE 文件转换为wav文件
%clear all;
fs = 16000;
files = find_wav('F:\TIMIT\TRAIN');
for fileIdx = 1:length(files)
file = deblank(files(fileIdx,:));
file_splits = regexp(file, '\\', 'split');
newfile = deblank(strcat('F:\TIMIT\TRAIN', '\', file_splits(end-1), '_', file_splits(end)));
fileID = fopen(file);
newfile_path= newfile{1};
%判断文件头,防止误操作
head = fread(fileID, 1024, 'char*1');
headStr = sprintf('%s',head(1:7));
if(~strcmp(headStr,'NIST_1A'))
fclose(fileID);
continue;
end
frewind(fileID);
allData = fread(fileID, inf, 'short');
fclose(fileID);
% delete(file);
wavwrite(allData(513:end)./32768, fs, newfile_path); %SPHERE 文件头1024字节
% fclose(fileID);
end
clear all;
files = find_wav('.');
for fileIdx = 1:length(files)
file = files(fileIdx,:);
[y, fs, nbits] = wavread(file);%不是wav文件就会报错
if(fs~=16000)
fprintf('%s: fs~=16000\n', file);
end
if(nbits ~= 16)
fprintf('%s: nbits ~= 16\n', file);
end
end