首页 > 解决方案 > 如何使用 JMF 录制音频设备?

问题描述

因此,对于我要从计算机的麦克风录制音频,我需要使用 anCaptureDeviceManager返回安装在计算机系统上的可用设备列表。这可以通过调用getDeviceList(Format format). 但是,要创建 Format 的实例,我需要在构造函数中指定一个编码字符串new Format(String encoding)。我不确定该编码是什么,因为我只想返回所有可用设备的列表。getDeviceList() 方法返回一个空向量。

API 还对 getDeviceList(Format format) 方法进行了说明:

 If no Format is specified, this method returns a list of CaptureDeviceInfo 
 objects for all of the available capture devices.

但是,只有一个 getDeviceList() 方法需要格式。

标签: javaaudiovectorjmf

解决方案


你可以先用

Vector devs = CaptureDeviceManager.getDeviceList(null)

然后你可以使用

devs = CaptureDeviceManager.getDeviceList(fmts);

fmts 在哪里

AudioFormat fmts=getAudioFormat();

private AudioFormat getAudioFormat() {
    double sampleRate = 44100;
    int sampleSizeInBits = 16;
    int channels = 2;
    boolean signed = true;
    boolean bigEndian = true;
    return new AudioFormat(AudioFormat.LINEAR, sampleRate, sampleSizeInBits, channels); 
  }

它曾经为我工作。


推荐阅读