ios - WebRTC iOS:如何录制远程音频流?
问题描述
用例是我正在运行 webRTC 会话并尝试捕获远程和本地音轨。使用 AVAudioSession 和 AVAudioRecorder 我只能录制通过麦克风进入的本地视频轨道。通过扬声器传来的远程音轨根本没有被记录下来。这是我尝试过的示例。
func setupView() {
recordingSession = AVAudioSession.sharedInstance()
do {
try recordingSession.setCategory(.playAndRecord, options: .defaultToSpeaker)
try recordingSession.setMode(.videoChat)
try recordingSession.setActive(true)
recordingSession.requestRecordPermission() { [unowned self] allowed in
DispatchQueue.main.async {
if allowed {
//self.loadRecordingUI()
} else {
// failed to record
}
}
}
} catch {
// failed to record
}
}
@IBAction func recordButtonTapped() {
if audioRecorder == nil {
startRecording()
} else {
finishRecording(success: true)
}
}
func startRecording() {
let audioFilename = getFileURL()
let recordSettings = [ AVFormatIDKey: Int(kAudioFormatLinearPCM),
AVSampleRateKey: 8000.0,
AVNumberOfChannelsKey: 1,
AVLinearPCMBitDepthKey: 16,
AVLinearPCMIsBigEndianKey: false,
AVLinearPCMIsFloatKey: false,
AVEncoderAudioQualityKey: AVAudioQuality.max.rawValue] as [String : Any]
do {
audioRecorder = try AVAudioRecorder(url: audioFilename, settings: recordSettings)
audioRecorder.delegate = self
audioRecorder.record()
} catch {
finishRecording(success: false)
}
}
关于我可能做错了什么的任何建议。
解决方案
推荐阅读
- python - 用于同时输入和套接字连接的 Python 多线程
- java - 有时双引号会在写入 csv 文件时消失
- react-three-fiber - 球体不考虑平面几何外的重力
- bash - bashs 关于出口管道出口的命令行为。`退出1 | 出口 2`
- sql - 如何删除具有特定条件的 XML 中的项目?
- windows - 如何使用 PowerShell 更改文件夹选项“打开文件资源管理器”
- java - 使用外部 jar 在 debian 10 命令行中运行 java 程序
- python-3.x - 服务器在使用 BSE SOAP API 的功能时返回 404 错误
- c# - REST API 最佳实践 - 在现有 API 的请求/响应中添加新参数
- python - 当 dtype = 'float64' 和 dtype = 'category' 相等时,Pandas 类别显示不同的行为