Java语音聊天-所有终端都有自己的语音回响
我已经用java编写了一个p2p语音聊天应用程序,使用sound.sampled api,我可以与其他人进行对话,但我实际上听到了我的声音回响,我只是将我的语音包发送到其他连接,而不是我自己。另一位用户说,他也能听到自己的声音回响 这是我正在使用的音频捕获和回放的一个片段,它的回声也很差Java语音聊天-所有终端都有自己的语音回响,java,audio,voice,Java,Audio,Voice,我已经用java编写了一个p2p语音聊天应用程序,使用sound.sampled api,我可以与其他人进行对话,但我实际上听到了我的声音回响,我只是将我的语音包发送到其他连接,而不是我自己。另一位用户说,他也能听到自己的声音回响 这是我正在使用的音频捕获和回放的一个片段,它的回声也很差 package soundtest; import java.io.*; import javax.swing.*; import javax.sound.sampled.*; public class S
package soundtest;
import java.io.*;
import javax.swing.*;
import javax.sound.sampled.*;
public class Soundtest extends JFrame{
public static void main(String[] args) {
AudioFormat format = new AudioFormat(44100, 16, 2, true, true);
DataLine.Info targetInfo = new DataLine.Info(TargetDataLine.class, format); //Read from
DataLine.Info sourceInfo = new DataLine.Info(SourceDataLine.class, format); //Write to
try{
TargetDataLine microphone = (TargetDataLine) AudioSystem.getLine(targetInfo);
microphone.open(format);
microphone.start();
SourceDataLine speakers = (SourceDataLine) AudioSystem.getLine(sourceInfo);
speakers.open(format);
speakers.start();
int numBytesRead;
byte[] targetData = new byte[microphone.getBufferSize() / 5];
for(;;){
numBytesRead = microphone.read(targetData, 0, targetData.length);
if (numBytesRead == -1) break;
speakers.write(targetData, 0, numBytesRead);
}
}
catch(Exception e){
System.err.println(e);
}
}
}
有人知道回声的原因吗?您是否在监控系统中的麦克风?嗯,似乎有一个常见的回声消除问题。