Android : manually streaming audio effeciently using AudioTrack and Socket

Home - Android : manually streaming audio effeciently using AudioTrack and Socket

Girly Saputri Staff asked 10 months ago

The basic Idea is to create an application that can record audio from one device and send it over Wlan using sockets to another device that will play it. In nutshell a Lan voice chat program.
I am recording live audio from mic using a AudioRecord object and then read the recorded data into byte array ,then write the byte array to a TCP socket. The receiving device then reads that byte array from the socket and writes it to buffer of an AudioTrack object.
its like
Audio Record–>byte array–>socket—>LAN—>socket–>byte array–>AudioTrack
The process is repeated using while loops.
Although the audio is playing there its lagging between frames. i.e when I say Hello the receiver hears He–ll–O. Although the audio is complete but there is lag between the buffer blocks.
As far as I know the lag is due to delay in Lan transmission
How do I improve it? What approach should I use so it is smooth as it is in commercial online chat applications like skype and gtalk?

Your Answer