Monthly Archives: March 2012

How to Convert Sampling Rate with Java

This worked for me.

You can convert by applying AudioSystem.getAudioInputStream to an AudioInputStream object, and you get another AudioInputStream as the result.  Here is the sample code of the part:

AudioInputStream inStream = AudioSystem.getAudioInputStream(soundFile); AudioFormat outDataFormat = new AudioFormat(8000.0f, 16, 1, 2, true, false); AudioInputStream outStream = AudioSystem.getAudioInputStream(outDataFormat, inStream);

In order to make above code work, we need following two extensions.  Without these extensions, we get exception on the execution above.