I want to convert audio InputStream to wav file format in java.
Require format is : mu-law 8000 Hz 64 kbps Mono
I am using the following method for the conversion but generated audio file is corrupted.
public static void getWavFile(String filePath, InputStream audioStream) throws IOException, UnsupportedAudioFileException {
try {
byte[] decodedData = IOUtils.toByteArray(audioStream);
File outFile = new File(filePath);
AudioFormat format = new AudioFormat(AudioFormat.Encoding.ALAW, 8000, 16, 2, 4, 8000, false);
AudioSystem.write(new AudioInputStream(new ByteArrayInputStream(decodedData), format, decodedData.length),
AudioFileFormat.Type.WAVE, outFile);
} catch (IOException ex) {
ex.printStackTrace();
}
}
I am using this audio file to play in my IVR flow and it strictly allow only the given format.