Java Voice Server Not Working

两盒软妹~` 提交于 2019-12-08 03:49:33

问题


I am trying to make a voice server and the server is throwing this error "javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 8000.0 Hz, 8 bit, mono, 1 bytes/frame, not supported.". Here is my code, Thank you in advance

    public class VoiceUser extends Thread {                                     // CHAT USER
    private ObjectOutputStream clientOutput;

    public VoiceUser(Socket sv) {
        try {
            System.out.println("VSTART");
            clientOutput = new ObjectOutputStream(sv.getOutputStream());
            outputArray.add(clientOutput);
        } catch (IOException e) {
            System.out.println("Can't create stable connection between server and client");
        }
    }
    public void run() {
        try {
            AudioFormat af = new AudioFormat(8000.0f,8,1,true,false);
            DataLine.Info info = new DataLine.Info(TargetDataLine.class, af);
            TargetDataLine microphone = (TargetDataLine)AudioSystem.getLine(info);
            microphone.open(af);
            microphone.start();
            int bytesRead = 0;
            byte[] soundData = new byte[1];
            while(bytesRead != -1)
            {
                bytesRead = microphone.read(soundData, 0, soundData.length);
                System.out.println(soundData.length);
                if(bytesRead >= 0)
                {
                    for(ObjectOutputStream o : outputArray) {
                        o.write(soundData, 0, bytesRead);
                    }
                }
            }
        } catch (IOException | LineUnavailableException e) {
            e.printStackTrace();
        }
    }
}

来源:https://stackoverflow.com/questions/36902042/java-voice-server-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!