Neha,

Your echo comes from the fact that you are using 400 bytes buffer to
transfer the recording to the playback.
It will physically take time to fill that buffer and then process.

Making the buffer much smaller might not necessarily work either, as
it will mean more overhead of the recording + playing management in a
unit of time. However adjusting the buffer size would be a first step.

You are using getMinBufferSize() method, but you ignore the returned
values, when it comes to the buffer used to transfer the recording to
the playback track.

You should use Math.max(recordingMinBufferSize, playbackMinBufferSize)
as a buffer size in all 3 cases.
You should also write only bytesRead bytes, rather than writing full
buffer every time.

Daniel



On Thu, May 26, 2011 at 10:28 AM, neha <neha.05...@gmail.com> wrote:
> Is there any way to synchronize the capturing and playback of audio
> data in Android?
>
> I am using audioRecord/track to achieve this.But its producing echo.
> Is there any way to cancel echo.
> My code is-
>                                {
>                                isRecording=true;
>
>                                bufferSize =
> AudioRecord.getMinBufferSize(8000,AudioFormat.CHANNEL_CONFIGURATION_MONO,AudioFormat.ENCODING_PCM_16BIT);
>                                audioRecord = new 
> AudioRecord(MediaRecorder.AudioSource.MIC,
>                                8000,
> AudioFormat.CHANNEL_CONFIGURATION_MONO,AudioFormat.ENCODING_PCM_16BIT,
> bufferSize);
>
>                                audioRecord.startRecording();
>
>                                int BUFFER_SIZE_IN_BYTES
> =AudioTrack.getMinBufferSize(RECORDER_SAMPLERATE,AudioFormat.CHANNEL_CONFIGURATION_MONO,RECORDER_AUDIO_ENCODING);
>                                AudioTrack audioTrack = new
> AudioTrack(AudioManager.STREAM_SYSTEM,
>                                                        
> 8000,AudioFormat.CHANNEL_CONFIGURATION_MONO,
>                                                        
> AudioFormat.ENCODING_PCM_16BIT, BUFFER_SIZE_IN_BYTES,
>                                                        
> AudioTrack.MODE_STREAM);
>                                byte[] buffer=new byte[400];
>                                audioTrack.play();
>                                while (isRecording) { int bytesRead = 
> audioRecord.read(buffer,
> 0,
>                                400);
>                                int bytesWritten = audioTrack.write(buffer, 0, 
> 400);
>
>                                }
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to android-developers@googlegroups.com
> To unsubscribe from this group, send email to
> android-developers+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en



-- 
Daniel Drozdzewski

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

Reply via email to