I'm trying to make a simple voice recorder. I'm using Xcode-beta 7 and I've based my code off of these three sources.
- AVFoundation Audio Recording With Swift
- AVAudioRecorder Reference to see the inputs of the initializers.
- Recording audio in Swift to get the Settings that I should use
I'm using the following code:
var recordSettings = [
AVFormatIDKey: kAudioFormatAppleIMA4,
AVLinearPCMIsBigEndianKey: 0,
AVLinearPCMIsFloatKey: 0,
AVNumberOfChannelsKey: 2,
AVSampleRateKey: 32000
]
var session = AVAudioSession.sharedInstance()
do{
try session.setCategory(AVAudioSessionCategoryPlayAndRecord)
recorder = AVAudioRecorder(URL: filePath, settings: recordSettings, error: nil)
}catch{
print("Error")
}
but it says that "Cannot find an initializer for type 'AVAudioRecorder' that accepts an argument list of type '(URL:NSURL?, settings:[String:AudioFormatID], error:nil)'"
Aren't my inputs exactly what the documentation asks for?
AVAudioRecorder does not need anymore the error parameter:
Also, I needed to unwrap the filePath, as suggested in a previous answer: