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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T10:33:59+00:00 2026-05-24T10:33:59+00:00

This is a code that will attempt to record an audio sample : but

  • 0

This is a code that will attempt to record an audio sample : but i’ve a not constructed AudioFormat object ( that has been passed to DataLine.Info) because i don’t know the sample rate.

EDIT

I have seen that just randomly placing sample rate of 8000 works . But is it fine ? Can i keep any value of sample rate ?

boolean lineIsStopped = false;
TargetDataLine line = null; 
AudioFormat af; // object not constructed through out
DataLine.Info info = new DataLine.Info(TargetDataLine.class, af); // af not initialized
try {
  line = (TargetDataLine)AudioSystem.getLine(info); 
  line.open( af );      
} catch( LineUnavailableException ex ) {
   // handle the error
  }

// now we are ready for an input
// call start to start accepting data from mic
byte data[] = new byte[ line.getBufferSize() / 5 ];
 line.start(); // this statement starts delivering data into the line buffer
// start retreiving data from the line buffer
 int numBytesRead;
 int offset = 0;
 ByteArrayOutputStream out = new ByteArrayOutputStream();
 while( ! lineIsStopped ) { // when the line is not stopped i.e is active
     numBytesRead = line.read( data , offset , data.length );
     // now save the data
     try {
        out.write(data); // writes data to this output stream !
     } catch( Exception exc) {
         System.out.println(exc);
       }
 }

In this how can i construct audio format object without getting any audio sample ?

  • 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-24T10:34:01+00:00Added an answer on May 24, 2026 at 10:34 am

    After reading your comments, you are recording from the mic. In which case you want to set the audio format according to the quality you want from the mic. If you want telephone quality 8k hz would be fine. If you want tape quality 22khz, and if you want CD quality audio 44.1khz. Of course, if you transmitting that over the network then 8khz is probably going to be good enough.

    It’s always a good idea to have this be a setting if your application so the user can control what quality they want.

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

Sidebar

Related Questions

I have this code that performs an ajax call and loads the results into
So I have this code that takes care of command acknowledgment from remote computers,
I'm a newbie to python and the app engine. I have this code that
I have this jQuery code that queries an API on a keyup event (via
I have this legacy code that I am working with and there is code
Is there an easy way to modify this code so that the target URL
I have this small code library that I'm considering releasing into Open Source. I
Well, I have this bit of code that is slowing down the program hugely
I've got a problem with inheritance and generics. This is the code that illustrates
The code that I want to write is like this: void MethodOnThreadA() { for

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.