My application involves uploading a wave file via a web UI, converting format to 8k, 8 bit mulaw and storing it on the server. My code is failing on the server when trying to do:
final AudioInputStream ais = AudioSystem.getAudioInputStream( in );
The error is:
Caused by: javax.sound.sampled.UnsupportedAudioFileException: could not get audio input stream from input stream
at javax.sound.sampled.AudioSystem.getAudioInputStream(AudioSystem.java:1102) [classes.jar:1.6.0_65]
So I scaled back to a simple test case where I try to load the audio file as a local file:
final File audioFile = new File("/path/to/audio.wav");
final InputStream in = new FileInputStream( file );
final AudioInputStream ais = AudioSystem.getAudioInputStream( in );
This works.
I then went back to my server side and added some debugging like so:
final byte[] audio = IOUtils.toByteArray( in );
final File audioLog = File.createTempFile( "audiolog", ".wav" );
IOUtils.write( audio, new FileOutputStream( audioLog ) );
s_logger.info( "File logged to: " + audioLog.getAbsolutePath() );
final InputStream byteIn = new ByteArrayInputStream( audio );
final AudioInputStream ais = AudioSystem.getAudioInputStream( byteIn );
This fails in the exact same way.
I then compare the original file that was uploaded against the audio file logged on the server and they are identical, right down to the checksum:
$ cksum uploaded.wav
4019972581 84076 uploaded.wav
$ cksum audiolog6415586848170376004.wav
4019972581 84076 audiolog6415586848170376004.wav
Any ideas what may be going on? My server side code run on JBoss 7.1.
Thanks.
-Raj
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…