Reputation:
Using Java, I assume Java Sound API is it possible to record the system audio in real time? By this I mean everything from system error notifications to iTunes and chrome.
Upvotes: 3
Views: 3189
Reputation: 4390
You need to connect your application to the main sound driver (the one giving output on your system). Usually this driver can change and its a good idea to provide code to be able to switch drivers.
After you've done that you will need to take buffers of sound data as input and save them.
A good starting place is to read over Java Sound API Tutorials by Oracle.
Generally, you will need to start by grabbing the correct audio device:
Getting a Mixer (Taken from Accessing Audio System Resources)
Usually, one of the first things a program that uses the Java Sound API needs to do is to obtain a mixer, or at least one line of a mixer, so that you can get sound into or out of the computer. Your program might need a specific kind of mixer, or you might want to display a list of all the available mixers so that the user can select one. In either case, you need to learn what kinds of mixers are installed. AudioSystem provides the following method:
static Mixer.Info[] getMixerInfo()
Each
Mixer.Info
object returned by this method identifies one type of mixer that is installed. (Usually a system has at most one mixer of a given type. If there happens to be more than one of a given type, the returned array still only has oneMixer.Info
for that type.) An application program can iterate over theMixer.Info
objects to find an appropriate one, according to its needs. TheMixer.Info
includes the following strings to identify the kind of mixer:
Name
Version
Vendor
Description
I suggest making the entire list of devices accessible so you can choose the correct one at run-time. You cannot easily know (if at all) which device is correct at compile time, especially if you deploy the application.
Afterwards you will need to create a TargetDataLine
to receive data from the mixer.
Now, to record you must save this data. This involves taking the data and writing buffer-by-buffer to a file. How you do this will of course depend on the file formats you wish to use.
Upvotes: 2