Main Topics
Browse All TopicsHi,
I simply want to read from the microphone input as bytes into an array.
Can anyone provide sample code or links to how to do this. I would prefer a simple complete example rather than bits of code as I seem to get off other sites. Surely its just a simple case of reading in the byte stream like the byte stream of anything else like a file for example?
Thanks in advance.
Regards
John
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Thanks for your comments, I have tried to understand from the code links you have posted what is going on. I have tried to extract what I think is the very basic of what goes on, I literally want to get data from the microphone and display its byte values on the screen. This is the code I have done so far, but it wont work (null pointer exception).
public class Microphone
{
private static TargetDataLine m_line;
public static void main(String[] args)
{
//open line
m_line.start();
byte[] data = new byte [10000];
//read in the data from the microphone
m_line.read(data,0,10000);
//display the bytes
for(int i=0; i<10000; i++){
System.out.println(data[i]
}
}
}
Thanks for your help so far.
Regards
John
You're missing some details. Try following this code (complete code can be found at the URL):
//This method captures audio input from a microphone and saves it in
// a ByteArrayOutputStream object.
private void captureAudio(){
try{
//Get everything set up for
// capture
audioFormat = getAudioFormat();
DataLine.Info dataLineInfo = new DataLine.Info( TargetDataLine.class, audioFormat);
targetDataLine = (TargetDataLine) AudioSystem.getLine( dataLineInfo); targetDataLine.open(audioF
targetDataLine.start();
//Create a thread to capture the microphone data and start it
// running. It will run until the Stop button is clicked.
Thread captureThread = new Thread( new CaptureThread());
captureThread.start();
} catch (Exception e) {
System.out.println(e);
System.exit(0);
} //end catch
} //end captureAudio method
http://www.developer.com/j
Business Accounts
Answer for Membership
by: marklorenzPosted on 2007-09-04 at 11:06:47ID: 19827091
Perhaps this is what you're looking for:
ava/other/ article.ph p/2105421
ooks/tutor ial/sound/ capturing. html
Java Sound, Capturing Microphone Data into an Audio File
http://www.developer.com/j
Capturing Audio
http://java.sun.com/docs/b