使用(Java) AudioInputStream打开wav文件时的问题



我正在使用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());
        }

对于我如何处理这个案子有什么建议吗?提前感谢

您的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());
}

最新更新