16 비트 및 24 비트 샘플링 비트 심도의 오디오 파일을 읽고 문제없이 길이를 결정하기 위해 파싱합니다. 32 비트 파일을 읽을 때, I는Java AudioSystem : 32 비트 Wav 파일 읽기
javax.sound.sampled.UnsupportedAudioFileException: could not get audio input stream from input file
at javax.sound.sampled.AudioSystem.getAudioInputStream(AudioSystem.java:1170)
...
32 비트 테스트 파일을 수동으로 다른 (선형 PCM)와 같은 방식으로 인코딩을 얻는다. AudioSystem이 32 비트 Wav를 지원하지 않거나, 대안이 있을지 궁금합니다. 참고로 다음은 수업입니다.
import java.io.*;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
public class soundUtility {
public static double getWavDuration(File filename)
{
AudioInputStream stream = null;
try
{
stream = AudioSystem.getAudioInputStream(filename);
AudioFormat format = stream.getFormat();
return filename.length()/format.getSampleRate()/(format.getSampleSizeInBits()/8.0)/format.getChannels();
}
catch (Exception e)
{
e.printStackTrace();
return -1;
}
finally
{
try { stream.close(); } catch (Exception ex) { }
}
}
public static void main(String[] args) {
try {
// ===== TESTS: toggle these calls to test the included files =====
// File soundFile = new File("16bit.mono.441k.30secs.wav");
// File soundFile = new File("24bit.48k.11secs.stereo.wav");
File soundFile = new File("32bit.Floating.Stereo.48k.wav");
// ===========
System.out.println(getWavDuration(soundFile));
} catch (Exception e) {
e.printStackTrace();
}
}
}
통찰력을 가져 주셔서 감사합니다.