title: How to play back AudioRecord with some delay
body: <p>I'm implementing an app which will repeat everything I'm telling it.
  What I need is to play the sound I'm recording on a buffer just with a second of delay
  So that I would be listening myself but 1 second delayed</p>
  
  <p>This is my run method of the Recorder class</p>
  
  <pre><code>public void run()
      {           
          AudioRecord recorder = null;
          int ix = 0;
          buffers = new byte[256][160];
  
          try
          {
              int N = AudioRecord.getMinBufferSize(44100,AudioFormat.CHANNEL_IN_STEREO,AudioFormat.ENCODING_PCM_16BIT);
              recorder = new AudioRecord(AudioSource.MIC, 44100, AudioFormat.CHANNEL_IN_STEREO, AudioFormat.ENCODING_PCM_16BIT, N*10);               
              recorder.startRecording();
              Timer t = new Timer();              
              SeekBar barra = (SeekBar)findViewById(R.id.barraDelay);
              t.schedule(r = new Reproductor(), barra.getProgress());           
  
              while(!stopped)
              {                   
                  byte[] buffer = buffers[ix++ % buffers.length];                 
                  N = recorder.read(buffer,0,buffer.length);                  
              }
          }
          catch(Throwable x)
          {               
          }
  
          finally
          { 
              recorder.stop();
              recorder.release();
              recorder = null;                        
          }
  </code></pre>
  
  <p>And this is the run one of my player:</p>
  
  <pre><code>public void run() {
          reproducir = true;
  
          AudioTrack track = null;            
          int jx = 0;
  
          try
          {
              int N = AudioRecord.getMinBufferSize(44100,AudioFormat.CHANNEL_IN_STEREO,AudioFormat.ENCODING_PCM_16BIT);               
              track = new AudioTrack(AudioManager.STREAM_MUSIC, 44100, 
                      AudioFormat.CHANNEL_OUT_STEREO, AudioFormat.ENCODING_PCM_16BIT, N*10, AudioTrack.MODE_STREAM);              
              track.play();
              /*
               * Loops until something outside of this thread stops it.
               * Reads the data from the recorder and writes it to the audio track for playback.
               */
              while(reproducir)
              {                   
                  byte[] buffer = buffers[jx++ % buffers.length];                 
                  track.write(buffer, 0, buffer.length);
              }
          }
          catch(Throwable x)
          {               
          }
          /*
           * Frees the thread's resources after the loop completes so that it can be run again
           */
          finally
          {               
              track.stop();
              track.release();
              track = null;               
          }
  
      }
  </code></pre>
  
  <p>Reproductor is an inner class extending TimerTask and implementing the "run" method.</p>
  
  <p>Many thanks!</p>