var recordSetting=NSMutableDictionary()//录音设置
//设置录音格式 AVFormatIDKey==kAudioFormatLinearPCM
recordSetting.setValue(kAudioFormatMPEG4AAC, forKey: AVFormatIDKey)
//设置录音采样率(Hz) 如:AVSampleRateKey==8000/44100/96000(影响音频的质量)
recordSetting.setValue(44100, forKey: AVSampleRateKey)
//录音通道数 1 或 2
recordSetting.setValue(1, forKey: AVNumberOfChannelsKey)
//线性采样位数 8、16、24、32
recordSetting.setValue(16, forKey:AVLinearPCMBitDepthKey)
//录音的质量
recordSetting.setValue(AVAudioQuality.High.hashValue, forKey: AVEncoderAudioQualityKey)
self.session = AVAudioSession.sharedInstance()
self.session.setCategory(AVAudioSessionCategoryPlayAndRecord, error: nil)
session.setActive(true, error: nil)
//开启音量检测
var strUrl=NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomainMask.UserDomainMask, true)[0] as! NSString
var pathComponents = [strUrl,"sound.m4a"]
var url = NSURL.fileURLWithPathComponents(pathC![图片说明](https://img-ask.csdn.net/upload/201508/11/1439296049_555623.png)omponents)!
urlPlay=url
recorder = AVAudioRecorder(URL: url, settings: recordSetting as [NSObject : AnyObject], error: nil)! **这句话报错,错误原因如图?该怎么改呢,为什么是这个原因呢**?
//开启音量检测
recorder.meteringEnabled=true
recorder.prepareToRecord()