I need to do an analysis on sounds to check if it was hampered or deleted.
import java.net.URL;
import javax.swing.*;
import javax.sound.sampled.*;
public class LoopSounds {
public static void main(String[] args) throws Exception {
URL url = new URL(
"http://pscode.org/media/leftright.wav");
Clip clip = AudioSystem.getClip();
AudioInputStream ais = AudioSystem.
getAudioInputStream( url );
clip.open(ais);
URL url2 = new URL(
"http://pscode.org/media/100_2817-linear.wav");
Clip clip2 = AudioSystem.getClip();
AudioInputStream ais2 = AudioSystem.
getAudioInputStream( url2 );
clip2.open(ais2);
// loop continuously
clip.loop(Clip.LOOP_CONTINUOUSLY);
clip2.loop(Clip.LOOP_CONTINUOUSLY);
SwingUtilities.invokeLater(new Runnable() {
public void run() {
// A GUI element to prevent the Clip's daemon Thread
// from terminating at the end of the main()
JOptionPane.showMessageDialog(null, "Close to exit!");
}
});
}
}
But I would be doing a comparison between two sounds, and I need to extract the numeric values for my analysis.
AudioInputStream has a read() method.
You may make a function like this:
public void compareVoices(AudioInputStream ais,AudioInputStream ais2){
for(int i = 0;i>ais.getFrameLength;i++){
if(ais.read()!=ais2.read()){
return(false);
}
}
return(true);
}
Note: This function will work just if these two .wav files are exactly the same.