tags:

views:

226

answers:

2
A: 

Are you sure the audio file is in valid format? The exception normally means that java can't interpret the data read form the file as valid audio data.

Are you sure the settings you provide with ULAW_FORMAT are correct?

I'm not familiar with µ-law encoding but are the values for frameSize and frameRate correct?

You could also try

AudioSystem.getAudioInputStream(AudioFormat.Encoding.ULAW, inputFileStream);

If that too doesn't work either the file has invalid audio data or java has some parsing bug.

jitter
Check my update Jitter. (Thanks for your answer)
Castanho
About your question if I'm sure that this is a audio file. Yes, I'm sure because I'm able to open this file in GoldWave (www.goldwave.com/). To open the file I use the options (File type: raw, Attributes µ-law MONO, Rate 8000 Hz)
Castanho
A: 

µ-law is a sample value encoding and not a file format, so using the AudioSystem to find a suitable AudioReader for a "µ-law file" (whatever that is) is going to fail. If I'm not mistaken, Sun's VM has built-in support for AIFF, AU and WAV files.

I'm now only guessing, but if your file contains raw µ-law data without any file format header, you can simply create an AudioInputStream directly, without going through the utility methods in AudioSystem:

int length = ... // file length in number of samples
FileInputStream fis = new FileInputStream("...");

AudioInputStream ais = new AudioInputStream(
    fis, new AudioFormat(AudioFormat.Encoding.ULAW, 8000, 8, 1, 1, 8000, false), length);

And at last: if your first question is really correct (you are only trying to get the duration of the file), there is no need to fight with the AudioInputStream. If the file really contains raw µ-law data with 8000 samples/s and each sample is one byte, it's eeh, well you get it?

jarnbjo
This help me! Thanks!
Castanho