-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSoundRecorder.java
More file actions
35 lines (27 loc) · 884 Bytes
/
SoundRecorder.java
File metadata and controls
35 lines (27 loc) · 884 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package com.company;
import javax.sound.sampled.*;
import java.io.ByteArrayOutputStream;
public class SoundRecorder {
private boolean stopped = false;
private TargetDataLine line;
private AudioFormat format;
private byte[] data = null;
public static void main(String[]args){
SoundRecorder a = new SoundRecorder();
a.StartRecording();
}
public SoundRecorder(){
}
public void StartRecording(){
int numBytesRead;
data = new byte[line.getBufferSize() / 5];
// Begin audio capture.
line.start();
// Here, stopped is a global boolean set by another thread.
while (!stopped) {
// Read the next chunk of data from the TargetDataLine.
numBytesRead = line.read(data, 0, data.length);
// Save this chunk of data.
}
}
}