i getting audio from android client with DatagramSocket in java server now i want save audio that has been receive to wave file.
java server code is:
private static void receiveAudioFromAndroidClient() {
try {
DatagramSocket serverSocket = new DatagramSocket(50005);
serverSocket1 = new ServerSocket(8072);
byte[] receiveData = new byte[4096];
// ( 1280 for 16 000Hz and 3584 for 44 100Hz (use AudioRecord.getMinBufferSize(sampleRate, channelConfig, audioFormat) to get the correct size)
format = new AudioFormat(sampleRate, 16, 1, true, false);
while (status == true) {
DatagramPacket receivePacket = new DatagramPacket(receiveData,
receiveData.length);
serverSocket.receive(receivePacket);
ByteArrayInputStream baiss = new ByteArrayInputStream(receivePacket.getData());
ais = new AudioInputStream(baiss, format, receivePacket.getLength());
// A thread solve the problem of chunky audio
new Thread(new Runnable() {
@Override
public void run() {
toSpeaker(receivePacket.getData());
}
}).start();
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
please help me
Use AudioSystem
to write audio data to file, like this:
AudioInputStream ais = new AudioInputStream(...);
AudioSystem.write(ais, AudioFileFormat.Type.WAVE, new File("audio.wav"));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.