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 package org.openimaj.audio.analysis.benchmarking.dataset;
31
32 import java.io.File;
33 import java.io.FileFilter;
34 import java.io.FilenameFilter;
35
36 import org.openimaj.citation.annotation.Reference;
37 import org.openimaj.citation.annotation.ReferenceType;
38 import org.openimaj.data.dataset.Dataset;
39 import org.openimaj.data.dataset.ListBackedDataset;
40 import org.openimaj.data.dataset.MapBackedDataset;
41 import org.openimaj.experiment.annotations.DatasetDescription;
42
43 import cern.colt.Arrays;
44
45
46
47
48
49
50
51 @DatasetDescription(
52 name = "Music-Speech Dataset",
53 description = "The 'music-speech' corpus is a small collection of some 240 " +
54 "15-second extracts collected 'at random' from the radio by Eric Scheirer " +
55 "during his internship at Interval Research Corporation in the summer of 1996 " +
56 "under the supervision of Malcolm Slaney",
57 url = "http://labrosa.ee.columbia.edu/sounds/musp/scheislan.html")
58 @Reference(
59 type = ReferenceType.Inproceedings,
60 author = { "Scheirer E.", "Slaney, M." },
61 title = "Construction And Evaluation Of A Robust Multifeature Speech/music Discriminator",
62 year = "1997",
63 booktitle = "Proc. ICASSP-97, Munich.")
64 public class MusicSpeechDataset extends MapBackedDataset<String, Dataset<File>, File>
65 {
66
67 private File soundsDir;
68
69
70
71
72
73
74
75 public MusicSpeechDataset( final File baseDir, final boolean testOrTrain )
76 {
77
78 String soundsDir = "wavfile" + File.separator;
79 soundsDir += testOrTrain? "test" : "train";
80
81 this.processDir( this.soundsDir = new File( baseDir, soundsDir ) );
82
83 System.out.println( this );
84 }
85
86 private void processDir( final File dir )
87 {
88 final File[] groups = dir.listFiles( new FileFilter()
89 {
90 @Override
91 public boolean accept( final File pathname )
92 {
93 return pathname.isDirectory() &&
94 !pathname.getName().equals( "." ) &&
95 !pathname.getName().equals("..");
96 }
97 } );
98
99 System.out.println( Arrays.toString( groups ));
100
101 if( groups.length == 0 )
102 {
103 System.out.println( "Processing "+dir );
104
105 final File[] files = dir.listFiles( new FilenameFilter()
106 {
107 @Override
108 public boolean accept( final File dir, final String name )
109 {
110 return name.endsWith( ".wav" );
111 }
112 } );
113
114 final ListBackedDataset<File> list = new ListBackedDataset<File>();
115 this.map.put( dir.getAbsolutePath().substring( this.soundsDir.getAbsolutePath().length()+1 ), list );
116
117 for( final File file : files )
118 {
119 list.add( file );
120 }
121 }
122 else
123 {
124 for( final File group: groups )
125 this.processDir( group );
126 }
127 }
128 }