I have a java application that records audio from a mixer and saves it in a byte array or saves it to a file. I need to get the sound from two mixers at the same time, and save it to an audio file (I'm trying to use .wav). The fact is that I can get two byte arrays, but I donβt know how to combine them (by "merging" I do not mean concatenation). To be specific, this is an application that processes conversations via a USB modem, and I need to record them (streams are voices for each speaker, already printed for recording them separately).
Are there any tips on how to do this?
Here is my code:
import java.nio.file.Files; import java.nio.file.Paths; import java.nio.file.Path; public class FileMixer { Path path1 = Paths.get("/file1.wav"); Path path2 = Paths.get("/file2.wav"); byte[] byte1 = Files.readAllBytes(path1); byte[] byte2 = Files.readAllBytes(path2); byte[] out = new byte[byte1.length]; public FileMixer() { byte[] byte1 = Files.readAllBytes(path1); byte[] byte2 = Files.readAllBytes(path2); for (int i=0; i<byte1.Length; i++) out[i] = (byte1[i] + byte2[i]) >> 1; } }
Thanks in advance
source share