How to Convert Sampling Rate with Java

This worked for me.

http://stackoverflow.com/questions/2276027/converting-the-sample-rate-on-the-fly-when-reading-a-wav-file-into-a-samples-arr

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.

http://www.tritonus.org/tritonus_share-0.3.6.jar http://www.tritonus.org/tritonus_remaining-0.3.6.jar


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.