How to record microphone sound using Java API?

The tutorial http://download.oracle.com/javase/tutorial/sound/capturing.html does not cover how to choose a microphone.

I list faucets 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()); } } 

i.e. by the presence of a microphone input. But next time, having a mixer, I can’t get a line to read.

If I use mixer.getTargetLineInfo() , I get an array from one Info , which when passed to mixer.getLine returns an object of type com.sun.media.sound.PortMixer$PortMixerPort , which is not duplicated.

If I use mixer.getTargetLines() , I get an empty array.

If I create my own DataLine.Info and pass it to the getLine mixer, I get an unsupported exception.

So what to do?

+6
source share
2 answers

Offer left field.

Provide visual rendering of each audio line in the component along the lines of AudioPlotPanel or a simpler RMS volume . It shouldn't take too long to figure out which sound line they are laying.;)

+2
source

I am trying to do the same. I have not found a good solution yet, but I can say that it does not work, because you are trying to get a DataLine from a portal mixer. If and when I find out, I will definitely inform you.

0
source

Source: https://habr.com/ru/post/889922/


All Articles