Paweł
Paweł

Reputation: 21

How can I read info from .wave file using JavaSound (Java, Java Sound)

Hi I need to read SampleRate, SignalFrequency and Amplitude from .wave file. How can I do that using JavaSound?

Upvotes: 2

Views: 2749

Answers (1)

Mansoor Siddiqui
Mansoor Siddiqui

Reputation: 21663

You can get the sampling rate by getting a handle on the AudioFormat object:

AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(new File("test.wav"));
AudioFormat audioFormat = audioInputStream.getFormat();

Once you have that, you can get the sample rate as follows:

float sampleRate = audioFormat.getSampleRate();

As for the amplitude, that is basically the raw .wav file data, which you can access directly from the audioInputStream by calling any of its read() methods.

Upvotes: 5

Related Questions