Getting compiler error on snips.appendBuffer(buffer)


#1

On step 6 of the iOS Quick Start : Setup view controller, after making all the additions suggested in the step I get the following compiler error: Call can throw, but it is not marked with ‘try’ and the error is not handled

I get it with regards to snips.appendBuffer(buffer) in the following block:

fileprivate class func createAudioEngine(with snips: SnipsPlatform) throws -> AVAudioEngine {
let audioEngine = AVAudioEngine()
let audioSession = AVAudioSession.sharedInstance()
try audioSession.setCategory(.playAndRecord, mode: .measurement, options: [.mixWithOthers, .allowBluetoothA2DP, .allowBluetooth])
try audioSession.setPreferredSampleRate(16_000)
try audioSession.setActive(true, options: .notifyOthersOnDeactivation)
let recordingFormat = AVAudioFormat(commonFormat: .pcmFormatInt16, sampleRate: 16_000, channels: 1, interleaved: true)
let input = audioEngine.inputNode
let downMixer = AVAudioMixerNode()
audioEngine.attach(downMixer)
audioEngine.connect(input, to: downMixer, format: nil)
downMixer.installTap(onBus: 0, bufferSize: 1024, format: recordingFormat, block: { (buffer, time) in snips.appendBuffer(buffer)})
audioEngine.prepare()
return audioEngine
}

Any ideas?

Edit: I was able to make it work, since appendBuffer is a throwable function, changing the line to:

do { try snips.appendBuffer(buffer) } catch {print(error)}

solves the issue. Maybe the latest version of SnipsPlatform.appendBuffer is now throwable and before it wasn’t so the documentation didn’t reflect it.