Audio Feature Extraction
in
Share your Work
•
1 year ago
Hi!
Im working on a project about extracting features in bird sounds (e.g. spectral flux, spectral centroid, zero crossing, etc.) and I am currently using minim.
I try to get the spectral flux first in an audio, but why is that every time I run my program, the MEAN SPECTRAL FLUX changes though I am just using the same test audio file?
Also, is there a way to getBand() without playing the audio.
Also, is there a way to getBand() without playing the audio.
- import ddf.minim.spi.*;
import ddf.minim.signals.*;
import ddf.minim.*;
import ddf.minim.analysis.*;
import ddf.minim.ugens.*;
import ddf.minim.effects.*;
import java.io.*;
Minim minim;
AudioPlayer input;
FFT fft;
String sound;
String windowName;
int index;
double[] spectrum;
double[] myspectrum;
double[] lastspectrum;
double spectralcentroid = 0;
double spectralflux = 0;
void setup()
{
size(512, 200, P3D);
minim = new Minim(this);
//sound = getParameter("sound");
sound = "D:/Downloads/Brown Shrike Call 3.wav";
input = minim.loadFile(sound);
input.play();
fft = new FFT(input.bufferSize(), input.sampleRate());
myspectrum = new double[input.bufferSize()];
spectrum = new double[fft.specSize()];
lastspectrum = new double[fft.specSize()];
Arrays.fill( lastspectrum, 0 );
}
void draw()
{
fft.forward(input.mix);
/*-------------SPECTRAL FLUX---------------*/
double flux = 0;
for( int i = 0 ; i < fft.specSize() ; i++)
{
spectrum[i] = Math.abs(fft.getBand(i));
flux += spectrum[i] - lastspectrum[i];
}
spectralflux += flux;
try{
// Create file
FileWriter fstream = new FileWriter("features.txt");
BufferedWriter out = new BufferedWriter(fstream);
out.write("Bandwidth: " + Double.toString(fft.getBandWidth()));
out.newLine();
out.write("Spectral Flux: " + Double.toString(spectralflux/fft.specSize()));
//Close the output stream
out.close();
}catch (Exception e){//Catch exception if any
System.err.println("Error: " + e.getMessage());
}
if(input.isPlaying() == false) exit();
}
void stop()
{
// always close Minim audio classes when you finish with them
input.close();
minim.stop();
super.stop();
}
THANKS!