Matlab程序:
function aucut(t,overlap)% t 为切割秒数,overlap 为样本重叠秒数
mkdir('classical10s');%创建保存剪切后语音的文件夹
file = '/Users/liupeng/Desktop/matlab/speechRecognition/classical/';
file1 = strcat(file, '*.au');
a=dir(file1); %在文件夹中搜索以.au 为后缀的文件并记录,如.wav 文件则搜*.wav
for i=1:length(a)%读取.au 后缀文件的数目
file2 = strcat(file, a(i).name);
[y1,fs]=audioread(file2);%读取.au 文件的数值与参数,如.wav 文件则 wavread
str1 = strcat('/Users/liupeng/Desktop/matlab/speechRecognition/classical10s/', a(i).name);%记录其中一个.au 文件的名称
j=fix((length(y1)/fs-overlap)/(t-overlap));%切割后音乐的份数
for k=1:j%对每首音乐进行切割并命名
y2=y1(((k-1)*t*fs-(k-1)*overlap*fs +1):(k*t*fs-(k-1)*overlap*fs+1));
filename=strcat(str1,'_');
filename=strcat(filename,num2str(k-1));
filename=strcat(filename,'.wav');
%cd(foldername)
%if (j<=2)|| (k~=1 && k~=j)%若是 Jamendo 数据库,则调用切去首尾
audiowrite(filename,y2,fs);%若.wav 文件则为 wavwrite.
%end
cd ..
end
end
end