我正在使用JDK7并尝试运行wav文件 - 我尝试了以下测试但是在下面复制了错误:
错误:
line with format ULAW 8000.0 Hz, 8 bit, mono, 1 bytes/frame, not supported.
示例代码:
import javax.sound.sampled.*;
try {
Clip clip = AudioSystem.getClip();
AudioInputStream inputStream = AudioSystem.getAudioInputStream(
new File("C://Users//xyz//Desktop//centerClosed.wav"));
clip.open(inputStream);
clip.start();
} catch (Exception e) {
System.err.println(e.getMessage());
}
关于我如何处理这个案子的任何想法?提前致谢
答案 0 :(得分:1)
您的wav
文件似乎采用ULAW格式,采样频率为8kHz,这是剪辑显然无法理解的格式。
尝试将音频转换为44.1kHz PCM,如下所示:
import javax.sound.sampled.*;
try {
Clip clip = AudioSystem.getClip();
AudioInputStream ulawIn = AudioSystem.getAudioInputStream(
new File("C://Users//xyz//Desktop//centerClosed.wav"));
// define a target AudioFormat that is likely to be supported by your audio hardware,
// i.e. 44.1kHz sampling rate and 16 bit samples.
AudioInputStream pcmIn = AudioSystem.getAudioInputStream(
new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, 44100f, 16, 1, 2, 44100f, true)
ulawIn);
clip.open(pcmIn);
clip.start();
} catch (Exception e) {
System.err.println(e.getMessage());
}