我正在开发一个需要从麦克风录制声音的基于 Java 的应用程序。以下是我的代码:
audioFormat = new AudioFormat(8000, 16, 1, true, false);
targetInfo = new DataLine.Info(TargetDataLine.class, audioFormat);
try {
targetDataLine = (TargetDataLine) AudioSystem.getLine(targetInfo);
targetDataLine.open(audioFormat, 320);
targetDataLine.start();
} catch (LineUnavailableException ex) {
java.util.logging.Logger.getLogger(SoundManager.class.getName()).log(Level.SEVERE, null, ex);
}
在这里,我在“targetDataLine.open(audioFormat, 320);”行遇到异常
javax.sound.sampled.LineUnavailableException:行格式为 PCM_SIGNED 8000.0 Hz,16 位,单声道,2 字节/帧,不支持 little-endian。
我已将 PC 的硬件和操作系统更改为 CentOS7,相同的代码在以前的硬件和操作系统 CentOS 6.7 上运行良好。
我检查了我现在的电脑支持的格式,如下:
> Supported SourceDataLines of default mixer (PCH [default]):
>
> interface SourceDataLine supporting 48 audio formats, and buffers of
> at least 32 bytes max buffer size: -1 min buffer size: 32
> Supported Audio formats:
> PCM_SIGNED unknown sample rate, 16 bit, mono, 2 bytes/frame, little-endian
> PCM_SIGNED unknown sample rate, 16 bit, mono, 2 bytes/frame, big-endian
> PCM_SIGNED unknown sample rate, 16 bit, stereo, 4 bytes/frame, little-endian
> PCM_SIGNED unknown sample rate, 16 bit, stereo, 4 bytes/frame, big-endian
> PCM_SIGNED unknown sample rate, 16 bit, 3 channels, 6 bytes/frame, little-endian
> PCM_SIGNED unknown sample rate, 16 bit, 3 channels, 6 bytes/frame, big-endian
> PCM_SIGNED unknown sample rate, 16 bit, 4 channels, 8 bytes/frame, little-endian
> PCM_SIGNED unknown sample rate, 16 bit, 4 channels, 8 bytes/frame, big-endian
> PCM_SIGNED unknown sample rate, 8 bit, mono, 1 bytes/frame,
> PCM_UNSIGNED unknown sample rate, 8 bit, mono, 1 bytes/frame,
> PCM_SIGNED unknown sample rate, 8 bit, stereo, 2 bytes/frame,
> PCM_UNSIGNED unknown sample rate, 8 bit, stereo, 2 bytes/frame,
> PCM_SIGNED unknown sample rate, 8 bit, 3 channels, 3 bytes/frame,
> PCM_UNSIGNED unknown sample rate, 8 bit, 3 channels, 3 bytes/frame,
> PCM_SIGNED unknown sample rate, 8 bit, 4 channels, 4 bytes/frame,
> PCM_UNSIGNED unknown sample rate, 8 bit, 4 channels, 4 bytes/frame,
> PCM_SIGNED unknown sample rate, 32 bit, mono, 4 bytes/frame, little-endian
> PCM_SIGNED unknown sample rate, 32 bit, mono, 4 bytes/frame, big-endian
> PCM_SIGNED unknown sample rate, 32 bit, stereo, 8 bytes/frame, little-endian
> PCM_SIGNED unknown sample rate, 32 bit, stereo, 8 bytes/frame, big-endian
> PCM_SIGNED unknown sample rate, 32 bit, 3 channels, 12 bytes/frame, little-endian
> PCM_SIGNED unknown sample rate, 32 bit, 3 channels, 12 bytes/frame, big-endian
> PCM_SIGNED unknown sample rate, 32 bit, 4 channels, 16 bytes/frame, little-endian
> PCM_SIGNED unknown sample rate, 32 bit, 4 channels, 16 bytes/frame, big-endian
> PCM_SIGNED unknown sample rate, 24 bit, mono, 4 bytes/frame, little-endian
> PCM_SIGNED unknown sample rate, 24 bit, mono, 4 bytes/frame, big-endian
> PCM_SIGNED unknown sample rate, 24 bit, stereo, 8 bytes/frame, little-endian
> PCM_SIGNED unknown sample rate, 24 bit, stereo, 8 bytes/frame, big-endian
> PCM_SIGNED unknown sample rate, 24 bit, 3 channels, 12 bytes/frame, little-endian
> PCM_SIGNED unknown sample rate, 24 bit, 3 channels, 12 bytes/frame, big-endian
> PCM_SIGNED unknown sample rate, 24 bit, 4 channels, 16 bytes/frame, little-endian
> PCM_SIGNED unknown sample rate, 24 bit, 4 channels, 16 bytes/frame, big-endian
> PCM_SIGNED unknown sample rate, 24 bit, mono, 3 bytes/frame, little-endian
> PCM_SIGNED unknown sample rate, 24 bit, mono, 3 bytes/frame, big-endian
> PCM_SIGNED unknown sample rate, 24 bit, stereo, 6 bytes/frame, little-endian
> PCM_SIGNED unknown sample rate, 24 bit, stereo, 6 bytes/frame, big-endian
> PCM_SIGNED unknown sample rate, 24 bit, 3 channels, 9 bytes/frame, little-endian
> PCM_SIGNED unknown sample rate, 24 bit, 3 channels, 9 bytes/frame, big-endian
> PCM_SIGNED unknown sample rate, 24 bit, 4 channels, 12 bytes/frame, little-endian
> PCM_SIGNED unknown sample rate, 24 bit, 4 channels, 12 bytes/frame, big-endian
> PCM_SIGNED unknown sample rate, 20 bit, mono, 3 bytes/frame, little-endian
> PCM_SIGNED unknown sample rate, 20 bit, mono, 3 bytes/frame, big-endian
> PCM_SIGNED unknown sample rate, 20 bit, stereo, 6 bytes/frame, little-endian
> PCM_SIGNED unknown sample rate, 20 bit, stereo, 6 bytes/frame, big-endian
> PCM_SIGNED unknown sample rate, 20 bit, 3 channels, 9 bytes/frame, little-endian
> PCM_SIGNED unknown sample rate, 20 bit, 3 channels, 9 bytes/frame, big-endian
> PCM_SIGNED unknown sample rate, 20 bit, 4 channels, 12 bytes/frame, little-endian
> PCM_SIGNED unknown sample rate, 20 bit, 4 channels, 12 bytes/frame, big-endian
如果我在这方面得到某种帮助,我将不胜感激。