My goal
I want to do the following in Java: record some sound made by Java itself, and then save it as a wav file.
I've searched for a lot of these kind of programs online, and I've found some good ones, but I get the same problem again and again (the current version can be found here). The problem is always something like this:
In the public class
, the function start
begins with
AudioFormat format = getAudioFormat();
DataLine.Info info = new DataLine.Info(TargetDataLine.class, format);
if (!AudioSystem.isLineSupported(info)) {
System.out.println("Line not supported");
System.exit(0);
}
, where getAudioFormat()
returns AudioFormat(16000,8,2,true,true)
. If I run the file, it prints Line not supported
, but why?
What I've tried:
- I've searched for loads of different formats online, and tried each of them.
- I've taken an existing wav file which Java can play, taken the format of that one, and used it as the format for the file I try to create.
Some more information:
System.out.println(AudioSystem.getTargetLineInfo(info));
System.out.println(AudioSystem.getAudioFileTypes());
System.out.println(AudioSystem.getMixerInfo());
System.out.println(AudioSystem.getSourceDataLine(format));
where format
is the format of the existing wav file, and info
is defined as in the first code snippet, prints:
[Ljavax.sound.sampled.Line$Info;@4eec7777
[Ljavax.sound.sampled.AudioFileFormat$Type;@41629346
[Ljavax.sound.sampled.Mixer$Info;@6d311334
com.sun.media.sound.DirectAudioDevice$DirectSDL@448139f0
I use Windows 7, 64 bits.
I'd like to add that if there's a better, entirely different way to achieve my goal, that's fine too.
format = info.getFormats()[0]
doesn't change the value of format. – Pim May 17 '15 at 14:57