J
J
J. Snow2017-06-17 12:43:46
Java
J. Snow, 2017-06-17 12:43:46

Java: Is it possible to record sound from the output of a sound card (NOT a microphone)?

Hey!
I'm trying to record the sound that goes to the output of the speakers.
Is it possible?
I didn't find any restrictions. You need to get the desired TargetDataLine and write. But I am facing IllegalArgumentException .
The code is something like this:
(Pay no attention to the syntax, this is Kotlin)

audioFormat = AudioFormat(8000f, 8, 2, true, false)

mixerInfo = AudioSystem.getMixerInfo()
mixer = AudioSystem.getMixer(mixerInfo[0]) // перепробовал все миксеры

dataLineInfo = DataLine.Info(TargetDataLine::class.java, audioFormat)
dataLine = mixer.getLine(dataLineInfo) as TargetDataLine // IllegalArgumentException

dataLine.open()
dataLine.start()
AudioSystem.write(AudioInputStream(dataLine), AudioFileFormat.Type.WAVE, File("1.wav"))

Exception when calling getLine :
java.lang.IllegalArgumentException: Line unsupported: interface TargetDataLine supporting format PCM_SIGNED 8000.0 Hz, 8 bit, stereo, 2 bytes/frame, little-endian

I tried all kinds of formats and mixers.
Input mixers (i.e. microphones) work fine.
The output mixers don't work at all.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question