|
@ -15,14 +15,12 @@ public final class VoiceRecorder extends AbstractListenerContainer<IRecorderList |
|
|
private TargetDataLine line; |
|
|
private TargetDataLine line; |
|
|
private Thread thread; |
|
|
private Thread thread; |
|
|
|
|
|
|
|
|
private int maximum; |
|
|
|
|
|
|
|
|
private int limit; |
|
|
|
|
|
|
|
|
private static final int BUFFER_SIZE = 1024; |
|
|
private static final int BUFFER_SIZE = 1024; |
|
|
|
|
|
|
|
|
public VoiceRecorder(final int maximum) { |
|
|
public VoiceRecorder(final int maximum) { |
|
|
this.maximum = maximum; |
|
|
|
|
|
|
|
|
|
|
|
out = new ByteArrayOutputStream(); |
|
|
|
|
|
|
|
|
this.limit = maximum; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public VoiceRecorder() { |
|
|
public VoiceRecorder() { |
|
@ -50,7 +48,7 @@ public final class VoiceRecorder extends AbstractListenerContainer<IRecorderList |
|
|
|
|
|
|
|
|
public void start() { |
|
|
public void start() { |
|
|
final Runnable runnable = () -> { |
|
|
final Runnable runnable = () -> { |
|
|
while (out.size() < maximum) { |
|
|
|
|
|
|
|
|
while (out.size() < limit) { |
|
|
captureAudio(); |
|
|
captureAudio(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -62,10 +60,10 @@ public final class VoiceRecorder extends AbstractListenerContainer<IRecorderList |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
try { |
|
|
try { |
|
|
|
|
|
out = new ByteArrayOutputStream(); |
|
|
line = AudioSystem.getTargetDataLine(null); |
|
|
line = AudioSystem.getTargetDataLine(null); |
|
|
thread = new Thread(runnable); |
|
|
thread = new Thread(runnable); |
|
|
|
|
|
|
|
|
out.reset(); |
|
|
|
|
|
line.open(); |
|
|
line.open(); |
|
|
line.start(); |
|
|
line.start(); |
|
|
thread.start(); |
|
|
thread.start(); |
|
@ -87,8 +85,8 @@ public final class VoiceRecorder extends AbstractListenerContainer<IRecorderList |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public void setMaximum(final int maximum) { |
|
|
|
|
|
this.maximum = maximum; |
|
|
|
|
|
|
|
|
public void setLimit(final int limit) { |
|
|
|
|
|
this.limit = limit; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |