-2

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.

Cᴏʀʏ
  • 105,112
  • 20
  • 162
  • 194
jil harrys
  • 11
  • 2
  • 2
    What exactly do you mean by extracting a number from an audio file? Are you looking for byte data, spoken numeric values, volume levels. It's unclear what you are asking. – Cᴏʀʏ Feb 21 '17 at 22:34
  • Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. – techydesigner Feb 22 '17 at 02:46
  • what i actually want is to detected the differences between two audio. that is the original audio and an altered audio – jil harrys Feb 23 '17 at 19:45

1 Answers1

0

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.

Gal Aharon
  • 61
  • 2
  • 8