After extensive research on the subject, I reached a brick wall.
All I want to do is add a collection of .wav files to the byte array one by one and output them all to one complete newly created WAV file. I extract all .wav data into an array of bytes, skipping the .wav header and heading straight for the data, and then when it comes to writing it in a newly created WAV file, I get an error, for example: Error1: javax.sound.sampled.UnsupportedAudioFileException : Failed to get input audio stream from input stream Error2: Failed to get input audio signal stream from input stream
The code:
try { String path = "*********"; String path2 = path + "newFile.wav"; File filePath = new File(path); File NewfilePath = new File(path2); String [] folderContent = filePath.list(); int FileSize = 0; for(int i = 0; i < folderContent.length; i++) { RandomAccessFile raf = new RandomAccessFile(path + folderContent[i], "r"); FileSize = FileSize + (int)raf.length(); } byte[] FileBytes = new byte[FileSize]; for(int i = 0; i < folderContent.length; i++) { RandomAccessFile raf = new RandomAccessFile(path + folderContent[i], "r"); raf.skipBytes(44); raf.read(FileBytes); raf.close(); } boolean success = NewfilePath.createNewFile(); InputStream byteArray = new ByteArrayInputStream(FileBytes); AudioInputStream ais = AudioSystem.getAudioInputStream(byteArray); AudioSystem.write(ais, Type.WAVE, NewfilePath); }
source share