Wav file convert to byte array in java

user1367678 picture user1367678 · May 1, 2012 · Viewed 28.2k times · Source

My project is 'Speech Recognition of Azeri speech'. I have to write a program that converts wav files to byte array.

How to convert audio file to byte[]?

Answer

Andrew Thompson picture Andrew Thompson · May 1, 2012

Basically as described by the snippet in the first answer, but instead of the BufferedInputStream use AudioSystem.getAudioInputStream(File) to get the InputStream.

Using the audio stream as obtained from AudioSystem will ensure that the headers are stripped, and the input file decode to a byte[] that represents the actual sound frames/samples - which can then be used for FFT etc.