In Java, how do I record the sound output that is going to the speakers? [duplicate]
Asked Answered
A

1

7

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.

Acronym answered 22/6, 2012 at 13:37 Comment(5)
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.Doctrine
This closely related question just asked may be relevant to you #11168965Doctrine
Do you still have this problem?or solved?Jenisejenkel
how did you solved it ?Formenti
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.Acronym
C
2

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.

Custom answered 22/6, 2012 at 13:43 Comment(7)
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.Acronym
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)Custom
Hmm, I misread that portion. That might do what I am looking for. I'll try it out.Acronym
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.Custom
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.Acronym
Also see the MediaTypes code on this answer for more information on lines.Lovejoy
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.Contemporize

© 2022 - 2024 — McMap. All rights reserved.