I'm trying to send voice from android to PC over sockets. My code is working but at PC end what I hear is lot of noise, I am even unable to listen to any voice.
Here is the android code that i'm using:
byte buffer[]=new byte[1024];
int buffersize = AudioRecord.getMinBufferSize(SAMPLE_RATE, AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT);
mic=new AudioRecord(MediaRecorder.AudioSource.MIC, SAMPLE_RATE, AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT, buffersize);
mic.startRecording();
while(running){
count=mic.read(buffer, 0, buffer.length);
if(count>0){
OutputStream.write(buffer, 0, count);
}
}
Here is PC Code:
float sampleRate=44100;
int sampleSize=16;
int channel=1;
boolean sign=true;
boolean bigendian=true;
AudioFormat format=new AudioFormat(sampleRate, sampleSize, channel, sign, bigendian);
SourceDataLine voiceLine;
DataLine.Info LineInfo=new DataLine.Info(SourceDataLine.class, format);
if(AudioSystem.isLineSupported(LineInfo)){
System.out.println("Line Supported...");
}else{
System.out.println("not supported Line...");
}
voiceLine = (SourceDataLine) AudioSystem.getLine(LineInfo);
voiceLine.open(format);
voiceLine.start();
byte buffer[] = new byte[1024];
inputStream=new BufferedInputStream(connection.getInputStream());
while(true){
count=inputStream.read(buffer,0,buffer.length);
InputStream in;
in=new ByteArrayInputStream(buffer);
AudioInputStream ais=new AudioInputStream(in, format, buffer.length /format.getFrameSize());
ais.read(audio, 0, count);
voiceLine.write(audio, 0, count);
}
What I test so far:
What I have tried so far:
But got nothing.
I ended up solving this myself.
It turned out that I had to change it to bigendian=false;
, and now it works.