如何使用java代码控制麦克风开关功能?我需要控制麦克风开启的时间。 我试图在Java中使用下面的代码:硬件麦克风控制
final AudioFormat format = getFormat();//getformat() has the audio format
DataLine.Info info = new DataLine.Info(TargetDataLine.class, format);
final TargetDataLine line = (TargetDataLine) AudioSystem.getLine(info);
line.open(format); //open mic for input
line.start();
byte[] buffer = new byte[1048576];
OutputStream out = new ByteArrayOutputStream();//output the audio to buffer
boolean running = true;
try {
while (running) {
int count = line.read(buffer, 0, buffer.length);
running=false;
if (count > 0) {
out.write(buffer, 0, count);
}
}
out.close();
} catch (IOException e) {
System.out.println("Error");
System.err.println("I/O problems: " + e);
System.exit(-1);
}
但是这基本上取决于缓冲区的大小。而而循环可以输入30secs每音频音频。 我需要仅为10secs采样输入。 任何帮助?谢谢。:)
为了更快提供更好的帮助,请发布[SSCCE](http://sscce.org/)。另外,请为代码块使用一致的逻辑缩进。 – 2012-03-17 13:16:05