【发布时间】:2018-10-31 18:05:43
【问题描述】:
我正在尝试在 iOS 中录制 Opus 格式。当我使用 LinearPCM 格式测试记录器时,即wav、AVAudioRecorderDelegate 函数和 updateMeters 被正确调用并且记录器 url 在给定路径保存了有效文件。这是我用于重新编码的配置。
let fileMgr = FileManager.default
let dirPaths = fileMgr.urls(for: .documentDirectory,
in: .userDomainMask)
let soundFileURL = dirPaths[0].appendingPathComponent("audio.wav")
let recordSettings =
[AVEncoderAudioQualityKey: AVAudioQuality.low.rawValue,
AVEncoderBitRateKey: 16,
AVNumberOfChannelsKey: 1,
AVFormatIDKey : kAudioFormatLinearPCM,
AVSampleRateKey: 44100.0] as [String : Any]
然后我尝试使用以下配置为 Opus 测试它,但没有调用委托函数,米值是恒定的 -160db(silence) 和 audioRecorder url 是 nil 因为我无法在委托函数中获取它:
func audioRecorderDidFinishRecording(_ recorder: AVAudioRecorder, successfully flag: Bool) {
print(audioRecorder!.currentTime)
self.audioFileUrl = audioRecorder!.url
}
我正在使用的 Opus 配置:
let soundFileURL = dirPaths[0].appendingPathComponent("audio.opus")
let recordSettings =
[AVEncoderAudioQualityKey: AVAudioQuality.high.rawValue,
AVEncoderBitRateKey: 16,
AVNumberOfChannelsKey: 1,
AVFormatIDKey : kAudioFormatOpus,
AVSampleRateKey: 44100.0] as [String : Any]
如何正确设置配置以录制我的音频社交网络应用程序的 Opus 格式。对于在其他用户端上传和收听的 30 秒音频帖子来说,什么是最好的。
【问题讨论】:
标签: ios swift audio-recording opus