Posts

Post not yet marked as solved
18 Replies
I don't know if this will work, but it did for me. I am also not 100% sure why it worked, but I think by changing the audio session mode from .measurement to .voicePrompt, it only requires voice input and not output. Therefore, with no output, the error of input format not matching output format cannot occur, because there is no output. Please find my bug fix below:Old code with format matching error:do { AudioOutputUnitStop((audioEngine.inputNode.audioUnit)!) AudioUnitUninitialize((audioEngine.inputNode.audioUnit)!) try audioSession.setCategory(.playAndRecord, mode: .measurement, options: .duckOthers) } catch let error { print("\(error)") }New code without error:do { AudioOutputUnitStop((audioEngine.inputNode.audioUnit)!) AudioUnitUninitialize((audioEngine.inputNode.audioUnit)!) try audioSession.setCategory(.playAndRecord, mode: .voicePrompt, options: .duckOthers) } catch let error { print("\(error)") }I may be wrong as I am a novice still. But I hope this helps!
Post not yet marked as solved
6 Replies
I don't know if this would work for you, but it did for me, I declared the inputNode var as early as possible. (e.g: let inputNode = audioEngine.inputNode) in viewDidLoad. I think it solved the issue for me because it gives the app more time to instantiate inputNode. Which sometimes it does have enough time to do so, hence the random crashes with the error message above that I receive too. I used to declare inputNode right above installTap, which I think is too late. So when the inputNode is not instantiated properly, the sampleRate is different.