1

我正在尝试制作语音服务器,但服务器抛出此错误“javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 8000.0 Hz, 8 bit, mono, 1 bytes/frame, not supported.” . 这是我的代码,提前谢谢你

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

0 回答 0