An older Java-program I maintain comes with a bunch of little .au files to play different sounds. All of these are identified by file as: Sun/NeXT audio data: 8-bit ISDN mu-law, mono, 8000 Hz.
The program fails to play them complaining of unsuitable format. Having modified its format-selection to dump debug information, I came up with the following Java-code:
protected static AudioFormat getFormatForPlaying(byte [] audioData)
throws UnsupportedAudioFileException, IOException{
ByteArrayInputStream bais = new ByteArrayInputStream(audioData);
AudioFormat format = AudioSystem.getAudioFileFormat(bais).getFormat();
DataLine.Info info = new DataLine.Info(SourceDataLine.class, format);
if (AudioSystem.isLineSupported(info)) {
System.err.println("Audio format ``" + format + "'' can be used straight");
return format;
}
System.err.println("Audio format ``" + format + "'' can not be used straight");
AudioFormat[] possibleFormats = AudioSystem.getTargetFormats(
AudioFormat.Encoding.PCM_SIGNED, format);
for (AudioFormat newFormat : possibleFormats) {
info = new DataLine.Info(SourceDataLine.class, newFormat);
if (AudioSystem.isLineSupported(info)) {
System.err.println("Will try audio format " + newFormat + " instead of " + format);
return newFormat;
}
System.err.println("Format ``" + newFormat + "'' cannot be used");
}
throw new UnsupportedAudioFileException("No suitable audio format among " +
possibleFormats.length + " possibilities");
}
At run time I get the following printed to stderr now:
Audio format ``ULAW 8000.0 Hz, 8 bit, mono, 1 bytes/frame, '' can not be used straight
Format ``PCM_SIGNED 8000.0 Hz, 16 bit, mono, 2 bytes/frame, little-endian'' cannot be used
Format ``PCM_SIGNED 8000.0 Hz, 16 bit, mono, 2 bytes/frame, big-endian'' cannot be used
javax.sound.sampled.UnsupportedAudioFileException: No suitable audio format among 2 possibilities
Google's AI is telling me, that just means, my actual sound hardware cannot play such low rate audio, and that's that -- the sound library included in Java cannot modify the sampling rate for me, period...
Is that really true? If so, is there an easy way out -- such as by using some known and common conversion package?
(When I play the same sound-files using mplayer, for example, it reports converting them from 8kHz to 16kHz automatically.)