Das Programm kann sie nicht abspielen und beschwert sich über ein ungeeignetes Format. Nachdem ich die Formatauswahl geändert hatte, um Debug-Informationen auszugeben, kam ich auf den folgenden Java-Code:
Code: Select all
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");
}
Code: Select all
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
Ist das wirklich wahr? Wenn ja, gibt es einen einfachen Ausweg – beispielsweise die Verwendung eines bekannten und gängigen Konvertierungspakets?
(Wenn ich beispielsweise dieselben Sounddateien mit mplayer abspiele, meldet es die automatische Konvertierung von 8 kHz in 16 kHz.)
Mobile version