录制.PCM音频
时间: 2023-07-27 10:05:47 浏览: 119
要录制.PCM音频,你可以使用一些音频录制软件或者编程语言中的音频录制库。以下是使用Java语言中的javax.sound.sampled库录制.PCM音频的示例代码:
```java
import javax.sound.sampled.*;
public class AudioRecorder {
private static final int SAMPLE_RATE = 16000;
private static final int SAMPLE_SIZE_IN_BITS = 16;
private static final int CHANNELS = 1;
private static final boolean SIGNED = true;
private static final boolean BIG_ENDIAN = false;
public static void main(String[] args) throws LineUnavailableException {
AudioFormat format = new AudioFormat(SAMPLE_RATE, SAMPLE_SIZE_IN_BITS, CHANNELS, SIGNED, BIG_ENDIAN);
DataLine.Info info = new DataLine.Info(TargetDataLine.class, format);
if (!AudioSystem.isLineSupported(info)) {
System.out.println("Line not supported");
System.exit(0);
}
TargetDataLine line = (TargetDataLine) AudioSystem.getLine(info);
line.open(format);
line.start();
System.out.println("Recording...");
AudioInputStream ais = new AudioInputStream(line);
try {
AudioSystem.write(ais, AudioFileFormat.Type.WAVE, new File("output.pcm"));
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("Recording stopped.");
}
}
```
这段代码会录制.PCM格式的音频,并将其保存到文件output.pcm中。你可以根据需要修改代码中的采样率、采样位数、声道数等参数。
阅读全文