6

I have a java application that is taking in sound from multiple sources, and one of the abilities of the user is to record what is happening in the application to an AVI file, and I would like to include the sound in that video capture. How do I record the sound that the user would hear (ex. a result of all of the sound inputs mixed together)? I can figure out how to get the actual sound stream in to the video, but I am not sure where to get that sound source from.

Andrew Thompson
  • 163,965
  • 36
  • 203
  • 405
Matt
  • 254
  • 1
  • 2
  • 12
  • just FYI: I haven't looked into this closely, but I've worked with javasound a fair bit, and I'm not sure this is possible. You may have to do your own mixing. – Bjorn Roche Jun 22 '12 at 16:04
  • This closely related question just asked may be relevant to you http://stackoverflow.com/questions/11168465/is-it-possible-to-capture-the-playing-audio-with-java/11170689 – Bjorn Roche Jun 23 '12 at 15:28
  • Do you still have this problem?or solved? – joey rohan Mar 11 '13 at 11:34
  • how did you solved it ? – coding_idiot Sep 11 '13 at 13:02
  • Sorry, I have not checked back in a long time. I never did end up solving this, it ended up being overcome by events. We decided not to record sound at all, so I no longer had to look in to it. – Matt Dec 17 '13 at 15:22

1 Answers1

4

Have you read the java tutorial on this? There's a lot of information that pertains to your question in Accessing Audio System Resources.

It details some recommended classes to use and provides examples of their implementation.

Andrew Thompson
  • 163,965
  • 36
  • 203
  • 405
Scotch
  • 3,052
  • 11
  • 31
  • 48
  • 2
    I have read through that, the issue I have with it is that you do not know which mixer goes to the speakers necessarily. On my Linux machine there are three mixers, two which appear to be outputs (one to analog, one to digital. On my windows machine, there appears to be many more mixers, two of which I can assume are outputs to speakers. I am not sure how to 'generically' choose which mixer to grab to record from. – Matt Jun 22 '12 at 14:28
  • Unless I'm misunderstanding, isn't that covered in this part : Getting a Line Directly from the AudioSystem Let's assume you haven't obtained a mixer, and your program is a simple one that really only needs a certain kind of line; the details of the mixer don't matter to you. You can use the AudioSystem method: static Line getLine(Line.Info info) (More details are provided below, on the link I posted) – Scotch Jun 22 '12 at 14:35
  • Hmm, I misread that portion. That might do what I am looking for. I'll try it out. – Matt Jun 22 '12 at 14:42
  • Good luck! Remember, if possible, you probably want this to be as generic as possible. Just because you get it working for you doesn't mean it will work for others. – Scotch Jun 22 '12 at 14:46
  • 1
    I have not had luck with it yet. I am playing an MP3 file through a SourceDataLine of a format, which I can hear through the speakers. I capture audio on a TargetDataLine of the same format. When I try to play back that audio through a SourceDataLine of the same format, I do not hear anything. I am assuming that it recorded silence (aka, reading the wrong line), but it is hard to tell. – Matt Jun 22 '12 at 19:41
  • Also see the `MediaTypes` code on [this answer](http://stackoverflow.com/a/7616206/418556) for more information on lines. – Andrew Thompson Jun 23 '12 at 09:47
  • 2
    This answer is painfully vague. Could you include an excerpt from the linked tutorial that covers how to record audio from the system's audio output? I see nothing in there that pertains to this question--only general information about the sound API. – FThompson Nov 29 '14 at 07:33