gpt4 book ai didi

javax.sound.sampled.LineUnavailableException : The system does not support the specified format

转载 作者:行者123 更新时间:2023-12-02 10:40:09 38 4
gpt4 key购买 nike

我正在探索录音 API。这在我的本地计算机上运行良好,但是当我在 Heroku 上部署相同的内容时,以下行抛出异常:

 if (!AudioSystem.isLineSupported(info)) {
throw new LineUnavailableException(
"The system does not support the specified format.");
}

文件格式为.wav。是 Heroku 上的声卡不可用还是我错过了其他东西?

这是我尝试在 Heroku 上执行的代码片段:

    format = getAudioFormat();
DataLine.Info info = new DataLine.Info(TargetDataLine.class, format);

// checks if system supports the data line
if (!AudioSystem.isLineSupported(info)) {
throw new LineUnavailableException(
"The system does not support the specified format.");
}

audioLine = AudioSystem.getTargetDataLine(format);

audioLine.open(format);
audioLine.start();

byte[] buffer = new byte[BUFFER_SIZE];
int bytesRead = 0;

recordBytes = new ByteArrayOutputStream();
isRunning = true;

while (isRunning) {
bytesRead = audioLine.read(buffer, 0, buffer.length);
recordBytes.write(buffer, 0, bytesRead);
}

谢谢

最佳答案

据我所知 Heroku 不支持声音。为了确定:

Mixer.Info[] mixerInfos = AudioSystem.getMixerInfo();
for (Mixer.Info[] info : mixerInfos) {
System.out.println("Supported: " + info);
}
if (mixerInfos.length == 0) {
System.out.println("Audio mixers are not supported.");
}

来自 getMixerInfo() 的 Javadocs:

Obtains an array of mixer info objects that represents the set of audio mixers that are currently installed on the system.

关于javax.sound.sampled.LineUnavailableException : The system does not support the specified format,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52977467/

38 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com