不支持 Java 声音格式
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11915469/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Java Sound format not supported
提问by xorinzor
When using the following code: http://pastebin.com/5iVnttiP
使用以下代码时:http: //pastebin.com/5iVnttiP
I receive this error:
我收到此错误:
javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 16000.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
at com.sun.media.sound.DirectAudioDevice$DirectDL.implOpen(Unknown Source)
at com.sun.media.sound.AbstractDataLine.open(Unknown Source)
at com.sun.media.sound.AbstractDataLine.open(Unknown Source)
at com.AIComputer.model.Recorder.<init>(Recorder.java:124)
at com.AIComputer.AIComputer.main(AIComputer.java:7)
Now I did some research and found out that not all sound cards support every format, however when running this demo: http://java.sun.com/products/java-media/sound/samples/JavaSoundDemo/I managed to produce a recording using the exact same parameters (linear, 16000, 16, signed, little endian, stereo).
现在我做了一些研究,发现并不是所有的声卡都支持每种格式,但是在运行这个演示时:http: //java.sun.com/products/java-media/sound/samples/JavaSoundDemo/我设法产生了一个使用完全相同的参数(线性、16000、16、有符号、小端、立体声)进行录音。
I have no idea what I'm doing wrong here (also since I'm still a beginner at Java coding).
我不知道我在这里做错了什么(因为我仍然是 Java 编码的初学者)。
Any help will be greatly appreciated!
任何帮助将不胜感激!
回答by mico
Can you say from which line on YOUR code this exception is thrown?
你能说从你的代码的哪一行抛出这个异常吗?
The docsof LineUnavailableException says
LineUnavailableException的文档说
This situation arises most commonly when a requested line is already in use by another application.
当请求的线路已被另一个应用程序使用时,这种情况最常见。
You're opening two lines in your code. When you try to open the second one, the existence of the first one blocks it.
您在代码中打开了两行。当您尝试打开第二个时,第一个的存在阻止了它。