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 8858695
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:53:12+00:00 2026-06-14T14:53:12+00:00

I am developing voice application. I need a buffer queue of some sort so

  • 0

I am developing voice application.

I need a buffer queue of some sort so that i record continuosly in a thread , place the buffers full of bytes into the queue and to transmit to the server, and i take the next buffer from the queue.

Here is the recording code:

     Queue<byte[]> qArray = new LinkedList<byte[]>();
     recordingThread = new Thread(new Runnable() {

        @Override
        public void run() {

            bData = new byte[BufferElements];

            while (isRecording) {
                recorder.read(bData, 0, BufferElements);
                qArray.add(bData);
                if (AudioRecord.ERROR_INVALID_OPERATION != 0) {
                    SendAudio();

                }

            }
        }
    }, "AudioRecorder Thread");
    recordingThread.start();

But still its missing few of byte[] data while sending it to the server

Here is the sending voice to the server code:

           try {
            HttpClient httpclient = new DefaultHttpClient();


            HttpPost httppost = new HttpPost(ServerUrl.url_audio);

            // Json Format
            JSONObject holder = new JSONObject();
            JSONArray jArray = new JSONArray();
            try {

                byte[] tmparr = qArray.poll();
                for (int i = 0; i < tmparr.length; i++) {
                    jArray.put(i, tmparr[i]);
                }

                holder.put("Voice", jArray);

I dont want to miss any data which is recording.

Any help would be appreciated lot. Thanks

  • 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-06-14T14:53:13+00:00Added an answer on June 14, 2026 at 2:53 pm

    When you place a byte[] into the queue, you need to then create a new buffer. Otherwise the next recording will overwrite the same buffer. Just move the initialization of bData into the loop:

    Queue<byte[]> qArray = new LinkedList<byte[]>();
    recordingThread = new Thread(new Runnable() {
    
        @Override
        public void run() {
            while (isRecording) {
                bData = new byte[BufferElements];
                recorder.read(bData, 0, BufferElements);
                qArray.add(bData);
                if (AudioRecord.ERROR_INVALID_OPERATION != 0) {
                    SendAudio();
                }
            }
        }
    }, "AudioRecorder Thread");
    recordingThread.start();
    

    You should also add logic to limit the size of the queue. If the queue overflows, you will still lose data, but at least you won’t crash with an out-of-memory error.

    EDIT Here’s a modified version of the recording loop that does proper error checking. It uses a Queue<ByteBuffer> instead of a Queue<byte[]>:

    public void run() {
        bData = ByteBuffer.allocate(BufferElements);
        while (isRecording && !isInterrupted()) {
            int result = recorder.read(bData, 0, BufferElements);
            if (result > 0) {
                qArray.add(bData);
                SendAudio();
                bData = ByteBuffer.allocate(BufferElements);
            } else if (result == AudioRecord.ERROR_INVALID_OPERATION) {
                Log.e("Recording", "Invalid operation error");
                break;
            } else if (result == AudioRecord.ERROR_BAD_VALUE) {
                Log.e("Recording", "Bad value error");
                break;
            } else if (result == AudioRecord.ERROR) {
                Log.e("Recording", "Unknown error");
                break;
            }
            try {
                Thread.sleep(50);
            } catch (InterruptedException e) {
                break;
            }
        }
    }
    

    Of course, somewhere you’ll need to call recorder.startRecording() or you won’t get any data.

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

Sidebar

Related Questions

i'm developing an application that aims to record the voice of the user and
I am developing a Android Application, In which I need to send voice by
I am developing an Android application which always listen voice from user. It works
Developing a project of mine I realize I have a need for some level
Developing a C# .NET 2.0 WinForm Application. Need the application to close and restart
Iam developing one application.In that iam placing the radio buttons(uiimageview) on table view and
I am developing web application where users have collection of tags. I need to
I am developing an voice recording android application. For this I am using the
I am developing an app where the user can record their voice, and then
I'm currently developing an application that needs to store data in it's on database,

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.