【发布时间】:2021-08-10 10:16:26
【问题描述】:
我在应用程序中开始录制时听到咔哒声。我不知道它是从哪里来的,我认为它可能来自按钮上的点击,但这似乎有些牵强。
这是我正在使用的代码:
private var recorderSettings: [String: Any] {
[
AVFormatIDKey: NSNumber(value: kAudioFormatMPEG4AAC),
AVSampleRateKey: 44100.0,
AVNumberOfChannelsKey: 1,
AVEncoderAudioQualityKey: AVAudioQuality.high.rawValue
]
}
audioRecorder = try AVAudioRecorder(url: fileUrl, settings: recorderSettings)
try audioSession.setCategory(.playAndRecord, mode: .default, options: [])
audioRecorder?.isMeteringEnabled = true
audioRecorder?.record()
meteringTimer = Timer.scheduledTimer(withTimeInterval: 0.05, repeats: true, block: { (timer) in
self.audioRecorder?.updateMeters()
self.soundSamples[self.currentSample] = self.audioRecorder?.averagePower(forChannel: 0) ?? 0
self.currentSample = (self.currentSample + 1) % self.numberOfSamples
})
【问题讨论】:
-
这是在物理设备上还是模拟器上?
-
设备上的@Adrian
-
我以前没有在设备上录制过,但我想看看苹果的在线文档。我最近在设备上进行了播放,最终在
AppDelegate中准备好了音频? stackoverflow.com/a/66937105/4475605
标签: ios swift audio audio-recording audio-processing