Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6931747
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:37:03+00:00 2026-05-27T11:37:03+00:00

I got 0.3-0.5 sec latency while record audio (live monitoring). Here’s my code: code

  • 0

I got 0.3-0.5 sec latency while record audio (live monitoring). Here’s my code:

code from here: Android – Getting audio to play through earpiece

public class Sounds extends Activity {

private boolean isRecording;
private AudioManager am;
private int count;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    am = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
    am.setMicrophoneMute(true);

    while(count <= 1000000){
    Record record = new Record();  
    record.run();
    count ++;
    Log.d("COUNT", "Count is : " + count);
    }
}

public class Record extends Thread
{

        static final int bufferSize = 200000;
        final short[] buffer = new short[bufferSize];
        short[] readBuffer = new short[bufferSize];

        public void run() {  
         isRecording = true;
         android.os.Process.setThreadPriority
         (android.os.Process.THREAD_PRIORITY_URGENT_AUDIO);

         int buffersize = AudioRecord.getMinBufferSize(11025,
         AudioFormat.CHANNEL_CONFIGURATION_MONO,
         AudioFormat.ENCODING_PCM_16BIT);

                        AudioRecord arec = new AudioRecord(MediaRecorder.AudioSource.MIC,
                                        11025,
                                        AudioFormat.CHANNEL_CONFIGURATION_MONO,
                                        AudioFormat.ENCODING_PCM_16BIT,
                                        buffersize);

                        AudioTrack atrack = new AudioTrack(AudioManager.STREAM_MUSIC,
                                        11025,
                                        AudioFormat.CHANNEL_CONFIGURATION_MONO,
                                        AudioFormat.ENCODING_PCM_16BIT,
                                        buffersize,
                                        AudioTrack.MODE_STREAM);


                        am.setRouting(AudioManager.MODE_NORMAL,1,
                          AudioManager.STREAM_MUSIC);


                        int ok = am.getRouting(AudioManager.ROUTE_EARPIECE);
                        Log.d("ROUTING", "getRouting = " + ok);
                        setVolumeControlStream(AudioManager.STREAM_VOICE_CALL);
                        //am.setSpeakerphoneOn(true);
                        Log.d("SPEAKERPHONE", "Is speakerphone on? : " + am.isSpeakerphoneOn());
                        am.setSpeakerphoneOn(false);
                        Log.d("SPEAKERPHONE", "Is speakerphone on? : " + am.isSpeakerphoneOn());
                        atrack.setPlaybackRate(11025);

                        byte[] buffer = new byte[buffersize];
                        arec.startRecording();
                        atrack.play();

                        while(isRecording) {
                                arec.read(buffer, 0, buffersize);
                                atrack.write(buffer, 0, buffer.length);
                        }

                        arec.stop();
                        atrack.stop();
                        isRecording = false;
        }
} 

}

Can you help me? (sorry for my english)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T11:37:03+00:00Added an answer on May 27, 2026 at 11:37 am

    From my understanding, you’re wanting to achieve lower latency? If so, it’s currently an issue with the Android OS that audio latency can be fairly high, which is why you don’t see many real-time audio apps in the marketplace. The Android 4.0 spec allows for low-latency audio, but until then, that may be speedy as you’ll get.

    Ref Section 5.4:
    http://static.googleusercontent.com/external_content/untrusted_dlcp/source.android.com/en/us/compatibility/4.0/android-4.0-cdd.pdf

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I got a code here, when it runs it creats and starts a new
I got a code from a client to fix the bug (code was written
Got a bluescreen in windows while cloning a mercurial repository. After reboot, I now
Got myself in a bit of a pickle here ... working on a CMS
Got some code that is not mine and its producing this warning atm: iehtmlwin.cpp(264)
Got a crash report from a beta tester and I'm having trouble identifying the
I can't read regex for the life of me. Anyone got a sec to
I've got some analysis code ( myprog ) that sucks in data using the
I've got some code with an apparent reference cycle in a block ivar. The
EDIT: I got it working it just won't download anything... So here is my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.