Q: How do I process audio in real time with AudioRecord? I've been trying to get the audio from the device mic using an AudioRecord in real time. I put each byte[] I get from the AudioRecord into an ArrayList and note the amount of time that elapses, and then when the ArrayList reaches a certain size I print the record of intervals. However, when I printed these intervals I learned that approximately 20 millis occur between reading every new byte[] from the AudioRecord, and the byte[]s themselves are only 81 entries long, rather than 1024. Is it possible to fix this so I can read in the audio data instantaneously?
private void writeAudioDataToFile() {
    // Write the output audio in byte

    short sData[] = new short[BufferElements2Rec];

    long startTime = time();
    long elapsed = 0;
    final long BUFFER_SIZE = 2000; //in millis
    //initialize buffer creation time variable to time just before creation of first buffer
    long bufferCreationTime = time();

    List<Long> time = new ArrayList<Long>();

    ArrayList<byte[]> byteBuffer = new ArrayList<byte[]>();

    while (isRecording) {
        // gets the voice output from microphone to byte format

        //TODO: absolute value averages of block data

        final int BYTE_ARRAY_SIZE = 1024;
        final int TIME_BYTE_ARRAY_SIZE = 8;

        //read the next short array of audio data
        audioRecord.read(sData, 0, BufferElements2Rec);
        System.out.println("Short writing to file" + " " + elapsed + " " + Arrays.toString(sData));
        System.out.println("" + elapsed + " " + " " + BUFFER_SIZE);
        try {
            // // stores the voice buffer
            final byte bData[] = short2byte(sData);
            byteBuffer.add(bData);
            time.add(time());

            elapsed = time() - startTime;

            if(elapsed > BUFFER_SIZE) {

                System.out.println(time);

                for (int i = 0; i < time.size(); i++)
                    time.set(i, time.get(i) - bufferCreationTime);

                System.out.println(time);

                System.out.println("TAG" + blockedBuffer);
            }

            //set new buffer creation time
            bufferCreationTime = time();

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    /*
    try {
        os.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
    */
}

