[英]How to capture sound from microphone with java sound API?
The tutorial http://download.oracle.com/javase/tutorial/sound/capturing.html does not cover how to select microphone. The tutorial http://download.oracle.com/javase/tutorial/sound/capturing.html does not cover how to select microphone.
I am enumerating mixers with the following code我正在使用以下代码枚举混音器
System.out.println("Searching for microphones");
for(Mixer.Info mixerinfo : AudioSystem.getMixerInfo()) {
mixer = AudioSystem.getMixer(mixerinfo);
//System.out.println(mixerinfo.toString());
if( mixer.isLineSupported(Port.Info.MICROPHONE) ) {
mixers.add(mixer);
System.out.println(Integer.toString(mixers.size()) + ": " + mixerinfo.toString());
}
}
ie by presense of microphone input.即通过麦克风输入。 But next, having a mixer, I can't get line to read.但是接下来,有一个混音器,我无法阅读。
If I use mixer.getTargetLineInfo()
, I receive an array of one Info
, which when passing to mixer.getLine
returns an object of type com.sun.media.sound.PortMixer$PortMixerPort
, which is not ducumented.如果我使用mixer.getTargetLineInfo()
,我会收到一个Info
的数组,当传递给mixer.getLine
时会返回一个 object 类型的com.sun.media.sound.PortMixer$PortMixerPort
,这是没有记录的。
If I use mixer.getTargetLines()
I get an empty array.如果我使用mixer.getTargetLines()
我得到一个空数组。
If I create my own DataLine.Info
and pass it to the mixer's getLine
, I get unsupported exception.如果我创建自己的DataLine.Info
并将其传递给混音器的getLine
,我会得到不受支持的异常。
So, what to do?那么该怎么办?
Provide a visual rendering of each sound line, in a component along the lines of the AudioPlotPanel or a simpler RMS volume .在沿AudioPlotPanel或更简单的RMS 音量线的组件中提供每条声音线的可视化渲染。 It should not take the user too long to figure which sound line they are yodeling through.用户不应该花费太长时间来确定他们正在通过哪个声线。 ;) ;)
I'm trying to do the same thing.我正在尝试做同样的事情。 I haven't quite found a good solution yet but I can tell you that's not working out because you're trying to get a DataLine from a Port mixer.我还没有找到一个好的解决方案,但我可以告诉你这行不通,因为你正试图从端口混合器中获取数据线。 If and when I figure it out I'll be sure to let you know.如果我弄清楚了,我一定会告诉你的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.