I want to record live audio and play back to the speaker after a certain amount of time i specified.
- recordAndPlayAfter(2000);
example.. if i call the function it will record the audio and stream it to speaker with a 2000 millisecond delay. If i say "Hello", i would hear hello after 2 second.
please help me, I stuck at this for days, and Found no solution on Internet. Thanks in Advance.
here is my function below
`public void echoSound() {
new Thread(new Runnable() {
@Override
public void run() {
isRecording = true;
buffersize = AudioRecord.getMinBufferSize(11025, AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_16BIT);
arec = new AudioRecord(MediaRecorder.AudioSource.MIC, 11025, AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_16BIT, buffersize);
buffer = new byte[buffersize];
arec.startRecording();
atrack = new AudioTrack(AudioManager.STREAM_MUSIC, 11025, AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_16BIT, buffersize, AudioTrack.MODE_STREAM);
atrack.setPlaybackRate(11025);
atrack.play();
atrack.setPositionNotificationPeriod(msValue);
while(isRecording) {
arec.read(buffer, 0, buffersize);
atrack.write(buffer,0,buffer.length);
}
}
}).start();
}
`