问题描述
如何合并两个音频文件到android平台的单个文件。也就是说,如果我有两个音频文件,即A和B.Please给我的code创建由B A.后追加一个新的音频文件C是否有任何需要的音频文件转换为字节/短阵?? ...
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();
在此先感谢。
推荐答案
要结合起来,对一个3GP或MP4容器的音频文件,你应该能够使用的退房样本:<一href="https://github.com/sannies/mp4parser/blob/master/examples/src/main/java/com/google$c$c/mp4parser/AppendExample.java" rel="nofollow">https://github.com/sannies/mp4parser/blob/master/examples/src/main/java/com/google$c$c/mp4parser/AppendExample.java
To combine audio files that are in an 3gp or mp4 container you should be able to use https://github.com/sannies/mp4parserCheck out the samples:https://github.com/sannies/mp4parser/blob/master/examples/src/main/java/com/googlecode/mp4parser/AppendExample.java
获得mp4parser罐(通过maventral),并做到这一点:
get the mp4parser jar (via maventral) and do this:
File firstFile=new File("/mnt/sdcard/Android/data/Dictation/Audio/Dict136.3gp");
File secondFile=new File("/mnt/sdcard/Android/data/Dictation/Audio/Dict139.3gp");
Movie movieA = MovieCreator.build(firstFile);
Movie movieB = MovieCreator.build(secondFile);
final Movie finalMovie = new Movie();
List<Track> audioTracks = new ArrayList<>();
for (Movie movie : new Movie[] { movieA, movieB}) {
for (Track track : movie.getTracks()) {
if (track.getHandler().equals("soun")) {
audioTracks.add(track);
}
}
}
finalMovie.addTrack(new AppendTrack(audioTracks.toArray(new Track[audioTracks.size()])));
final Container container = new DefaultMp4Builder().build(finalMovie);
File mergedFile = new File("/mnt/sdcard/Android/data/Dictation/Audio/merged.3gp");
final FileOutputStream fos = new FileOutputStream(mergedFile);
FileChannel fc = new RandomAccessFile(mergedFile, "rw").getChannel();
container.writeContainer(fc);
fc.close();
这篇关于合并2个音频文件,依次机器人?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!