I used the code from Join two WAV files from Java. I tested it, however it only worked without a loop. I now did a loop to append multiple audio files, like this:
AudioInputStream clip1 = null, clip2 = null;
for (int i = 1; i < fileAudio.size(); i++){
try {
if (i == 1) {
clip1 = AudioSystem.getAudioInputStream(new File("audio/" + fileAudio.get(0)));
}else{
clip1 = AudioSystem.getAudioInputStream(new File("merged.wav"));
}
clip2 = AudioSystem.getAudioInputStream(new File("audio/" + fileAudio.get(i)));
AudioInputStream appendedFiles =
new AudioInputStream(
new SequenceInputStream(clip1, clip2),
clip1.getFormat(),
clip1.getFrameLength() + clip2.getFrameLength());
AudioSystem.write(appendedFiles,
AudioFileFormat.Type.WAVE,
new File("merged.wav"));
System.out.println("Appending audio:" + clip1.getFrameLength());
clip1.close();
clip2.close();
appendedFiles.close();
} catch (Exception e) {
e.printStackTrace();
}
}
The result given is the correct length of audio files combined, but the sound is only from the last audio file. Meaning it didn't truly append the audio of the file(s).