问题
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