以下是將音頻數據從2 audio input streams
讀取到字節數組中的代碼。連接2個字節數組然後轉換爲音頻流
import javax.sound.sampled.*;
import java.io.*;
class tester {
public static void main(String args[]) throws IOException {
try {
Clip clip_1 = AudioSystem.getClip();
AudioInputStream ais_1 = AudioSystem.getAudioInputStream(new File("D:\\UnderTest\\wavtester_1.wav"));
clip_1.open(ais_1);
Clip clip_2 = AudioSystem.getClip();
AudioInputStream ais_2 = AudioSystem.getAudioInputStream(new File("D:\\UnderTest\\wavtester_2.wav"));
clip_2.open(ais_2);
byte arr_1[] = new byte[ais_1.available()]; // not the right way ?
byte arr_2[] = new byte[ais_2.available()];
ais_1.read(arr_1);
ais_2.read(arr_2);
} catch(Exception exc) {
System.out.println(exc);
}
}
}
從上面的代碼我有一個字節爲array1,array2
ais_1,ais_2
。有什麼辦法連接這兩個字節數組(arr_1,arr_2
),然後將它們轉換回音頻流?我想連接2個音頻文件。
我做這樣的評論,因爲它不是一個完整的答案:我不認爲'.available()'必然會返回流中可用的總字節數。應該使用'ais_1.frameLength * ais_1.frameSize'來代替。 – MusiGenesis