Recovering from errors caused by lack of microphone

I have just now completed the "Transcribing speech to text" tutorial at:

The download for this tutorial's starter files includes the file: "SpeechRecognizer.swift"
This file works fine when my headset is attached. I am able to transcribe speech with it. However when a microphone is not attached, program execution halts with an error at line 124. The relevant lines starting at line 124 are:

inputNode.installTap(onBus: 0, bufferSize: 1024, format: recordingFormat) { (buffer: AVAudioPCMBuffer, when: AVAudioTime) in

The error message is:

Thread 4: "required condition is false: IsFormatSampleRateAndChannelCountValid(format)"

I need the program to recover gracefully with continued execution when it happens there is no microphone to record speech with. Please suggest code modifications using "try", or other method, that will cause the program to continue to run regardless of whether a microphone is attached. I am very new to both Swift, and the API to the user interface. I just barely know what I am doing now.

One of these might help: