我想弄清楚如何使用我的 MacBookPro 從麥克風(fēng)錄制聲音。我不確定這是代碼問題還是 MacOS 中的隱藏權(quán)限問題。我已經(jīng)完成了大部分教程并嘗試了各種不同的解決方案,以至于我創(chuàng)建了下面的測試用例。public class AudioLinesTester { private static final Logger LOGGER = LoggerFactory.getLogger(AudioLinesTester.class); public static void main(String[] args) { LOGGER.debug("Starting Line tester"); AudioFormat format = new AudioFormat(8000.0f, 8, 1, true, true); Mixer.Info[] infos = AudioSystem.getMixerInfo(); Map<Line.Info, byte[]> sounds = new HashMap<Line.Info, byte[]>(); Stream.of(infos).forEach(mixerInfo -> { Mixer mixer = AudioSystem.getMixer(mixerInfo); Line.Info[] lineInfos = mixer.getTargetLineInfo(); if (lineInfos.length > 0 && lineInfos[0].getLineClass().equals(TargetDataLine.class)) { // The name of the AudioDevice LOGGER.debug("Line Name: {}", mixerInfo.getName()); // The type of audio device LOGGER.debug("Line Description: {}", mixerInfo.getDescription()); for (Line.Info lineInfo : lineInfos) { LOGGER.debug("\t---{}", lineInfo); Line line; try { line = mixer.getLine(lineInfo); TargetDataLine microphone = AudioSystem.getTargetDataLine(format, mixerInfo); microphone.open(format, 100352); LOGGER.debug("Listening on {}", microphone); ByteArrayOutputStream out = new ByteArrayOutputStream(); int numBytesRead; int CHUNK_SIZE = 1024; byte[] data = new byte[microphone.getBufferSize() / 5]; microphone.start(); int bytesRead = 0; 我希望從某些東西中得到一些輸出,但我只是得到填充有 0 的字節(jié)數(shù)組。有人能幫忙嗎?
如何錄制麥克風(fēng)的聲音?
慕標(biāo)5832272
2023-05-24 17:34:19