Hi,

For my app, I need to record audio from MIC on an Android phone, and
send it over TCP to the other android phone, where it needs to be
played.

I am using AudioRecord and AudioTrack class. These classes works great
with a local file - write audio to the file using DataOutputStream,
and read from it using DataInputStream.

However, if I obtain the same stream from a socket instead of a File,
and try writing to it, I get an Exception.

I am at a loss to understand what could possibly be going wrong. Any
help would be greatly appreciated.

The problem is same even if I try with larger buffer sizes (65535
bytes, 160000 bytes).

This is the code:

Recorder:

int bufferSize = AudioRecord.getMinBufferSize(11025, ,
AudioFormat.CHANNEL_CONFIGURATION_MONO,
AudioFormat.ENCODING_PCM_16BIT);

AudioRecord recordInstance = new
AudioRecord(MediaRecorder.AudioSource.MIC, 11025,
AudioFormat.CHANNEL_CONFIGURATION_MONO,
AudioFormat.ENCODING_PCM_16BIT, bufferSize);

byte[] tempBuffer = new byte[bufferSize];

recordInstance.startRecording();

while (/*isRecording*/) {
      bufferRead = recordInstance.read(tempBuffer, 0, bufferSize);
      dataOutputStreamInstance.write(tempBuffer);
}

The DataOutputStream above is obtained as:

BufferedOutputStream buff = new BufferedOutputStream(out1); //out1 is
the socket's outputStream
DataOutputStream dataOutputStreamInstance = new DataOutputStream
(buff);

Could you please have a look, and let me know what is it that I could
be doing wrong here?

Thanks,

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to