how can merge two audio files to a single file in android platform. that is if i have two audio files namely A and B.Please give me the code to create a new audio file C that is appended by B after A. Is there any need to convert the audio files to byte/short array ??...
i did like this but it plays 1st file only.
File firstFile=new File("/mnt/sdcard/Android/data/Dictation/Audio/Dict136.3gp");
File secondFile=new File("/mnt/sdcard/Android/data/Dictation/Audio/Dict139.3gp");
System.out.println("1 file:::::"+firstFile+"\n 2nd file::"+secondFile);
FileInputStream fistream1;
try {
fistream1 = new FileInputStream(firstFile);
FileInputStream fistream2 = new FileInputStream(secondFile);//second source file
SequenceInputStream sistream = new SequenceInputStream(fistream1, fistream2);
FileOutputStream fostream = new FileOutputStream("/mnt/sdcard/Android/data/Dictation/Audio/merged.3gp");//destinationfile
int temp;
while( ( temp = sistream.read() ) != -1)
{
System.out.print( (char) temp ); // to print at DOS prompt
fostream.write(temp); // to write to file
}
filePath="/mnt/sdcard/Android/data/Dictation/Audio/merged.3gp";
playAudio(filePath);
fostream.close();
fistream1.close();
fistream2.close();
thanks in advance.
To combine audio files that are in an 3gp or mp4 container you should be able to use https://github.com/sannies/mp4parser Check out the samples: https://github.com/sannies/mp4parser/blob/master/examples/src/main/java/com/googlecode/mp4parser/AppendExample.java
get the mp4parser jar (via maventral) and do this:
You can try using
File Input/output Stream
for this. To read any file in byte arrays useHere the
buffer
contain you file's byte array. In this way you can get the byte array of both the file. now in 2nd step when you have taken the byte array of bot file you need to copy both of byte array into one single array and then you can write this (3rd new array) to a new file using thisWhere
data
is the new 3rd array you will get after merging both arraysEDIT: See this how to combine two arrays
Hope this will help you.