Reputation: 1682
I am having a problem With AsyncTask
as executeOnExecutor()
for parallel execution, but I am getting voice with delay (400 ms to 600 ms) when sending and receiving audio. Here is my code:
The code for recording audio call:
private void startRecording() {
recorder = new AudioRecord(MediaRecorder.AudioSource.MIC,
RECORDER_SAMPLERATE, RECORDER_CHANNELS,
RECORDER_AUDIO_ENCODING, BufferElements * BytesPerElement);
recorder.startRecording();
isRecording = true;
/*
* Schedule a task for repeated fixed-rate execution after a specific
* delay has passed.
*/
timer.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
bData = new short[BufferElements];
while (isRecording) {
// gets the voice output from microphone to byte format
/*
* Reads audio data from the audio hardware for recording
* into a buffer.
*/
recorder.read(bData, 0, BufferElements);
if (AudioRecord.ERROR_INVALID_OPERATION != 0) {
/* Send the audio voice data to server */
SendAudio();
}
}}, 0, 1);
}
When making call between two users, firstly initiate call take place as shown in figure.
------>> Calling from user 1 to user 2 Initiate call = 0
If user2 receives call, Initiate call = 1 <<------
If initiate call = 1, transfer data between two users i.e. sending and receiving voice data.
------>> When Initiate call = 1, Transfer data
Sending and receiving voice data <<------
What is the problem in playing audio data?
Getting delay in voice while playing the audio. Time between sending & receiving response is too much, approximately 400 ms to 600 ms. What do I need to do to solve this problem? Holding 5 chunks of data for the first time, when it receives the 5 audio data starts playing immediately one after the other, as shown in code above.
Upvotes: 2
Views: 703
Reputation:
Try to reduce the 5 audio data to 3? - not always the best idea, but it could help. How is the bandwidth, is enough for transfer comfortably? how is the network latency? do a ping , if there is a 400ms, than ofc you can't do much.
Upvotes: 1