我已经读了几天的Java声音API了,我无法理解。我是一个体面的程序员,只是很难理解API。
我一直在尝试从麦克风捕获音频并实时显示波形图。
我在捕捉音频时遇到麻烦,他们在教程中说要这样做,但是我似乎无法使它正常工作。
任何建议和帮助将不胜感激,逐行回答将是理想的。
谢谢,麻烦您了。
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.DataLine;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.TargetDataLine;
public class FindLine {
public static void main (String[] args){
AudioFormat format = new AudioFormat(22000,16,2,true,true);
TargetDataLine line;
DataLine.Info info = new DataLine.Info(TargetDataLine.class,
format); // format is an AudioFormat object
if (!AudioSystem.isLineSupported(info)) {
// Handle the error ...
}
// Obtain and open the line.
try {
line = (TargetDataLine) AudioSystem.getLine(info);
line.open(format);
} catch (LineUnavailableException ex) {
// Handle the error ...
}
}
}