我正在做一个麦克风对讲机程序,使用声音api进行功能开发。
播放对方的声音:
AudioFormat audioFormat = new AudioFormat(16000.0F, 16, 1, true, false);
SourceDataLine sourceDataLine;
DataLine.Info dataLineInfo = new DataLine.Info(SourceDataLine.class, audioFormat, AudioSystem.NOT_SPECIFIED);
sourceDataLine = (SourceDataLine) AudioSystem.getLine(dataLineInfo);
sourceDataLine.open(audioFormat);
sourceDataLine.start();
while(true) sourceDataLine.write(buffer, 0, buffer.length); //write audio data
收集麦克风的语音数据并将其发送给另一方:
AudioFormat audioFormat = new AudioFormat(16000.0F, 16, 1, true, false);
DataLine.Info info = new DataLine.Info(TargetDataLine.class, audioFormat);
TargetDataLine targetDataLine = (TargetDataLine)AudioSystem.getLine(info);
targetDataLine.open(audioFormat);
targetDataLine.start();
System.out.println("You can speak now!");
int nByte = 0;
final int bufSize = 3200;
byte[] buffer = new byte[bufSize];
while ((nByte = targetDataLine.read(buffer, 0, bufSize)) > 0) {
//send.....
}
问题:在播放另一方声音的同时,采集麦克风将另一方的声音发送给另一方。我该怎么办?谢谢。
暂无答案!
目前还没有任何答案,快来回答吧!