0

I need to write some java code that will listen to the audio that other processes produce. I've looked around and it seems I should use PulseAudio. If I am not mistaken, I need to define a sink that will be my java process, and tell the source (alsa?) to go there. I failed to find any details on how to do this.

And - what should I use on the java side? This gives me 0 mixers:

Info[] mis = AudioSystem.getMixerInfo();
for (Info mi : mis)
{
    System.out.println(mi.getName());
    System.out.println(mi.getVendor());
    System.out.println(mi.getDescription());
    System.out.println("---------------");
}
reformy
  • 989
  • 2
  • 10
  • 19

1 Answers1

0

Finally I've managed to get this working. I am sure this can be done a bit shorter so fill free to correct me:

  • Create a loopback sink: sudo modprobe snd-aloop
  • Check the list of audio sinks: aplay -l. If you have a real sound card, the loopback will be card 1.
  • Create (or edit) the .asoundrc file: cat > ~/.asoundrc.

Put this there:

pcm.!default {
 type hw
 card 1
 device 0
}

This will direct all processes starting from hereon to use the loopback for audio output.

  • Install PulseAudio Volume Control: sudo apt-get install pavucontrol
  • Open the Volume Control application and make sure the real card is not marked as fallback, and that the loopback is (under 'output').
  • This will send the audio using the System.in stream to a java process: arecord -D hw:1,1 -f cd | java -jar some-java-code.jar
reformy
  • 989
  • 2
  • 10
  • 19