dan@0
|
1 function [segments,samples,labels] = read_data_develop(directoryAudio,directoryAnnotation,new_fs)
|
dan@0
|
2 %%
|
dan@0
|
3 % Mobilab 2012-2013
|
dan@0
|
4 %
|
dan@0
|
5 % Input arguments:
|
dan@0
|
6 % - directoryAudi:
|
dan@0
|
7 % Contains the path to the folder where the data is located
|
dan@0
|
8 % - directoryAnnotation:
|
dan@0
|
9 % Contains the path to the folders where the annotations are located
|
dan@0
|
10 % - new_fs:
|
dan@0
|
11 % Resample the .wav files to this sample frequency. If left
|
dan@0
|
12 % blank, no resampling occur
|
dan@0
|
13 % Output arguments
|
dan@0
|
14 % - segments is a cell structure:
|
dan@0
|
15 % Columns: # number of development examples
|
dan@0
|
16 % Rows: # numer of annotators
|
dan@0
|
17 % Each cell contains the segmented files from corresponding
|
dan@0
|
18 % development file and annotator
|
dan@0
|
19 % - samples is a cell structure:
|
dan@0
|
20 % Same structure as segments. Each cell contains the start and
|
dan@0
|
21 % stop time of the event.
|
dan@0
|
22 % - labels is a cell structure:
|
dan@0
|
23 % Same structure as segments. Each cell contains the labels of
|
dan@0
|
24 % the corresponding events
|
dan@0
|
25 %% Defaults
|
dan@0
|
26 down=1; if nargin < 3; down=0; end
|
dan@0
|
27 %% Annotation
|
dan@0
|
28 addpath(directoryAudio);
|
dan@0
|
29 files=find_format(directoryAudio, '.wav');
|
dan@0
|
30 names=files.names;
|
dan@0
|
31 nrScripts = length(names);
|
dan@0
|
32
|
dan@0
|
33 % Preallocation for speed
|
dan@0
|
34 segments=cell(1,nrScripts);
|
dan@0
|
35 samples=cell(1,nrScripts);
|
dan@0
|
36 labels=cell(1,nrScripts);
|
dan@0
|
37
|
dan@0
|
38 for(scriptNr=1:nrScripts)
|
dan@0
|
39
|
dan@0
|
40 [x_temp fs] = wavread(names{1,scriptNr});
|
dan@0
|
41 if(down==1)
|
dan@0
|
42 x_temp = resample(x_temp,new_fs,fs);
|
dan@0
|
43 fs=new_fs;
|
dan@0
|
44 end,
|
dan@0
|
45
|
dan@0
|
46
|
dan@0
|
47 addpath(directoryAnnotation);
|
dan@0
|
48 files2=find_format(directoryAnnotation, 'txt');
|
dan@0
|
49 annotation=textread(files2.names{1,i}, '%s' ,'delimiter', '\t');
|
dan@0
|
50 startStop=zeros(length(annotation)/3,2);
|
dan@0
|
51 id=cell(length(annotation)/3,1);
|
dan@0
|
52 u=1;
|
dan@0
|
53 for(v=1:3:length(annotation))
|
dan@0
|
54 startStop(u,1)=str2num(annotation{v,1});
|
dan@0
|
55 startStop(u,2)=str2num(annotation{v+1,1});
|
dan@0
|
56 x{u,2}=fs;
|
dan@0
|
57 x{u,1}=x_temp(ceil(startStop(u,1)*x{u,2})+1:ceil(startStop(u,2)*x{u,2}));
|
dan@0
|
58 id{u,1}=annotation{v+2,1};
|
dan@0
|
59 u=u+1;
|
dan@0
|
60 end,
|
dan@0
|
61 segments{k,i}=x;
|
dan@0
|
62 samples{k,i}=startStop;
|
dan@0
|
63 labels{k,i}=id;
|
dan@0
|
64 rmpath(directoryAnnotation{k,1});
|
dan@0
|
65 clear x;
|
dan@0
|
66 end,
|
dan@0
|
67 end
|
dan@0
|
68
|
dan@0
|
69
|
dan@0
|
70
|
dan@0
|
71
|
dan@0
|
72
|
dan@0
|
73
|
dan@0
|
74
|
dan@0
|
75
|
dan@0
|
76
|
dan@0
|
77
|
dan@0
|
78
|
dan@0
|
79
|
dan@0
|
80
|