0
我有兩個.3gp(或.wav)音頻文件,我已經從用戶的麥克風中保存。我怎樣才能將這兩個音頻文件在代碼中連接成一個文件?謝謝。Android將兩個音頻文件合併爲一個
我有兩個.3gp(或.wav)音頻文件,我已經從用戶的麥克風中保存。我怎樣才能將這兩個音頻文件在代碼中連接成一個文件?謝謝。Android將兩個音頻文件合併爲一個
組合兩個wav文件:
import java.io.File;
import java.io.IOException;
import java.io.SequenceInputStream;
import javax.sound.sampled.AudioFileFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
public class WavAppender {
public static void main(String[] args) {
String wavFile1 = "D:\\wav1.wav";
String wavFile2 = "D:\\wav2.wav";
try {
AudioInputStream clip1 = AudioSystem.getAudioInputStream(new File(wavFile1));
AudioInputStream clip2 = AudioSystem.getAudioInputStream(new File(wavFile2));
AudioInputStream appendedFiles =
new AudioInputStream(
new SequenceInputStream(clip1, clip2),
clip1.getFormat(),
clip1.getFrameLength() + clip2.getFrameLength());
AudioSystem.write(appendedFiles,
AudioFileFormat.Type.WAVE,
new File("D:\\wavAppended.wav"));
} catch (Exception e) {
e.printStackTrace();
}
}
}
最好的,謝謝! – JDS 2013-05-07 01:57:57
AudioSystem不適用於android – wutzebaer 2014-03-19 21:30:21
是的AudioSystem在Android中不可用。有沒有其他解決方案呢? – Vikram 2015-05-06 06:07:11