0

I want to record live audio and play back to the speaker after a certain amount of time i specified.

  1. 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();


}

`

arifcse10
  • 133
  • 2
  • 3
  • 12
  • I'm not sure I see what the problem is. Allocate a large enough buffer (or an array of smaller buffers) to hold at least X ms worth of audio data, and begin writing to the audio track once X ms worth of audio data has been recorded. – Michael Aug 29 '16 at 10:57
  • Thanks for replying. I solved that problem using a file. but can you share any method using buffer? – arifcse10 Aug 30 '16 at 18:09

0 Answers0