我正在尝试清除音频文件的内容而不删除和创建新文件,我完全被难倒了。
如果需要这里我用来录制音频的代码:
func record(){
let audioSession:AVAudioSession = AVAudioSession.sharedInstance()
let audioHeardUrl = URL(fileURLWithPath: Bundle.main.path(forResource: "recordedAudio", ofType: "caf")!)
let recordSettings: [String: Any] = [AVFormatIDKey:kAudioFormatAppleIMA4,
AVSampleRateKey:44100.0,
AVNumberOfChannelsKey:2,AVEncoderBitRateKey:12800,
AVLinearPCMBitDepthKey:16,
AVEncoderAudioQualityKey:AVAudioQuality.max.rawValue]
do {
try audioSession.setCategory("AVAudioSessionCategoryRecord")
} catch { print("Setting Audio Session Category Error") }
do {
try audioSession.setActive(true)
} catch { print("Activating Audio Session Error") }
do {
try recordedAudio = AKAudioFile(forWriting: audioHeardUrl, settings: recordSettings)
} catch { print("Audio Storing Error") }
do {
try audioRecorder = AKNodeRecorder(node: mic, file: recordedAudio)
} catch { print("Creating Audio Recorder Error") }
var error: NSError?
if let e = error {
print(e.localizedDescription)
} else {
do {
try audioRecorder.record()
} catch { print("Recording Error") }
}
}