Android: Streaming audio over TCP Sockets

All your problems with Audio, Video and Images.

Android: Streaming audio over TCP Sockets

Postby kchaits123 » Sat May 01, 2010 4:32 pm

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. This works great with a 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:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. int bufferSize = AudioRecord.getMinBufferSize(11025, , AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_16BIT);
  3.  
  4.  
  5.  
  6. AudioRecord recordInstance = new AudioRecord(MediaRecorder.AudioSource.MIC, 11025, AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_16BIT, bufferSize);
  7.  
  8.  
  9.  
  10. byte[] tempBuffer = new byte[bufferSize];
  11.  
  12.  
  13.  
  14. recordInstance.startRecording();
  15.  
  16.  
  17.  
  18. while (/*isRecording*/) {
  19.  
  20.       bufferRead = recordInstance.read(tempBuffer, 0, bufferSize);
  21.  
  22.       dataOutputStreamInstance.write(tempBuffer);
  23.  
  24. }
Parsed in 0.032 seconds, using GeSHi 1.0.8.4


The DataOutputStream above is obtained as:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. BufferedOutputStream buff = new BufferedOutputStream(out1); //out1 is the socket's outputStream
  2.  
  3. DataOutputStream dataOutputStreamInstance = new DataOutputStream (buff);
Parsed in 0.030 seconds, using GeSHi 1.0.8.4


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

Thanks,
kchaits123
Freshman
Freshman
 
Posts: 2
Joined: Sat May 01, 2010 9:03 am

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: Google Feedfetcher and 16 guests