我对我的英语感到抱歉。
我正在尝试创建一个程序来记录我的扬声器音频并将其保存到文件中。从我的 SourceDataLine 创建一个 WAVE 文件我按照这个问题中的步骤 [https://stackoverflow.com/questions/9573920/how-can-i-write-the-contents-of-a-sourcedataline-to-a-文件]
并制作了以下代码
Mixer speaker = AudioSystem.getMixer( availableMixers [3] );
AudioFormat audioFormat = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, 44100, 16, 2, 4, 44100 , false);
DataLine.Info lineInfo = new DataLine.Info (SourceDataLine.class , audioFormat);
SourceDataLine sourceDataLine = (SourceDataLine) speaker.getLine(lineInfo);
sourceDataLine.open(audioFormat);
sourceDataLine.start();
byte [] data = new byte [sourceDataLine.getBufferSize() ]; // i am not sure what i should put here
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(data);
File audioFile = new File("C:\\Users\\user\\Desktop\\RecordAudio\\record.wav");
AudioSystem.write(AudioSystem.getAudioInputStream(byteArrayInputStream), AudioFileFormat.Type.WAVE, audioFile);
代码的输出是:
javax.sound.sampled.UnsupportedAudioFileException:在 Main.main(Main.java:34) 的 java.desktop/javax.sound.sampled.AudioSystem.getAudioInputStream(AudioSystem.java:1014) 的格式不受支持的流
and I am not sure why can you tell me what am I doing wrong?