java - 如何使用 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() 方法需要格式。
解决方案
你可以先用
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);
}
它曾经为我工作。
推荐阅读
- angular - Angular 7 - 将新的动态组件插入现有模块
- php - 在浏览器中获取语法颜色
- crossfilter - 交叉过滤器:按 X 和 Y 过滤散点图
- reactjs - React 中的路由
- ios12 - iOS Xcode 10 如何修复损坏的“新构建系统”-build.db:数据库被锁定可能有两个并发构建
- flutter - 如何在 Flutter 中延迟 SnackBar
- javascript - Uncaught SyntaxError: Unexpected token in import React from 'react'
- mysql - MAMP:MySQL 未启动(无法打开 Windows 事件日志)
- python - scipy.optimize.curve_fit:max_nfev 的默认值坏了?
- json.net - 在 Visual Studio 扩展中包含 Json.NET