-
Notifications
You must be signed in to change notification settings - Fork 0
/
createFragments.m
executable file
·59 lines (56 loc) · 2.27 KB
/
createFragments.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% MASTER'S THESIS %
% %
% Student: Martin Hellwagner %
% Supervisor: Prof. Stefan Weinzierl (TU Berlin) %
% Advisor: Prof. Anders Friberg (KTH Stockholm) %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function fragments = createFragments(folder,extension,files,name,annotations)
% creating annotated audio fragments
fragments = cell(length(annotations),3);
for i = 1:length(annotations)
for j = 1:length(files)
if (strncmp(annotations{i,1},files{j,1},annotations{i,2}))
fragments{i,1} = annotations{i,1};
startTime = str2double(annotations{i,3})*(files{j,3}/1000);
endTime = str2double(annotations{i,4})*(files{j,3}/1000);
fragments{i,2} = files{j,2}(startTime:endTime);
fragments{i,3} = files{j,3};
end
end
end
% initializating values
name = strsplit(name,'-');
folder = [folder '/' name{1}];
index = 0;
if ~exist(folder,'dir')
mkdir(folder);
else
fileList = dir([folder '/']);
fileList = {fileList.name};
lastFile = fileList(end);
lastFile = strsplit(lastFile{1},'_');
index = str2num(lastFile{1});
end
% saving annotated audio fragments
j = 0;
for i = 1:length(fragments)
if (~isempty(fragments{i,1}))
fileName = [num2str(i+index-j) '_' name{2} '_' fragments{i,1} extension];
if ((i+index-j) < 10)
fragments{i,1} = [folder '/000' fileName];
elseif ((i+index-j) >= 10 && (i+index-j) < 100)
fragments{i,1} = [folder '/00' fileName];
elseif ((i+index-j) >= 100 && (i+index-j) < 1000)
fragments{i,1} = [folder '/0' fileName];
else
fragments{i,1} = [folder '/' fileName];
end
audiowrite(fragments{i,1},fragments{i,2},fragments{i,3});
else
j = j+1;
end
end
end