Question

I am running a study where two participants will each wear a different microphone while discussing multiple topics. I need to be able to analyze each participant's audio input in Java — capturing two audio input streams independently. I cannot combine both input streams for analysis.

Does anyone know if I can do this in Java, and how?

I have come across this, which states "Commonly, only one input port can be open at a time, but an audio-input mixer that mixes audio from multiple ports is also possible."

Thanks

Edit 1: The capture and analysis has to be done in real-time.

Edit 2: I am using a Windows 7 64-bit operating system. My sound card has only one microphone port. I have two USB audio adapters that are similar to this. If I cannot accomplish this in Java, what is a good alternative solution? Using a USB library has been suggested. The analysis that I will perform on the audio data is to determine the utterance rate of each speaker (how much they are talking).

Conclusion: I was able to read from two TargetDataLines simultaneously by using threads in Java. Both of my USB audio adapters were visible to Java.

Was it helpful?

Solution

I haven't done this myself, so take the following as a suggestion more than an answer. (I'm more into music synthesis and audio effects for real time playback such as game sound.)

As you probably have already read in the tutorial, Java provides a class called AudioSystem which provides access to lines and ports that are available on a given computer. If the computer with which you wish to operate with has two mike lines, then there is every reason to believe that those two lines will both be made visible to Java. The input limitation depends more on the hardware (sound card being used and number of mike lines it offers) and drivers and OS than it does on Java. You may have to purchase a special sound card that allows simultaneous multiple inputs.

Also, I know there can exist limits at the OS level (some flavors of Linux in particular) that only allow one output line to operate at a time. This would limit what Java can see. But I haven't really explored this with my Windows OS yet.

For reading data from a line, a TargetDataLine class is normally used. Data is usually read from this line in buffer blocks (e.g., 1024 bytes at a time) via a while loop. I have had multiple TargetDataLines operating simultaneously in the past: where the data source were various Java software synth sources. Assuming each TDL is assigned to a different input line, each can be read from within this loop, and the respective data then passed on to the different analyzers. TargetDataLines are blocking lines--if a line doesn't have data ready (usually processing goes much faster than audio data can be presented)--then the program blocks until the data is present.

Java is capable of much real-time DSP. I don't know the specific form of analysis you wish to do, but there are probably libraries available by independent sources.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top