Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/323.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java语音聊天-所有终端都有自己的语音回响_Java_Audio_Voice - Fatal编程技术网

Java语音聊天-所有终端都有自己的语音回响

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

我已经用java编写了一个p2p语音聊天应用程序,使用sound.sampled api,我可以与其他人进行对话,但我实际上听到了我的声音回响,我只是将我的语音包发送到其他连接,而不是我自己。另一位用户说,他也能听到自己的声音回响

这是我正在使用的音频捕获和回放的一个片段,它的回声也很差

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);
    }
}
}

有人知道回声的原因吗?

您是否在监控系统中的麦克风?嗯,似乎有一个常见的回声消除问题。