Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Combining 2+ WAV Files into a single WAV file

804900Jan 7 2011 — edited Jan 7 2011
Hello there,

I am trying to combine at least 2 WAV files (my example uses 3) into a single file. I have tried several examples (http://www.jsresources.org/examples/AudioConcat.html and http://stackoverflow.com/questions/653861/join-two-wav-files-from-java) but both have the same problem: the output file is an exact copy of the last file to have been joined.

Here is the code for the simpler of the 2 examples which I have altered to meet my needs.
        File outputFile = new File("concat.wav");
        for (int i = 0; i < files.length - 1; i++) {
            try {
                AudioInputStream clip1 = AudioSystem.getAudioInputStream(files);
AudioInputStream clip2 = AudioSystem.getAudioInputStream(files[i + 1]);

AudioInputStream appendedFiles =
new AudioInputStream(
new SequenceInputStream(clip1, clip2),
clip1.getFormat(),
clip1.getFrameLength() + clip2.getFrameLength());

AudioSystem.write(appendedFiles,
AudioFileFormat.Type.WAVE,
outputFile);

files[i + 1] = outputFile;//first file read in next loop, will contain joined file so far

} catch (Exception e) {
e.printStackTrace();
}
}
return outputFile;


I am unsure as where the problem lies, so would be grateful for anyone to point out the (no doubt obvious) mistake i've made :p
This post has been answered by captfoss on Jan 7 2011
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 4 2011
Added on Jan 7 2011
1 comment
2,091 views